import socket import json import sys import time ''' testing procedure: python udp_sender.py small fast # small UDP packet reaches destination ip route get to 10.10.10.10 python udp_sender.py big fast # big UDP packet does not reach destination ip route get to 10.10.10.10 python udp_sender.py small slow # small UDP packet reaches destination ip route get to 10.10.10.10 python udp_sender.py big slow # big UDP packet does not reach destination ip route get to 10.10.10.10 # entry is added python udp_sender.py big fast # big UDP packet reaches destination ''' DST_HOST = '10.10.10.10' # IP of host with mtu smaller then sender one or with MTU reduction in path DST_PORT = 515 # PORT on dst host SOURCE_HOST = socket.gethostbyname(socket.gethostname()) # source IP adress, it may not work in every case SOURCE_PROT = 60000 # source static port for easier packet capture SLEEP_TIME = 1 # may vary depending network architecture and server speed sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) sock.bind((SOURCE_HOST, SOURCE_PROT)) sock.connect((DST_HOST, DST_PORT)) msg = {} msg['sourcehost'] = socket.getfqdn() if sys.argv[1] == 'big': msg['message'] = "bigmessage_datadatadatadatadatadata\n" * 120 # packet exceeds typical 1500 MTU else: msg['message'] = "smallmessage_datadatadatadatadatadata\n" sock.send(json.dumps(msg)) if sys.argv[2] == 'slow': time.sleep(SLEEP_TIME) sock.close() sys.exit(0)