-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopo.py
111 lines (90 loc) · 3.47 KB
/
topo.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet, Host
from mininet.log import setLogLevel
from mininet.cli import CLI
from mininet.node import OVSSwitch, Controller, RemoteController
from mininet.link import TCLink
from time import sleep
import random
'''
s1
h1 h2 h3 h4 h5 h6 h7 h8 h9 h10
'''
TEST_TIME = 30 #seconds
TEST_TYPE = "normal"
#normal, attack, manual
class SingleSwitchTopo(Topo):
"Single switch connected to 10 hosts."
def build(self):
s1 = self.addSwitch('s1')
h1 = self.addHost('h1', ip='10.1.1.1/24', mac="00:00:00:00:00:01", defaultRoute="via 10.1.1.10")
h2 = self.addHost('h2', ip='10.1.1.2/24', mac="00:00:00:00:00:02", defaultRoute="via 10.1.1.10")
h3 = self.addHost('h3', ip='10.1.1.3/24', mac="00:00:00:00:00:03", defaultRoute="via 10.1.1.10")
h4 = self.addHost('h4', ip='10.1.1.4/24', mac="00:00:00:00:00:04", defaultRoute="via 10.1.1.10")
h5 = self.addHost('h5', ip='10.1.1.5/24', mac="00:00:00:00:00:05", defaultRoute="via 10.1.1.10")
h6 = self.addHost('h6', ip='10.1.1.6/24', mac="00:00:00:00:00:06", defaultRoute="via 10.1.1.10")
h7 = self.addHost('h7', ip='10.1.1.7/24', mac="00:00:00:00:00:07", defaultRoute="via 10.1.1.10")
h8 = self.addHost('h8', ip='10.1.1.8/24', mac="00:00:00:00:00:08", defaultRoute="via 10.1.1.10")
h9 = self.addHost('h9', ip='10.1.1.9/24', mac="00:00:00:00:00:09", defaultRoute="via 10.1.1.10")
h10 = self.addHost('h10', ip='10.1.1.10/24', mac="00:00:00:00:00:10", defaultRoute="via 10.1.1.10")
self.addLink(h1, s1, cls=TCLink, bw=5)
self.addLink(h2, s1, cls=TCLink, bw=5)
self.addLink(h3, s1, cls=TCLink, bw=5)
self.addLink(h4, s1, cls=TCLink, bw=5)
self.addLink(h5, s1, cls=TCLink, bw=5)
self.addLink(h6, s1, cls=TCLink, bw=5)
self.addLink(h7, s1, cls=TCLink, bw=5)
self.addLink(h8, s1, cls=TCLink, bw=5)
self.addLink(h9, s1, cls=TCLink, bw=5)
self.addLink(h10, s1, cls=TCLink, bw=5)
if __name__ == '__main__':
setLogLevel('info')
topo = SingleSwitchTopo()
c1 = RemoteController('c1', ip='127.0.0.1')
net = Mininet(topo=topo, controller=c1)
net.start()
if TEST_TYPE == "normal":
print ("Generating NORMAL Traffic.......")
h1 = net.get('h1')
cmd1 = "bash normal.sh &"
h1.cmd(cmd1)
h2 = net.get('h2')
cmd1 = "bash normal.sh &"
h2.cmd(cmd1)
h3 = net.get('h3')
cmd1 = "bash normal.sh &"
h3.cmd(cmd1)
h4 = net.get('h4')
cmd1 = "bash normal.sh &"
h4.cmd(cmd1)
h5 = net.get('h5')
cmd1 = "bash normal.sh &"
h5.cmd(cmd1)
h6 = net.get('h6')
cmd1 = "bash normal.sh &"
h6.cmd(cmd1)
h7 = net.get('h7')
cmd1 = "bash normal.sh &"
h7.cmd(cmd1)
h8 = net.get('h8')
cmd1 = "bash normal.sh &"
h8.cmd(cmd1)
h9 = net.get('h9')
cmd1 = "bash normal.sh &"
h9.cmd(cmd1)
h10 = net.get('h10')
cmd1 = "bash normal.sh &"
h10.cmd(cmd1)
sleep(TEST_TIME)
net.stop()
elif TEST_TYPE == "attack":
print ("Generating ATTACK Traffic.......")
h1 = net.get('h1')
cmd1 = "bash attack.sh &"
h1.cmd(cmd1)
sleep(TEST_TIME)
net.stop()
elif TEST_TYPE == "manual":
CLI(net)
net.stop()