blob: 13c66ac9c27329848d26935ab4e65875f1504eab [file] [log] [blame]
Srikanth Vavilapallicf584ff2015-03-01 14:12:44 -08001#!/usr/bin/python
2
3"""
4Start up the SDN-IP demo topology
5"""
6
7"""
8AS1 = 64513, (SDN AS)
9AS2 = 64514, reachable by 192.168.10.1, 192.168.20.1
10AS3 = 64516, reachable by 192.168.30.1
11AS4 = 64517, reachable by 192.168.40.1
12AS6 = 64520, reachable by 192.168.60.2, (route server 192.168.60.1)
13"""
14
15from mininet.net import Mininet
16from mininet.node import Controller, RemoteController
17from mininet.log import setLogLevel, info
18from mininet.cli import CLI
19from mininet.topo import Topo
20from mininet.util import quietRun
21from mininet.moduledeps import pathCheck
22
23import os.path
24import time
25import sys
26from subprocess import Popen, STDOUT, PIPE
27
28QUAGGA_DIR = '/usr/lib/quagga'
29#QUAGGA_DIR = '/usr/local/sbin'
30QUAGGA_RUN_DIR = '/usr/local/var/run/quagga'
31
32QUAGGA_CONFIG_FILE_DIR = '/home/tutorial1/ONLabTest/TestON/tests/PeeringRouterTest/mininet'
33
34class SDNIpModifiedTopo( Topo ):
35 "SDN Ip Modified Topology"
36
37 def __init__( self, *args, **kwargs ):
38 global numHost101
39 global numHost200
40 numHost101 = 101
41 numHost200 = 200
42 Topo.__init__( self, *args, **kwargs )
43 sw1 = self.addSwitch('sw1', dpid='0000000000000001')
44 sw2 = self.addSwitch('sw2', dpid='0000000000000002')
45 #sw3 = self.addSwitch('sw3', dpid='00000000000000a3')
46 #sw4 = self.addSwitch('sw4', dpid='00000000000000a4')
47 #sw5 = self.addSwitch('sw5', dpid='00000000000000a5')
48 #sw6 = self.addSwitch('sw6', dpid='00000000000000a6')
49 #add a switch for 3 quagga hosts
50 swTestOn = self.addSwitch('swTestOn', dpid='0000000000000102')
51 #Note this switch isn't part of the SDN topology
52 #We'll use the ovs-controller to turn this into a learning switch
53 as6sw = self.addSwitch('as6sw', dpid='00000000000000a7')
54
55 host1 = self.addHost( 'host1' )
56 root1 = self.addHost( 'root1', inNamespace=False , ip='0')
57 rootTestOn = self.addHost( 'rootTestOn', inNamespace=False, ip='0' )
58
59 #AS2 host
60 host3 = self.addHost( 'host3' )
61 as2host = self.addHost( 'as2host' )
62 #AS3 host
63 host4 = self.addHost( 'host4' )
64 as3host = self.addHost( 'as3host' )
65 #AS6 host
66 host5 = self.addHost( 'host5' )
67 as6host = self.addHost( 'as6host' )
68
69 self.addLink( host1, sw2 )
70 #Links to the multihomed AS
71 self.addLink( host3, sw1 )
72 self.addLink( host3, sw1 )
73 self.addLink( as2host, host3 )
74 #Single links to the remaining two ASes
75 self.addLink( host4, sw1 )
76 self.addLink( as3host, host4 )
77
78 #AS3-AS4 link
79 #self.addLink( host4, host5)
80 #Add new AS6 to its bridge
81 self.addLink( host5, as6sw )
82 self.addLink( as6host, host5 )
83
84 #Backup link from router5 to router4
85 self.addLink( host4, host5)
86
87 #test the host behind the router(behind the router server)
88# for i in range(1, 10):
89 # host = self.addHost('as6host%d' % i)
90 # self.addLink(host, as6router)
91
92 ## Internal Connection To Hosts ##
93 self.addLink( root1, host1 )
94
95 # self.addLink( sw1, sw2 )
96 # self.addLink( sw1, sw3 )
97 # self.addLink( sw2, sw4 )
98 # self.addLink( sw3, sw4 )
99 # self.addLink( sw3, sw5 )
100 # self.addLink( sw4, sw6 )
101 # self.addLink( sw5, sw6 )
102 self.addLink( as6sw, sw1 )
103
104
105 self.addLink(swTestOn, rootTestOn)
106 #self.addLink(swTestOn, host1)
107 self.addLink(swTestOn, host3)
108 self.addLink(swTestOn, host4)
109 self.addLink(swTestOn, host5)
110 self.addLink(swTestOn, as2host)
111
112
113 #self.addLink(rootTestOn, host4)
114
115def startsshd( host ):
116 "Start sshd on host"
117 info( '*** Starting sshd\n' )
118 name, intf, ip = host.name, host.defaultIntf(), host.IP()
119 banner = '/tmp/%s.banner' % name
120 host.cmd( 'echo "Welcome to %s at %s" > %s' % ( name, ip, banner ) )
121 host.cmd( '/usr/sbin/sshd -o "Banner %s"' % banner, '-o "UseDNS no"' )
122 info( '***', host.name, 'is running sshd on', intf, 'at', ip, '\n' )
123
124def startsshds ( hosts ):
125 for h in hosts:
126 startsshd( h )
127
128def stopsshd( ):
129 "Stop *all* sshd processes with a custom banner"
130 info( '*** Shutting down stale sshd/Banner processes ',
131 quietRun( "pkill -9 -f Banner" ), '\n' )
132
133def startquagga( host, num, config_file ):
134 info( '*** Starting Quagga on %s\n' % host )
135 zebra_cmd = 'sudo %s/zebra -d -f %s/zebra.conf -z %s/zserv%s.api -i %s/zebra%s.pid' % (QUAGGA_DIR, QUAGGA_CONFIG_FILE_DIR, QUAGGA_RUN_DIR, num, QUAGGA_RUN_DIR, num)
136 quagga_cmd = 'sudo %s/bgpd -d -f %s -z %s/zserv%s.api -i %s/bgpd%s.pid' % (QUAGGA_DIR, config_file, QUAGGA_RUN_DIR, num, QUAGGA_RUN_DIR, num)
137
138 print zebra_cmd
139 print quagga_cmd
140
141 host.cmd( zebra_cmd )
142 host.cmd( quagga_cmd )
143
144def startquaggahost5( host, num ):
145 info( '*** Starting Quagga on %s\n' % host )
146 zebra_cmd = 'sudo %s/zebra -d -f %s/zebra.conf -z %s/zserv%s.api -i %s/zebra%s.pid' % (QUAGGA_DIR, QUAGGA_CONFIG_FILE_DIR, QUAGGA_RUN_DIR, num, QUAGGA_RUN_DIR, num)
147 quagga_cmd = 'sudo %s/bgpd -d -f ./as4quaggas/quagga%s.conf -z %s/zserv%s.api -i %s/bgpd%s.pid' % (QUAGGA_DIR, num, QUAGGA_RUN_DIR, num, QUAGGA_RUN_DIR, num)
148
149 host.cmd( zebra_cmd )
150 host.cmd( quagga_cmd )
151
152
153def stopquagga( ):
154 quietRun( 'sudo pkill -9 -f bgpd' )
155 quietRun( 'sudo pkill -9 -f zebra' )
156
157def sdn1net():
158 topo = SDNIpModifiedTopo()
159 info( '*** Creating network\n' )
160 net = Mininet( topo=topo, controller=RemoteController )
161 net = Mininet( topo=topo, controller=RemoteController )
162
163 host1, host3, host4, host5 = net.get( 'host1', 'host3', 'host4', 'host5' )
164
165 #host100.setIP('1.168.30.' + str(i), 24, str(host100) + "-eth2")
166
167 #host500.setMAC('00:00:00:00:04:%d' % (i-101), 'host%d-eth0' %(i))
168 #add IP prefixes
169 #for j in range(0,121):
170 #host100.cmd('sudo ip addr add %s.0.40.%s/24 dev host%s-eth0' %(i,j,i))
171
172 ## Adding 2nd, 3rd and 4th interface to host1 connected to sw1 (for another BGP peering)
173 #sw1 = net.get('sw1')
174 host1.setMAC('00:00:00:00:00:01', 'host1-eth0')
175 host1.cmd('ip addr add 192.168.20.101/24 dev host1-eth0')
176 host1.cmd('ip addr add 192.168.30.101/24 dev host1-eth0')
177 #host1.cmd('ip addr add 192.168.40.101/24 dev host1-eth0')
178 host1.cmd('ip addr add 192.168.60.101/24 dev host1-eth0')
179
180 # Net has to be start after adding the above link
181 net.start()
182
183 # Set up as6sw as a learning switch as quickly as possible so it
184 # hopefully doesn't connect to the actual controller
185 # TODO figure out how to change controller before starting switch
186 as6sw = net.get('as6sw')
187 as6sw.cmd('ovs-vsctl set-controller as6sw none')
188 as6sw.cmd('ovs-vsctl set-fail-mode as6sw standalone')
189
190
191 sw1 = net.get('sw1')
192 sw1.cmd('ovs-vsctl set-controller sw1 tcp:127.0.0.1:6633')
193# sw2.cmd('ovs-vsctl set-controller sw2 tcp:127.0.0.1:6633')
194# sw3.cmd('ovs-vsctl set-controller sw3 tcp:127.0.0.1:6633')
195# sw4.cmd('ovs-vsctl set-controller sw4 tcp:127.0.0.1:6633')
196# sw5.cmd('ovs-vsctl set-controller sw5 tcp:127.0.0.1:6633')
197# sw6.cmd('ovs-vsctl set-controller sw6 tcp:127.0.0.1:6633')
198
199
200 swTestOn = net.get('swTestOn')
201 swTestOn.cmd('ovs-vsctl set-controller swTestOn none')
202 swTestOn.cmd('ovs-vsctl set-fail-mode swTestOn standalone')
203
204 host1.defaultIntf().setIP('192.168.10.101/24')
205 # Run BGPd
206 #host1.cmd('%s -d -f %s' % (BGPD, BGPD_CONF))
207 #host1.cmd('/sbin/route add default gw 192.168.10.254 dev %s-eth0' % (host1.name))
208
209 # Configure new host interfaces
210 #host2.defaultIntf().setIP('172.16.10.2/24')
211 #host2.defaultIntf().setMAC('00:00:00:00:01:02')
212 #host2.cmd('/sbin/route add default gw 172.16.10.254 dev %s-eth0' % (host2.name))
213
214 # Set up AS2
215 host3.setIP('192.168.10.1', 24, 'host3-eth0')
216 #host3.cmd('sudo ip addr add 172.16.20.1/24 dev host3-eth0')
217 host3.setIP('192.168.20.1', 24, 'host3-eth1')
218 host3.setMAC('00:00:00:00:02:01', 'host3-eth0')
219 host3.setMAC('00:00:00:00:02:02', 'host3-eth1')
220 #host3.setIP('172.16.20.254', 24, 'host3-eth2')
221 host3.setIP('3.0.0.254', 8, 'host3-eth2')
222 host3.cmd('sysctl net.ipv4.conf.all.forwarding=1')
223
224 host3.setIP('1.168.30.2', 24, 'host3-eth3')
225 host3.cmd('sysctl net.ipv4.conf.all.arp_ignore=1')
226 host3.cmd('sysctl net.ipv4.conf.all.arp_announce=1')
227 as2host = net.get('as2host')
228 #as2host.defaultIntf().setIP('172.16.20.1/24')
229 for i in range(0, 20):
230 as2host.cmd('sudo ip addr add 3.0.%d.1/24 dev as2host-eth0' %i)
231 as2host.setIP('1.168.30.100', 24, 'as2host-eth1')
232
233 as2host.cmd('ip route add default via 3.0.0.254')
234
235 # Set up AS3
236 host4.setIP('192.168.30.1', 24, 'host4-eth0')
237 host4.setMAC('00:00:00:00:03:01', 'host4-eth0')
238 host4.setIP('4.0.0.254', 8, 'host4-eth1')
239 host4.setMAC('00:00:00:00:03:99', 'host4-eth1')
240 host4.cmd('sysctl net.ipv4.conf.all.forwarding=1')
241 as3host = net.get('as3host')
242 for i in range(0, 20):
243 as3host.cmd('sudo ip addr add 4.0.%d.1/24 dev as3host-eth0' %i)
244 as3host.cmd('ip route add default via 4.0.0.254')
245
246 host4.setIP('10.0.0.4', 24, 'host4-eth2')
247 host4.setMAC('00:00:00:00:03:33', 'host4-eth2')
248
249 #root space
250 host4.setIP('1.168.30.3', 24, 'host4-eth3')
251 host4.setMAC('00:00:00:00:03:03', 'host4-eth3')
252
253 # Set up AS4
254 #as4host = net.get('as4host')
255 #as4host.defaultIntf().setIP('172.16.40.1/24')
256 #as4host.cmd('ip route add default via 172.16.40.254')
257
258 # setup interface address for 100 quagga hosts
259 time.sleep(10)
260 #for i in range(numHost101, numHost200 + 1):
261 #host100 = net.get('host' + str(i))
262 #host100.cmd(str(i)+'.0.1.254', 24, 'host'+str(i)+'-eth1')
263 #as4host100 = net.get('as4host%s' %(i))
264 #as4host100.defaultIntf().setIP(str(i) + '.0.0.1/24')
265 #as4host100.cmd('ip route add default via ' + str(i) + '.0.0.254')
266 #for j in range(0, 100):
267 #as4host100.cmd('sudo ip addr add %d.0.%d.1/24 dev %s-eth0' %(i, j, as4host100))
268
269 # Set up AS6 - This has a router and a route server
270 #as6rs, host5 = net.get('as6rs', 'host5')
271 host5 = net.get('host5')
272 #as6rs.setIP('192.168.60.1', 24, 'as6rs-eth0')
273 #as6rs.setMAC('00:00:00:00:06:01', 'as6rs-eth0')
274 host5.setIP('192.168.60.2', 24, 'host5-eth0')
275 host5.setMAC('00:00:00:00:06:02', 'host5-eth0')
276 #as6router.setIP('172.16.60.254', 24, 'as6router-eth1')
277 host5.setIP('5.0.0.254', 8, 'host5-eth1')
278 host5.cmd('sysctl net.ipv4.conf.all.forwarding=1')
279 host5.setIP('10.0.0.5', 24, 'host5-eth2')
280 host5.setMAC('00:00:00:00:06:66', 'host5-eth2')
281 host5.setIP('1.168.30.5', 24, 'host5-eth3')
282 host5.setMAC('00:00:00:00:06:05', 'host5-eth3')
283
284 as6host = net.get('as6host')
285 #as6host.defaultIntf().setIP('5.0.0.1/24')
286 for i in range(0, 10):
287 as6host.cmd('sudo ip addr add 5.0.%d.1/24 dev as6host-eth0' %i)
288 as6host.cmd('ip route add default via 5.0.0.254')
289
290 # test the host in the as6
291 #for i in range(1, 10):
292 # baseip = (i-1)*4
293 # host = net.get('as6host%d' % i)
294 # host.defaultIntf().setIP('172.16.70.%d/24' % (baseip+1))
295 # host.cmd('ip route add default via 172.16.70.%d' % (baseip+2))
296 # as6router.setIP('172.16.70.%d' % (baseip+2), 30, 'as6router-eth%d' % (i+1))
297
298 # Start Quagga on border routers
299 startquagga(host3, 1, QUAGGA_CONFIG_FILE_DIR + '/quagga1.conf')
300 startquagga(host4, 2, QUAGGA_CONFIG_FILE_DIR + '/quagga2.conf')
301 #for i in range(numHost101, numHost200 + 1):
302 #host100=net.get('host%d' % (i))
303 #startquaggahost5(host100, i)
304
305 #startquagga(as6rs, 4, 'quagga-as6-rs.conf')
306 startquagga(host5, 5, QUAGGA_CONFIG_FILE_DIR + '/quagga-as6.conf')
307
308 #root1, root2, rootTestOn = net.get( 'root1', 'root2', 'rootTestOn' )
309 root1, rootTestOn = net.get( 'root1', 'rootTestOn' )
310 host1.intf('host1-eth1').setIP('1.1.1.1/24')
311 root1.intf('root1-eth0').setIP('1.1.1.2/24')
312 #host2.intf('host2-eth1').setIP('1.1.2.1/24')
313 #root2.intf('root2-eth0').setIP('1.1.2.2/24')
314
315 #rootTestOn.cmd('ip addr add 1.168.30.102/24 dev rootTestOn-eth0')
316 rootTestOn.cmd('ip addr add 1.168.30.99/24 dev rootTestOn-eth0')
317
318 stopsshd()
319
320 startquagga(host1, 100, QUAGGA_CONFIG_FILE_DIR + '/quagga-sdn-modified.conf')
321 hosts = [ host1, host3, host4, host5, as2host ];
322 #sshdHosts = sshdHosts + hosts
323 startsshds( hosts )
324 #
325 onos1 = '127.0.0.1'
326 forwarding1 = '%s:2000:%s:2000' % ('1.1.1.2', onos1)
327 root1.cmd( 'ssh -nNT -o "PasswordAuthentication no" -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % (forwarding1, onos1) )
328
329 # Forward 2605 to root namespace for easier access to SDN domain BGPd
330 # If root can ssh to itself without a password this should work
331 root1.cmd('ssh -N -o "PasswordAuthentication no" -o "StrictHostKeyChecking no" -L 2605:1.1.1.1:2605 1.1.1.1 &')
332 #time.sleep(3000000000)
333 CLI( net )
334
335 # Close the ssh port forwarding
336 #quietRun('sudo pkill -f 1.1.1.1')
337
338 stopsshd()
339 stopquagga()
340 net.stop()
341
342if __name__ == '__main__':
343 setLogLevel( 'debug' )
344 if len(sys.argv) > 1:
345 QUAGGA_CONFIG_FILE_DIR = sys.argv[1]
346 sdn1net()