-
Notifications
You must be signed in to change notification settings - Fork 2
/
mn_topo.py
144 lines (113 loc) · 5.03 KB
/
mn_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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import os
import shutil
import sys
import time
import math
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.net import Mininet
from mininet.topo import Topo
from mininet.node import OVSKernelSwitch, RemoteController, Node
from mininet.term import makeTerm
from mininet.link import TCLink
from comnetsemu.net import Containernet
class LinuxRouter(Node):
def config(self, **params):
super(LinuxRouter, self).config(**params)
self.cmd('sysctl net.ipv4.ip_forward=1')
def terminate(self):
self.cmd('sysctl net.ipv4.ip_forward=0')
super(LinuxRouter, self).terminate()
class Topology(Topo):
def build(self):
# aggiungo
h11 = self.addHost("it1", ip="192.168.2.73/24",defaultRoute='via 192.168.2.1',mac='00:00:00:00:00:0c')
h12 = self.addHost("it2", ip="192.168.2.74/24",defaultRoute='via 192.168.2.1',mac='00:00:00:00:00:0d')
h1 = self.addHost("a3", ip="192.168.2.21/24",defaultRoute='via 192.168.2.1',mac='00:00:00:00:00:01')
h2 = self.addHost("a4", ip="192.168.2.41/24",defaultRoute='via 192.168.2.1',mac='00:00:00:00:00:02')
h3 = self.addHost("h1", ip="192.168.2.22/24",defaultRoute='via 192.168.2.1',mac='00:00:00:00:00:03')
h4 = self.addHost("h2", ip="192.168.2.31/24",defaultRoute='via 192.168.2.1',mac='00:00:00:00:00:04')
h5 = self.addHost("h3", ip="192.168.2.32/24",defaultRoute='via 192.168.2.1',mac='00:00:00:00:00:05')
h6 = self.addHost("h4", ip="192.168.2.42/24",defaultRoute='via 192.168.2.1',mac='00:00:00:00:00:06')
h7 = self.addHost("h5", ip="192.168.2.51/24",defaultRoute='via 192.168.2.1',mac='00:00:00:00:00:07')
h8 = self.addHost("h6", ip="192.168.2.52/24",defaultRoute='via 192.168.2.1',mac='00:00:00:00:00:08')
h9 = self.addHost("a1", ip="192.168.3.61/24",defaultRoute='via 192.168.3.1',mac='00:00:00:00:00:09')
h10 = self.addHost("a2", ip="192.168.3.62/24",defaultRoute='via 192.168.3.1',mac='00:00:00:00:00:0a')
# aggiungo sftp
h13 = self.addHost("sftp", ip="192.168.2.75/24",defaultRoute='via 192.168.2.1',mac='00:00:00:00:00:0b')
# aggiungo i router
r1 = self.addHost("r1",cls=LinuxRouter,ip="192.168.2.1/24",mac='00:00:00:00:00:0e')
r2 = self.addHost("r2",cls=LinuxRouter,ip="192.168.3.1/24",mac='00:00:00:00:00:0f')
# aggiungo gli switch
for i in range(7):
sconfig = {"dpid": "%016x" % (i + 1)}
self.addSwitch("s%d" % (i + 1), protocols="OpenFlow10", **sconfig)
# creo topologia a stella con controller in mezzo
self.addLink("s1","s2")
self.addLink("s1","s3")
self.addLink("s1","s4")
self.addLink("s1","s5")
# collego pc agli switch per office1
self.addLink("s2","a3")
self.addLink("s2","h1")
self.addLink("s3","h2")
self.addLink("s3","h3")
# collego pc agli switch per office2
self.addLink("s4","a4")
self.addLink("s4","h4")
self.addLink("s5","h5")
self.addLink("s5","h6")
# collego pc allo switch per office3
self.addLink("s6","a1")
self.addLink("s6","a2")
# collego ufficio it
self.addLink("s7","it1")
self.addLink("s7","it2")
self.addLink("s7","sftp")
self.addLink("s1","r1",intfName2='r1-eth1',params2={'ip':'192.168.2.1/24'})
self.addLink("s6","r2",intfName2='r2-eth1',params2={'ip':'192.168.3.1/24'})
self.addLink("s1","s7")
self.addLink(r1,
r2,
intfName1='r1-eth2',
intfName2='r2-eth2',
params1={'ip': '10.100.0.1/24'},
params2={'ip': '10.100.0.2/24'})
def runTopo():
topo = Topology()
net = Mininet(
topo=topo,
switch=OVSKernelSwitch,
build=False,
autoSetMacs=True,
autoStaticArp=True,
link=TCLink,
)
controller = RemoteController("c1", ip="127.0.0.1", port=6633)
net.addController(controller)
net.start()
# creo il bridge per comunicare con il raspberry
n = net.getNodeByName("s7")
print("*** Setting up bridge network")
time.sleep(0.1)
n.cmd('sudo ovs-vsctl add-port s7 eth1')
# setup router
net['r1'].cmd("sudo ip route add 192.168.3.0/24 via 10.100.0.2 dev r1-eth2")
net['r2'].cmd("sudo ip route add 192.168.2.0/24 via 10.100.0.1 dev r2-eth2")
# setup ssh socket in h5 e sftp
net['sftp'].cmd("python3 sshsocket.py &")
net['h5'].cmd("python3 sshsocket.py &")
time.sleep(0.3)
# setup voip socket
voip = [net['h1'],net['h2'],net['h3'],net['h4'],net['h5'],net['h6'],net['a1'],net['a2'],net['a3'],net['a4'],net['it1'],net['it2']]
for h in voip:
h.cmd("python3 voipsocket.py &")
time.sleep(0.1)
print(f"Started {str(h)} socket")
print("All socket started")
n.cmd("hostname comnetsemu")
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
runTopo()