]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - tools/regression/netinet/ip_id_period/ip_id_period.py
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / tools / regression / netinet / ip_id_period / ip_id_period.py
1 # Copyright (C) 2008 Michael J. Silbersack.  All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
5 # are met:
6 # 1. Redistributions of source code must retain the above copyright
7 #    notice unmodified, this list of conditions, and the following
8 #    disclaimer.
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.
12 #
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.
23 #
24 # $FreeBSD$
25 #
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.
29
30 import os
31 import signal
32 import subprocess
33 import time
34
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
39
40 os.system('sysctl net.inet.icmp.icmplim=0')
41 os.system('ping -q -i .001 -c 100000 127.0.0.1')
42
43 time.sleep(3) # Give tcpdump time to catch up
44 os.kill(tcpdump.pid, signal.SIGTERM)
45
46 os.system('tcpdump -n -v -r results.pcap > results.txt')
47
48 id_lastseen = {}
49 id_minperiod = {}
50
51 count = 0
52 for line in open('results.txt').readlines():
53     id = int(line.split(' id ')[1].split(',')[0])
54     if id in id_lastseen:
55         period = count - id_lastseen[id]
56         if id not in id_minperiod or period < id_minperiod[id]:
57             id_minperiod[id] = period
58     id_lastseen[id] = count
59     count += 1
60
61 sorted_minperiod = list(zip(*reversed(list(zip(*list(id_minperiod.items()))))))
62 sorted_minperiod.sort()
63
64 print("Lowest 10 ID periods detected:")
65 x = 0
66 while x < 10:
67     id_tuple = sorted_minperiod.pop(0)
68     print("id: %d period: %d" % (id_tuple[1], id_tuple[0]))
69     x += 1
70
71 print("Highest 10 ID periods detected:")
72 x = 0
73 while x < 10:
74     id_tuple = sorted_minperiod.pop()
75     print("id: %d period: %d" % (id_tuple[1], id_tuple[0]))
76     x += 1