-
Notifications
You must be signed in to change notification settings - Fork 0
/
mytop.py
76 lines (53 loc) · 1.92 KB
/
mytop.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
#!/usr/bin/env python
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSKernelSwitch, UserSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from subprocess import call
def myNetwork():
net = Mininet( topo=None,
listenPort=6633,
build=False,
ipBase='10.0.0.0/8')
info( '*** Adding controller\n' )
c0=net.addController(name='c0',
controller=RemoteController,
ip='127.0.0.1',
protocol='tcp',
port=6633)
info( '*** Add switches\n')
s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
info('*** Add hosts\n')
hosts = {}
for i in range(1, 7):
host_name = 'h{}'.format(i)
ip_address = '10.0.0.{}'.format(i)
hosts[host_name] = net.addHost(host_name, cls=Host, ip=ip_address, defaultRoute=None)
info('*** Add links\n')
for host in hosts.values():
if str(host) == 'h3' or str(host) == 'h4':
net.addLink(host, s1, cls=TCLink, delay='50ms')
else:
net.addLink(host, s1, cls=TCLink, delay='1ms')
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches\n')
net.get('s1').start([c0])
info('*** Starting HTTP servers on hosts h1 to h4\n')
for i in range(1, 5):
host_name = 'h{}'.format(i)
host = hosts[host_name]
host.cmd('python3 -m http.server 80 &')
info( '*** Post configure switches and hosts\n')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
myNetwork()