aboutsummaryrefslogtreecommitdiffstats
path: root/mpm
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-12-08 11:17:30 -0800
committerMartin Braun <martin.braun@ettus.com>2017-12-22 15:05:59 -0800
commit7c7d5090177d32efb1bffa648fcb507fe04e97f9 (patch)
tree848a40ca70cf80b30bde66cab560a22ab860b540 /mpm
parent87dbcd9f1a5b2b464c27af56c3a91ab00f66c441 (diff)
downloaduhd-7c7d5090177d32efb1bffa648fcb507fe04e97f9.tar.gz
uhd-7c7d5090177d32efb1bffa648fcb507fe04e97f9.tar.bz2
uhd-7c7d5090177d32efb1bffa648fcb507fe04e97f9.zip
mpm: Fix ECHO command
The echo server was using the wrong socket options, allowing responses to be fragmented. Since we use the echo server for MTU discovery, that would have beaten the purpose. Also includes minor formatting fixes.
Diffstat (limited to 'mpm')
-rw-r--r--mpm/python/usrp_mpm/discovery.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/mpm/python/usrp_mpm/discovery.py b/mpm/python/usrp_mpm/discovery.py
index 9860958c9..7a133af15 100644
--- a/mpm/python/usrp_mpm/discovery.py
+++ b/mpm/python/usrp_mpm/discovery.py
@@ -18,6 +18,12 @@ from usrp_mpm.mpmlog import get_main_logger
RESPONSE_PREAMBLE = "USRP-MPM"
RESPONSE_SEP = ";"
RESPONSE_CLAIMED_KEY = "claimed"
+# "Max MTU" is not a redundant name. We don't know the total path MTU, but we
+# can say for sure that it won't exceed a certain value, and that's the max MTU
+MAX_MTU = 8000
+# For setsockopt
+IP_MTU_DISCOVER = 10
+IP_PMTUDISC_DO = 2
def spawn_discovery_process(device_info, shared_state, discovery_addr):
"""
@@ -57,15 +63,16 @@ def _discovery_process(device_info, state, discovery_addr):
# working yet
sock.bind((("0.0.0.0", MPM_DISCOVERY_PORT)))
send_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ send_sock.setsockopt(socket.IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_DO)
# TODO yeah I know that's not how you do this
- discovery_addr_prefix = discovery_addr.replace('.255', '')
+ discovery_addr_prefix = discovery_addr.replace('.255', '')
if discovery_addr == '0.0.0.0':
discovery_addr_prefix = ''
try:
while True:
- data, sender = sock.recvfrom(8000)
+ data, sender = sock.recvfrom(MAX_MTU)
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):
@@ -77,14 +84,15 @@ def _discovery_process(device_info, state, discovery_addr):
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])
- )
+ log.info("Received echo request from {sender}"
+ .format(sender=sender[0]))
send_data = data
- send_sock.sendto(send_data, sender)
+ try:
+ send_sock.sendto(send_data, sender)
+ except OSError as ex:
+ log.debug("ECHO send error: %s", str(ex))
except Exception as err:
- log.error("Error: %s", err)
- log.error("Error type: %s", type(err))
+ log.error("Unexpected error: `%s' Type: `%s'", str(err), type(err))
sock.close()
send_sock.close()
exit(1)