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