-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcap_gen.py
97 lines (79 loc) · 2.62 KB
/
pcap_gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from scapy.all import Ether, IP, UDP, Raw, wrpcap
import random
a = "10:10:10:10:10:10"
b = "20:20:20:20:20:20"
c = "30:30:30:30:30:30"
d = "40:40:40:40:40:40"
e = "50:50:50:50:50:50"
f = "60:60:60:60:60:60"
g = "70:70:70:70:70:70"
dummy = "1:1:1:1:1:1"
def three_flows():
packets = []
srcs = [a, b, c] * 3 + [a]
for src in srcs:
packets += Ether(src=src, dst=dummy) / IP(src="1.1.1.1", dst="1.1.1.1")
for i, p in enumerate(packets):
p.time = i / 10
return packets
def three_flows_bursty():
packets = []
srcs = [a, b, c] * 16 + [a, b]
for src in srcs:
packets += Ether(src=src, dst=dummy) / IP(src="1.1.1.1", dst="1.1.1.1")
time = 0
for i, p in enumerate(packets):
p.time = (i / 10) + int(i / 5)
return packets
def two_then_three():
packets = []
srcs = [b, c] * 7 + [a] * 6 + [a, b, c] * 10
for src in srcs:
packets += Ether(src=src, dst=dummy) / IP(src="1.1.1.1", dst="1.1.1.1")
for i, p in enumerate(packets):
p.time = i / 10
return packets
def four_flows():
packets = []
srcs = [a, b, c, d] * 12 + [a, b]
for src in srcs:
packets += Ether(src=src, dst=dummy) / IP(src="1.1.1.1", dst="1.1.1.1")
for i, p in enumerate(packets):
p.time = i / 10
return packets
def five_flows():
packets = []
srcs = [a, b, c, d, e] * 10
for src in srcs:
packets += Ether(src=src, dst=dummy) / IP(src="1.1.1.1", dst="1.1.1.1")
for i, p in enumerate(packets):
p.time = i / 10
return packets
def seven_flows():
packets = []
srcs = [a, b, c, d, e, f, g] * 7 + [a]
for src in srcs:
packets += Ether(src=src, dst=dummy) / IP(src="1.1.1.1", dst="1.1.1.1")
for i, p in enumerate(packets):
p.time = i / 10
return packets
def four_flows_diff_size():
packets = []
srcs = [a, b, c, d] * 12 + [a, b]
for src in srcs:
data = "F"*random.randint(25,50)
packets += Ether(src=src, dst=dummy) / IP(src="1.1.1.1", dst="1.1.1.1") / UDP(sport=123,dport=456) / Raw(data)
for i, p in enumerate(packets):
p.time = i / 10
return packets
def generate_pcaps():
# wrpcap("./pcaps/three_flows.pcap", three_flows())
# wrpcap("./pcaps/three_flows_bursty.pcap", three_flows_bursty())
wrpcap("./pcaps/two_then_three.pcap", two_then_three())
wrpcap("./pcaps/four_flows.pcap", four_flows())
wrpcap("./pcaps/five_flows.pcap", five_flows())
wrpcap("./pcaps/seven_flows.pcap", seven_flows())
wrpcap("./pcaps/four_flows_diff_size.pcap", four_flows_diff_size())
if __name__ == "__main__":
random.seed(5)
generate_pcaps()