1 # Copyright (C) 2008 Michael J. Silbersack. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
6 # 1. Redistributions of source code must retain the above copyright
7 # notice unmodified, this list of conditions, and the following
9 # 2. Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
13 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 # This is a regression test to verify the proper behavior of IP ID generation
27 # code. It will push 200000 packets, then report back what the min and max
28 # periods it saw for different IDs were.
35 if os.path.exists('results.pcap'):
36 os.remove('results.pcap')
37 tcpdump = subprocess.Popen('tcpdump -n -i lo0 -w results.pcap icmp', shell=True)
38 time.sleep(1) # Give tcpdump time to start
40 os.system('sysctl net.inet.icmp.icmplim=0')
41 os.system('ping -q -i .001 -c 100000 127.0.0.1')
43 time.sleep(3) # Give tcpdump time to catch up
44 os.kill(tcpdump.pid, signal.SIGTERM)
46 os.system('tcpdump -n -v -r results.pcap > results.txt')
52 for line in open('results.txt').readlines():
53 id = int(line.split(' id ')[1].split(',')[0])
54 if id_lastseen.has_key(id):
55 period = count - id_lastseen[id]
56 if not id_minperiod.has_key(id) or period < id_minperiod[id]:
57 id_minperiod[id] = period
58 id_lastseen[id] = count
61 sorted_minperiod = zip(*reversed(zip(*id_minperiod.items())))
62 sorted_minperiod.sort()
64 print "Lowest 10 ID periods detected:"
67 id_tuple = sorted_minperiod.pop(0)
68 print "id: %d period: %d" % (id_tuple[1], id_tuple[0])
71 print "Highest 10 ID periods detected:"
74 id_tuple = sorted_minperiod.pop()
75 print "id: %d period: %d" % (id_tuple[1], id_tuple[0])