-
Notifications
You must be signed in to change notification settings - Fork 1
/
pratica-2-II.py
62 lines (50 loc) · 1.59 KB
/
pratica-2-II.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
import atexit
import time
from mininet.net import Mininet
from mininet.topo import Topo
from mininet.cli import CLI
from mininet.log import info,setLogLevel
from mininet.node import Controller
from functools import partial
from mininet.node import RemoteController
from mininet.util import irange,dumpNodeConnections
net = None
def createTopo():
topo=Topo()
swCore1 = topo.addSwitch('s1')
## Ajuste do parametro de fanout da rede
fanout = 2
# Switches counter
lastSW = 2
lastHost = 1
# Aggregation switches loop
for i in irange (1, fanout):
swAggregL = topo.addSwitch('s%s' % lastSW)
topo.addLink(swCore1, swAggregL)
lastSW += 1
# Edge switches loop
for j in irange (1, fanout):
swEdge = topo.addSwitch('s%s' % lastSW)
topo.addLink(swAggregL, swEdge)
lastSW += 1
# Hosts loop
for k in irange (1, fanout):
host = topo.addHost('h%s' % lastHost)
topo.addLink(swEdge, host)
lastHost += 1
return topo
def startNetwork():
topo = createTopo()
global net
net = Mininet( topo=topo, controller=None)
net.addController( 'c0', controller=RemoteController, ip='127.0.0.1', port=6633 )
net.start()
time.sleep(20)
CLI(net)
def stopNetwork():
if net is not None:
net.stop()
if __name__ == '__main__':
atexit.register(stopNetwork)
setLogLevel('info')
startNetwork()