aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_mpm
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-06-06 22:04:08 -0700
committerMartin Braun <martin.braun@ettus.com>2017-12-22 15:03:59 -0800
commit3c385a45877d0c5b9c7fd4430752460ec085202a (patch)
tree8b699f6ab5f34b9851ef54c69edcb5cf257f77e9 /mpm/python/usrp_mpm
parentbf4ff21ce6341f72b72a217d20063878b1b9ecc0 (diff)
downloaduhd-3c385a45877d0c5b9c7fd4430752460ec085202a.tar.gz
uhd-3c385a45877d0c5b9c7fd4430752460ec085202a.tar.bz2
uhd-3c385a45877d0c5b9c7fd4430752460ec085202a.zip
mpm: discovery can now be bound to subnet
Diffstat (limited to 'mpm/python/usrp_mpm')
-rw-r--r--mpm/python/usrp_mpm/discovery.py64
1 files changed, 40 insertions, 24 deletions
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)