Repository navigation
Expand file tree
/
Copy pathmulti_topo_scapy.py
More file actions
55 lines (47 loc) · 1.77 KB
/
Copy pathmulti_topo_scapy.py
File metadata and controls
55 lines (47 loc) · 1.77 KB
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
#!/usr/bin/python
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host
from mininet.node import OVSKernelSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from os import system
from sys import argv
def emptyNet():
s_range = int(argv[1])
h_range = int(argv[2])
packets = int(argv[3])
p_interval = float(argv[4])
ddos_packets = int(argv[5])
ddos_interval = int(argv[6])
system("echo 'attacker python gen_ddos_packet.py target " + str(ddos_packets)
+ " " + str(ddos_interval) + " &' > gen_scapy.sh")
system("echo 'h1 python gen_normal_packet.py " + str(h_range) + " " + str(packets)
+ " " + str(p_interval) + " &' >> gen_scapy.sh")
net = Mininet(topo=None, controller=RemoteController, switch=OVSKernelSwitch,
link=TCLink)
c1 = net.addController('c1', controller=RemoteController, ip='192.168.56.1',
port=6653)
hosts = []
switches = []
h = 0
for s in range(s_range):
switches.append(net.addSwitch('s' + str(s), protocols='OpenFlow13'))
for h in range(h + 1, h + 1 + h_range/s_range):
hosts.append(net.addHost('h' + str(h)))
net.addLink('s' + str(s), 'h' + str(h))
for s in range(s_range - 1):
net.addLink('s' + str(s), 's' + str(s+1))
attacker = net.addHost('attacker')
target = net.addHost('target')
net.addLink('s0', 'attacker')
net.addLink('s' + str(s_range - 1), 'target')
net.start()
CLI(net, script='gen_scapy.sh')
CLI(net)
if __name__ == '__main__':
# Tell mininet to print useful information
setLogLevel('info')
emptyNet()