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