-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster3.py
63 lines (56 loc) · 2.08 KB
/
cluster3.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
#!/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 = 3
h_range = int(argv[1])
packets = int(argv[2])
p_interval = int(argv[3])
c1addr = '192.168.56.1'
c2addr = '192.168.56.100'
c3addr = '192.168.56.100'
system("echo 'h1 nohup python gen_normal_packet.py " + str(h_range) + " " + str(packets)
+ " " + str(p_interval) + " /dev/null 2>&1 &' > gen_scapy.sh")
system("echo 'h" + str(h_range/2 + 1) + " nohup python gen_normal_packet.py " + str(h_range) + " " + str(packets)
+ " " + str(p_interval) + " /dev/null 2>&1 &' >> gen_scapy.sh")
system("echo 'h" + str(h_range) + " nohup python gen_normal_packet.py " + str(h_range) + " " + str(packets)
+ " " + str(p_interval) + " /dev/null 2>&1 &' >> gen_scapy.sh")
net = Mininet(topo=None, controller=RemoteController, switch=OVSKernelSwitch,
link=TCLink)
c1 = net.addController('c1', controller=RemoteController, ip=c1addr,
port=6653)
c2 = net.addController('c2', controller=RemoteController, ip=c2addr,
port=6653)
c3 = net.addController('c3', controller=RemoteController, ip=c3addr,
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))
net.build()
c1.start()
c2.start()
c2.start()
switches[0].start([c1])
switches[1].start([c2])
switches[2].start([c3])
CLI(net, script='gen_scapy.sh')
CLI(net)
if __name__ == '__main__':
# Tell mininet to print useful information
setLogLevel('info')
emptyNet()