-
Notifications
You must be signed in to change notification settings - Fork 0
/
abilene_origin.py
168 lines (149 loc) · 7.31 KB
/
abilene_origin.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/python
"""
Custom topology for Mininet, generated by GraphML-Topo-to-Mininet-Network-Generator.
"""
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.node import Node,OVSKernelSwitch
from mininet.node import CPULimitedHost
from mininet.link import TCLink
from mininet.cli import CLI
from mininet.log import setLogLevel,info
class GeneratedTopo( Topo ):
"Internet Topology Zoo Specimen."
def __init__( self, **opts ):
"Create a topology."
# Initialize Topology
Topo.__init__( self, **opts )
# add nodes
# switches first
NewYork = self.addSwitch( 's1' , cls=OVSKernelSwitch, dpid='0000000000000001')
Chicago = self.addSwitch( 's2' , cls=OVSKernelSwitch, dpid='0000000000000002')
WashingtonDC = self.addSwitch( 's3' , cls=OVSKernelSwitch, dpid='0000000000000003')
Seattle = self.addSwitch( 's4' , cls=OVSKernelSwitch, dpid='0000000000000004')
Sunnyvale = self.addSwitch( 's5' , cls=OVSKernelSwitch, dpid='0000000000000005')
LosAngeles = self.addSwitch( 's6' , cls=OVSKernelSwitch, dpid='0000000000000006')
Denver = self.addSwitch( 's7' , cls=OVSKernelSwitch, dpid='0000000000000007')
KansasCity = self.addSwitch( 's8' , cls=OVSKernelSwitch, dpid='0000000000000008')
Houston = self.addSwitch( 's9' , cls=OVSKernelSwitch, dpid='0000000000000009')
Atlanta = self.addSwitch( 's10' , cls=OVSKernelSwitch, dpid='0000000000000010')
Indianapolis = self.addSwitch( 's11' , cls=OVSKernelSwitch, dpid='0000000000000011')
# and now hosts
NewYork_host = self.addHost( 'h0' )
Chicago_host = self.addHost( 'h1' )
WashingtonDC_host = self.addHost( 'h2' )
Seattle_host = self.addHost( 'h3' )
Sunnyvale_host = self.addHost( 'h4' )
LosAngeles_host = self.addHost( 'h5' )
Denver_host = self.addHost( 'h6' )
KansasCity_host = self.addHost( 'h7' )
Houston_host = self.addHost( 'h8' )
Atlanta_host = self.addHost( 'h9' )
Indianapolis_host = self.addHost( 'h10' )
# hosts (put here if needed)
# dont forget to add edges afterwards!
#FIXME host and links section needs adjusting to your topology needs!!!
# this are just exemplarical entries,
# fitting my topology and needs.
# I left this here as an sample entry.
#FIXME this was needed before a host per switch was generated and linked
#node1 = self.addHost( 'h1' )
#node2 = self.addHost( 'h2' )
# next tree lines never put to use so far
#node3 = self.addHost( 'rcv1' )
#node4 = self.addHost( 'rcv2' )
#node5 = self.addHost( 'logserv' )
#self.addLink( HAM , node1 )
#self.addLink( GAR , node2 )
# add edges between switch and corresponding host
self.addLink( NewYork , NewYork_host )
self.addLink( Chicago , Chicago_host )
self.addLink( WashingtonDC , WashingtonDC_host )
self.addLink( Seattle , Seattle_host )
self.addLink( Sunnyvale , Sunnyvale_host )
self.addLink( LosAngeles , LosAngeles_host )
self.addLink( Denver , Denver_host )
self.addLink( KansasCity , KansasCity_host )
self.addLink( Houston , Houston_host )
self.addLink( Atlanta , Atlanta_host )
self.addLink( Indianapolis , Indianapolis_host )
# add edges between switches
self.addLink( NewYork , Chicago, bw=10, delay='0.690677696537ms')
self.addLink( NewYork , WashingtonDC, bw=10, delay='0.518903303662ms')
self.addLink( Chicago , Indianapolis, bw=10, delay='1.15170240387ms')
self.addLink( WashingtonDC , Atlanta, bw=10, delay='0.477628158502ms')
self.addLink( Seattle , Sunnyvale, bw=10, delay='1.10351797289ms')
self.addLink( Seattle , Denver, bw=10, delay='0.952189623151ms')
self.addLink( Sunnyvale , LosAngeles, bw=10, delay='0.506044716762ms')
self.addLink( Sunnyvale , Denver, bw=10, delay='0.85423284091ms')
self.addLink( LosAngeles , Houston, bw=10, delay='1.02920365882ms')
self.addLink( Denver , KansasCity, bw=10, delay='0.191285963954ms')
self.addLink( KansasCity , Houston, bw=10, delay='1.46743666378ms')
self.addLink( KansasCity , Indianapolis, bw=10, delay='0.206336052247ms')
self.addLink( Houston , Atlanta, bw=10, delay='1.15068985002ms')
self.addLink( Atlanta , Indianapolis, bw=10, delay='0.466772343871ms')
topos = { 'generated': ( lambda: GeneratedTopo() ) }
# here the code defining the topology ends
# the following code produces an executable script working with a remote controller
# and ssh access to the the mininet hosts from within the ubuntu vm
def setupNetwork():
"Create network and run simple performance test"
topo = GeneratedTopo()
net = Mininet(topo=topo, controller=lambda a: RemoteController( a, ip='127.0.0.1', port=6633 ), host=CPULimitedHost, link=TCLink)
# net.build()
# CLI(net)
# net.stop()
# print "Testing network connectivity"
# net.pingAll()
# print "Testing bandwidth between h1 and h2"
# h1, h2 = net.getNodeByName('h1', 'h2')
# net.iperf((h1, h2))
return net
def connectToRootNS( network, switch, ip, prefixLen, routes ):
"""Connect hosts to root namespace via switch. Starts network.
network: Mininet() network object
switch: switch to connect to root namespace
ip: IP address for root namespace node
prefixLen: IP address prefix length (e.g. 8, 16, 24)
routes: host networks to route to"""
# Create a node in root namespace and link to switch 0
root = Node( 'root', inNamespace=False )
intf = TCLink( root, switch ).intf1
root.setIP( ip, prefixLen, intf )
# Start network that now includes link to root namespace
network.start()
# Add routes from root ns to hosts
for route in routes:
root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
def sshd( network, cmd='/usr/sbin/sshd', opts='-D' ):
"Start a network, connect it to root ns, and run sshd on all hosts."
switch = network.switches[ 0 ] # switch to use
ip = '10.123.123.1' # our IP address on host network
routes = [ '10.0.0.0/8' ] # host networks to route to
connectToRootNS( network, switch, ip, 8, routes )
for host in network.hosts:
host.cmd( cmd + ' ' + opts + '&' )
print
print "*** Hosts are running sshd at the following addresses:"
print
#FIXME: when host lacks an interface because of broken setup process, dont call it!
#FIXME: host.IP() will trigger a warning and shut mininet down
#FIXME: (at least on this loglevel, dont know if others are different)
#for host in network.hosts:
#print host.name, host.IP()
#FIXME: because the upper part wont work dynamically,
#FIXME: the listing (according to the settings just above the print statements above)
#FIXME: will be static. in case you change the ip above, the next print lines
#FIXME: will be false: 10.0.0.x will be wrong!
#FIXME:
print "use 'ssh 10.0.0.x' from other consoles to connect"
print
print "*** Type 'exit' or control-D to shut down network"
CLI( network )
network.stop()
if __name__ == '__main__':
setLogLevel('info')
#setLogLevel('debug')
sshd( setupNetwork() )
# setupNetwork()