-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_topo.py
88 lines (70 loc) · 2.28 KB
/
test_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
#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
from mininet.node import RemoteController
from mininet.node import OVSSwitch
from mininet.cli import CLI
import os
import time
class MyTopo( Topo ):
#Simple topology example.
Switches = []
Hosts = []
def __init__(self):
#init topo
Topo.__init__(self)
def create_init(self):
self.createtopo()
def createtopo(self):
#create switches and hosts
#Switches
self.Switches.append(self.addSwitch('s1001'))
self.Switches.append(self.addSwitch('s2001'))
self.Switches.append(self.addSwitch('s2002'))
#Hosts
self.Hosts.append(self.addHost('h3001'))
self.Hosts.append(self.addHost('h3002'))
self.Hosts.append(self.addHost('h3003'))
self.Hosts.append(self.addHost('h3004'))
def createlinks(self):
###Add links###
self.addLink(self.Switches[0],self.Switches[1])
self.addLink(self.Switches[0],self.Switches[2])
self.addLink(self.Switches[1],self.Hosts[0])
self.addLink(self.Switches[1],self.Hosts[1])
self.addLink(self.Switches[2],self.Hosts[2])
self.addLink(self.Switches[2],self.Hosts[3])
def enable_ISP_OpenFlow(self):
for sw in self.Switches:
cmd = "sudo ovs-vsctl set bridge %s stp_enable=true" % sw
os.system(cmd)
print(cmd)
cmd = "sudo ovs-vsctl set bridge %s protocols=OpenFlow13" % sw
os.system(cmd)
print(cmd)
def emul_start():
"Crerate network and run simple performance test"
topo = MyTopo()
print("Create topo...")
topo.create_init() #create topology
print("Create links...")
topo.createlinks() #create links
topo.enable_ISP_OpenFlow()
###******###
net = Mininet(topo=topo, link=TCLink, controller=None, autoSetMacs=True) #autosetmac will let the MAC of switches be in order
###******###
#net = Mininet(topo=topo, link=TCLink, autoSetMacs=True)
#print("Add controller...")
net.addController('controller', controller=RemoteController, ip="10.0.2.15", port=6653)
net.start() #start Mininet
net.pingAll() #do pingall test
CLI(net) #for debugging
net.stop() # stop Mininet
if __name__ == '__main__':
# Set log level
# you can use 'info', 'warning', 'critical', 'error', 'debug', 'output'
setLogLevel('info')
emul_start()