diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-06-06 22:04:08 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:59 -0800 |
commit | 3c385a45877d0c5b9c7fd4430752460ec085202a (patch) | |
tree | 8b699f6ab5f34b9851ef54c69edcb5cf257f77e9 /mpm | |
parent | bf4ff21ce6341f72b72a217d20063878b1b9ecc0 (diff) | |
download | uhd-3c385a45877d0c5b9c7fd4430752460ec085202a.tar.gz uhd-3c385a45877d0c5b9c7fd4430752460ec085202a.tar.bz2 uhd-3c385a45877d0c5b9c7fd4430752460ec085202a.zip |
mpm: discovery can now be bound to subnet
Diffstat (limited to 'mpm')
-rwxr-xr-x | mpm/python/usrp_hwd.py | 9 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/discovery.py | 64 |
2 files changed, 48 insertions, 25 deletions
diff --git a/mpm/python/usrp_hwd.py b/mpm/python/usrp_hwd.py index 8abc89923..c44f3a109 100755 --- a/mpm/python/usrp_hwd.py +++ b/mpm/python/usrp_hwd.py @@ -51,6 +51,12 @@ def setup_arg_parser(): default=None ) parser.add_argument( + '--discovery-addr', + help="Bind discovery socket to this address only. Defaults to all " \ + "addresses.", + default="0.0.0.0", + ) + parser.add_argument( '--default-args', help="Provide a comma-separated list of key=value pairs that are" \ "used as defaults for device initialization.", @@ -122,7 +128,8 @@ def main(): return True log.info("Spawning discovery process...") _PROCESSES.append( - mpm.spawn_discovery_process(discovery_info, shared)) + mpm.spawn_discovery_process(discovery_info, shared, args.discovery_addr) + ) log.info("Spawning RPC process...") _PROCESSES.append( mpm.spawn_rpc_process(mpm.mpmtypes.MPM_RPC_PORT, shared, mgr)) diff --git a/mpm/python/usrp_mpm/discovery.py b/mpm/python/usrp_mpm/discovery.py index 5f025283d..47088c7e7 100644 --- a/mpm/python/usrp_mpm/discovery.py +++ b/mpm/python/usrp_mpm/discovery.py @@ -30,21 +30,26 @@ RESPONSE_PREAMBLE = "USRP-MPM" RESPONSE_SEP = ";" RESPONSE_CLAIMED_KEY = "claimed" -def spawn_discovery_process(device_info, shared_state): +def spawn_discovery_process(device_info, shared_state, discovery_addr): """ Returns a process that contains the device discovery. Arguments: device_info -- A dictionary of type string -> string. All of these items will be included in the response string. + shared_state -- Shared state of device (is it claimed, etc.). Is a + SharedState() object. + discovery_addr -- Discovery will listen on this address(es) """ - # claim_status = Value(ctypes.c_bool, False) - proc = Process(target=_discovery_process, args=(device_info, shared_state)) + proc = Process( + target=_discovery_process, + args=(device_info, shared_state, discovery_addr) + ) proc.start() return proc -def _discovery_process(device_info, state): +def _discovery_process(device_info, state, discovery_addr): """ The actual process for device discovery. Is spawned by spawn_discovery_process(). @@ -59,27 +64,38 @@ def _discovery_process(device_info, state): log = get_main_logger().getChild('discovery') sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + # FIXME really, we should only bind to the subnet but I haven't gotten that + # working yet sock.bind((("0.0.0.0", MPM_DISCOVERY_PORT))) - send_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - # try: - while True: - data, sender = sock.recvfrom(8000) - log.info("Got poked by: %s", sender[0]) - if data.strip(b"\0") == b"MPM-DISC": - log.info("Sending discovery response to %s port: %d", - sender[0], sender[1]) - send_data = bytes(create_response_string(), 'ascii') - log.info(send_data) - send_sock.sendto(send_data, sender) - elif data.strip(b"\0").startswith(b"MPM-ECHO"): - log.info("Received echo request from {sender}".format(sender=sender[0])) - send_data = data - send_sock.sendto(send_data, sender) + # TODO yeah I know that's not how you do this + discovery_addr_prefix = discovery_addr.replace('.255', '') + if discovery_addr == '0.0.0.0': + discovery_addr_prefix = '' - # except Exception as err: - # log.info("Error: %s", err) - # log.info("Error type: %s", type(err)) - # sock.close() - # send_sock.close() + try: + while True: + data, sender = sock.recvfrom(8000) + log.info("Got poked by: %s", sender[0]) + # TODO this is still part of the awful subnet identification + if not sender[0].startswith(discovery_addr_prefix): + continue + if data.strip(b"\0") == b"MPM-DISC": + log.info("Sending discovery response to %s port: %d", + sender[0], sender[1]) + send_data = bytes(create_response_string(), 'ascii') + log.info(send_data) + send_sock.sendto(send_data, sender) + elif data.strip(b"\0").startswith(b"MPM-ECHO"): + log.info("Received echo request from {sender}".format( + sender=sender[0]) + ) + send_data = data + send_sock.sendto(send_data, sender) + except Exception as err: + log.error("Error: %s", err) + log.error("Error type: %s", type(err)) + sock.close() + send_sock.close() + exit(1) |