1#!/usr/bin/python
2#
3# fragmentation.py
4#
5# Fragmentation test with PicoTCP sending and Linux receiving
6#
7# (sender)                         (Receiver)
8# PicoTCP ------------------------ Linux
9#
10# An udpclient is started which will give DATASIZE bytes in one go
11# to the socket. This data will be fragmented and send over to the
12# Linux, where it is reassembled and received in one piece.
13#
14
15from  topology import *
16import socket, random, string
17
18SRC_ADDR = ''
19DST_ADDR = '172.16.1.1'
20SRC_PORT = 6667
21SENDTO_PORT = 6667
22LISTEN_PORT = 6667
23DATASIZE = 4000
24LOOPS = 4
25SUBLOOPS = 1
26UDPCLIENT = "udpclient:" + str(DST_ADDR) + ":" + str(SENDTO_PORT) + ":"  + str(LISTEN_PORT) + ":" + str(DATASIZE) + ":" + str(LOOPS) + ":" + str(SUBLOOPS)
27
28print UDPCLIENT
29
30T = Topology()
31net1 = Network(T, "pyt0")
32h1 = Host(T, net1, args=UDPCLIENT)
33
34s_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
35s_udp.bind((SRC_ADDR, SRC_PORT))
36s_udp.settimeout(5);
37
38raw_input("Press enter to continue ...")
39start(T)
40
41while True:
42  data, addr = s_udp.recvfrom(DATASIZE)
43  #print data
44  if len(data) == DATASIZE:
45    print '\n\n'
46    print '+++++++++++++++++++++++++++++++++++++++++++++'
47    print '+++++ fragmentation test IS successful +++++'
48    print '+++++++++++++++++++++++++++++++++++++++++++++'
49    print '\n\n'
50    cleanup()
51    exit(0)
52
53print '\n\n'
54print '+++++++++++++++++++++++++++++++++++++++++++++'
55print '+++++ fragmentation test NOT successful ++++'
56print '+++++++++++++++++++++++++++++++++++++++++++++'
57print '\n\n'
58cleanup()
59exit(1)
60
61