1#!/usr/bin/python 2# 3# reassemby.py 4# 5# Reassemly test with PicoTCP receiving and Linux sending 6# 7# (receiver) (Sender) 8# PicoTCP ------------------------ Linux 9# 10# An udpecho is started which will receive DATASIZE bytes in one go 11# from the socket. The Linux will send DATASIZE bytes in one go to the 12# udpecho, this data will be sent fragmented. The udpecho is to reassemble 13# this data and echo it back. 14# 15 16from topology import * 17import socket, random, string 18 19SRC_ADDR = '' 20LINK_ADDR = '172.16.1.2' 21SRC_PORT = 5555 22LISTEN_PORT = 6667 23SENDTO_PORT = 5555 24DATASIZE = 3400 25UDPECHO = "udpecho:" + str(LINK_ADDR) + ":" + str(LISTEN_PORT) + ":" + str(SENDTO_PORT) + ":" + str(DATASIZE) 26 27print UDPECHO 28 29T = Topology() 30net1 = Network(T, "pyt0") 31h1 = Host(T, net1, args=UDPECHO) 32 33str_send = ''.join(random.choice(string.ascii_lowercase) for x in range(DATASIZE)) 34#print str_send 35s_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 36s_udp.bind((SRC_ADDR, SRC_PORT)) 37s_udp.settimeout(5); 38 39raw_input("Press enter to continue ...") 40start(T) 41 42while True: 43 s_udp.sendto(str_send, (LINK_ADDR, LISTEN_PORT)) 44 data = s_udp.recv(DATASIZE) 45 #print len(data) 46 if len(data) == DATASIZE: 47 print '\n\n' 48 print '+++++++++++++++++++++++++++++++++++++++++++++' 49 print '+++++ reassembly test IS successful +++++' 50 print '+++++++++++++++++++++++++++++++++++++++++++++' 51 print '\n\n' 52 cleanup() 53 exit(0) 54 55print '\n\n' 56print '+++++++++++++++++++++++++++++++++++++++++++++' 57print '+++++ reassembly test NOT successful ++++' 58print '+++++++++++++++++++++++++++++++++++++++++++++' 59print '\n\n' 60cleanup() 61exit(1) 62 63