-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopology.py
100 lines (76 loc) · 2.89 KB
/
topology.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
#!/usr/bin/python
"""
A simple minimal topology script for Mininet.
Based in part on examples in the [Introduction to Mininet] page on the Mininet's
project wiki.
[Introduction to Mininet]: https://github.com/mininet/mininet/wiki/Introduction-to-Mininet#apilevels
"""
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.net import Mininet
from mininet.topo import Topo
from mininet.node import RemoteController, OVSSwitch
from mininet.link import TCLink
# from topo import topo2file, FatTree, FatTreeOutBand
class MinimalTopo( Topo ):
"Minimal topology with a single switch and two hosts"
def build( self ):
# Create two hosts.
h0 = self.addHost('h000')
h1 = self.addHost('h001')
h2 = self.addHost('h002')
h3 = self.addHost('h003')
h4 = self.addHost('h004')
h5 = self.addHost('h005')
h6 = self.addHost('h006')
h7 = self.addHost('h007')
# Create a switch
s1 = self.addSwitch( 's001', protocols='OpenFlow10' )
s2 = self.addSwitch( 's002', protocols='OpenFlow10' )
s3 = self.addSwitch( 's003', protocols='OpenFlow10' )
s4 = self.addSwitch( 's004', protocols='OpenFlow10' )
# Add links between the switch and each host
# linkopts = dict(bw=1000)
self.addLink(s1, s2)
self.addLink(s1, s3)
self.addLink(s1, s4)
self.addLink(s2, s3)
self.addLink(s2, s4)
self.addLink(s3, s4)
self.addLink(s1, h0)
self.addLink(s1, h1)
self.addLink(s2, h2)
self.addLink(s2, h3)
self.addLink(s3, h4)
self.addLink(s3, h5)
self.addLink(s4, h6)
self.addLink(s4, h7)
def runMinimalTopo():
"Bootstrap a Mininet network using the Minimal Topology"
# Create an instance of our topology
topo = MinimalTopo()
# Create a network based on the topology using OVS and controlled by
# a remote controller.
net = Mininet(
topo=topo,
controller=lambda name: RemoteController( name, ip='127.0.0.1', port=6633, protocols='OpenFlow10' ),
switch=OVSSwitch,
link=TCLink,
autoSetMacs=True )
# c1 = net.addController('c1', controller=RemoteController, ip='127.0.0.1', port=6643, protocols='OpenFlow10')
# c2 = net.addController('c2', controller=RemoteController, ip='127.0.0.1', port=6653, protocols='OpenFlow10')
# c2 = net.addController('c2', controller=RemoteController, ip="127.0.0.1", port=6633)
# Actually start the network
net.start()
# Drop the user in to a CLI so user can run commands.
CLI( net )
# After the user exits the CLI, shutdown the network.
net.stop()
if __name__ == '__main__':
# This runs if this file is executed directly
setLogLevel( 'info' )
runMinimalTopo()
# Allows the file to be imported using `mn --custom <filename> --topo minimal`
topos = {
'minimal': MinimalTopo
}