blob: b034d342e2860accab2be0f5d67a0d68a03f9170 [file] [log] [blame]
pingping-linffca7e22015-11-13 15:43:08 -08001#!/usr/bin/python
2
3"""
4Set up the SDN-IP topology as same as it on Internet2
5"""
6
7"""
8AS 64513, (SDN AS)
9AS 64514, reachable by 10.0.4.1
10AS 64515, reachable by 10.0.5.1
11AS 64516, reachable by 10.0.6.1
12"""
13
14from mininet.net import Mininet
15from mininet.node import Controller, RemoteController
16from mininet.log import setLogLevel, info
17from mininet.cli import CLI
18from mininet.topo import Topo
19from mininet.util import quietRun
20from mininet.moduledeps import pathCheck
21
22import os.path
23import time
24from subprocess import Popen, STDOUT, PIPE
25
26QUAGGA_DIR = '/usr/lib/quagga'
27QUAGGA_RUN_DIR = '/usr/local/var/run/quagga'
pingping-lin2b2a8df2015-11-16 15:41:21 -080028QUAGGA_CONFIG_DIR = '~/OnosSystemTest/TestON/tests/USECASE_SdnipFunction_fsfw/Dependency/'
pingping-linffca7e22015-11-13 15:43:08 -080029# onos1IP = '10.254.1.201'
30numSw = 39
31
32
33class SDNTopo( Topo ):
34 "SDN Topology"
35
36 def __init__( self, *args, **kwargs ):
37
38 Topo.__init__( self, *args, **kwargs )
39
40 # BGP peer hosts
41 peer64514 = self.addHost( 'peer64514' )
42 peer64515 = self.addHost( 'peer64515' )
43 peer64516 = self.addHost( 'peer64516' )
44
45 '''
46 sw1 = self.addSwitch( 'SEAT', dpid = '00000000000000a1' )
47 sw2 = self.addSwitch( 'PORT', dpid = '00000000000000a2' )
48 sw3 = self.addSwitch( 'SUNN', dpid = '00000000000000a3' )
49 sw4 = self.addSwitch( 'RENO', dpid = '00000000000000a4' )
50 sw5 = self.addSwitch( 'LOSA', dpid = '00000000000000a5' )
51 sw6 = self.addSwitch( 'MISS', dpid = '00000000000000a6' )
52 sw7 = self.addSwitch( 'LASV', dpid = '00000000000000a7' )
53 sw8 = self.addSwitch( 'SALT', dpid = '00000000000000a8' )
54 sw9 = self.addSwitch( 'PHOE', dpid = '00000000000000a9' )
55 sw10 = self.addSwitch( 'TUCS', dpid = '0000000000000a10' )
56 sw11 = self.addSwitch( 'DENV', dpid = '0000000000000a11' )
57 sw12 = self.addSwitch( 'ELPA', dpid = '0000000000000a12' )
58 sw13 = self.addSwitch( 'MINN', dpid = '0000000000000a13' )
59 sw14 = self.addSwitch( 'KANS', dpid = '0000000000000a14' )
60 sw15 = self.addSwitch( 'TULS', dpid = '0000000000000a15' )
61 sw16 = self.addSwitch( 'DALL', dpid = '0000000000000a16' )
62 sw17 = self.addSwitch( 'HOUH', dpid = '0000000000000a17' )
63 sw18 = self.addSwitch( 'COLU', dpid = '0000000000000a18' )
64 sw19 = self.addSwitch( 'JCSN', dpid = '0000000000000a19' )
65 sw20 = self.addSwitch( 'BATO', dpid = '0000000000000a20' )
66 sw21 = self.addSwitch( 'EQCH', dpid = '0000000000000a21' )
67 sw22 = self.addSwitch( 'STAR', dpid = '0000000000000a22' )
68 sw23 = self.addSwitch( 'CHIC', dpid = '0000000000000a23' )
69 sw24 = self.addSwitch( 'INDI', dpid = '0000000000000a24' )
70 sw25 = self.addSwitch( 'CINC', dpid = '0000000000000a25' )
71 sw26 = self.addSwitch( 'LOUI', dpid = '0000000000000a26' )
72 sw27 = self.addSwitch( 'ATLA', dpid = '0000000000000a27' )
73 sw28 = self.addSwitch( 'JACK', dpid = '0000000000000a28' )
74 sw29 = self.addSwitch( 'CLEV', dpid = '0000000000000a29' )
75 sw30 = self.addSwitch( 'PITT', dpid = '0000000000000a30' )
76 sw31 = self.addSwitch( 'ASHB', dpid = '0000000000000a31' )
77 sw32 = self.addSwitch( 'WASH', dpid = '0000000000000a32' )
78 sw33 = self.addSwitch( 'RALE', dpid = '0000000000000a33' )
79 sw34 = self.addSwitch( 'CHAR', dpid = '0000000000000a34' )
80 sw35 = self.addSwitch( 'ALBA', dpid = '0000000000000a35' )
81 sw36 = self.addSwitch( 'BOST', dpid = '0000000000000a36' )
82 sw37 = self.addSwitch( 'HART', dpid = '0000000000000a37' )
83 sw38 = self.addSwitch( 'NEWY', dpid = '0000000000000a38' )
84 sw39 = self.addSwitch( 'PHIL', dpid = '0000000000000a39' )
85 '''
86 sw1 = self.addSwitch( 'sw1', dpid = '00000000000000a1' )
87 sw2 = self.addSwitch( 'sw2', dpid = '00000000000000a2' )
88 sw3 = self.addSwitch( 'sw3', dpid = '00000000000000a3' )
89 sw4 = self.addSwitch( 'sw4', dpid = '00000000000000a4' )
90 sw5 = self.addSwitch( 'sw5', dpid = '00000000000000a5' )
91 sw6 = self.addSwitch( 'sw6', dpid = '00000000000000a6' )
92 sw7 = self.addSwitch( 'sw7', dpid = '00000000000000a7' )
93 sw8 = self.addSwitch( 'sw8', dpid = '00000000000000a8' )
94 sw9 = self.addSwitch( 'sw9', dpid = '00000000000000a9' )
95 sw10 = self.addSwitch( 'sw10', dpid = '0000000000000a10' )
96 sw11 = self.addSwitch( 'sw11', dpid = '0000000000000a11' )
97 sw12 = self.addSwitch( 'sw12', dpid = '0000000000000a12' )
98 sw13 = self.addSwitch( 'sw13', dpid = '0000000000000a13' )
99 sw14 = self.addSwitch( 'sw14', dpid = '0000000000000a14' )
100 sw15 = self.addSwitch( 'sw15', dpid = '0000000000000a15' )
101 sw16 = self.addSwitch( 'sw16', dpid = '0000000000000a16' )
102 sw17 = self.addSwitch( 'sw17', dpid = '0000000000000a17' )
103 sw18 = self.addSwitch( 'sw18', dpid = '0000000000000a18' )
104 sw19 = self.addSwitch( 'sw19', dpid = '0000000000000a19' )
105 sw20 = self.addSwitch( 'sw20', dpid = '0000000000000a20' )
106 sw21 = self.addSwitch( 'sw21', dpid = '0000000000000a21' )
107 sw22 = self.addSwitch( 'sw22', dpid = '0000000000000a22' )
108 sw23 = self.addSwitch( 'sw23', dpid = '0000000000000a23' )
109 sw24 = self.addSwitch( 'sw24', dpid = '0000000000000a24' )
110 sw25 = self.addSwitch( 'sw25', dpid = '0000000000000a25' )
111 sw26 = self.addSwitch( 'sw26', dpid = '0000000000000a26' )
112 sw27 = self.addSwitch( 'sw27', dpid = '0000000000000a27' )
113 sw28 = self.addSwitch( 'sw28', dpid = '0000000000000a28' )
114 sw29 = self.addSwitch( 'sw29', dpid = '0000000000000a29' )
115 sw30 = self.addSwitch( 'sw30', dpid = '0000000000000a30' )
116 sw31 = self.addSwitch( 'sw31', dpid = '0000000000000a31' )
117 sw32 = self.addSwitch( 'sw32', dpid = '0000000000000a32' )
118 sw33 = self.addSwitch( 'sw33', dpid = '0000000000000a33' )
119 sw34 = self.addSwitch( 'sw34', dpid = '0000000000000a34' )
120 sw35 = self.addSwitch( 'sw35', dpid = '0000000000000a35' )
121 sw36 = self.addSwitch( 'sw36', dpid = '0000000000000a36' )
122 sw37 = self.addSwitch( 'sw37', dpid = '0000000000000a37' )
123 sw38 = self.addSwitch( 'sw38', dpid = '0000000000000a38' )
124 sw39 = self.addSwitch( 'sw39', dpid = '0000000000000a39' )
125
126
127 # Add a layer2 switch for control plane connectivity
128 # This switch isn't part of the SDN topology
129 # We'll use the ovs-controller to turn this into a learning switch
130 swCtl100 = self.addSwitch( 'swCtl100', dpid = '0000000000000100' )
131
132
133 # BGP speaker hosts
134 speaker1 = self.addHost( 'speaker1' )
135 speaker2 = self.addHost( 'speaker2' )
136
137 root = self.addHost( 'root', inNamespace = False , ip = '0' )
138
139 # hosts behind each AS
140 host64514 = self.addHost( 'host64514' )
141 host64515 = self.addHost( 'host64515' )
142 host64516 = self.addHost( 'host64516' )
143
144 self.addLink( 'speaker1', sw24 )
145 self.addLink( 'speaker2', sw24 )
146
147 # connect all switches
148 self.addLink( sw1, sw2 )
149 self.addLink( sw1, sw6 )
150 self.addLink( sw1, sw8 )
151 self.addLink( sw2, sw3 )
152 self.addLink( sw3, sw4 )
153 self.addLink( sw3, sw5 )
154 self.addLink( sw4, sw8 )
155 self.addLink( sw5, sw7 )
156 self.addLink( sw5, sw9 )
157 self.addLink( sw6, sw13 )
158 self.addLink( sw7, sw8 )
159 self.addLink( sw8, sw11 )
160 self.addLink( sw9, sw10 )
161 self.addLink( sw10, sw12 )
162 self.addLink( sw11, sw12 )
163 self.addLink( sw11, sw14 )
164 self.addLink( sw12, sw17 )
165 self.addLink( sw13, sw14 )
166 self.addLink( sw13, sw21 )
167 self.addLink( sw14, sw15 )
168 self.addLink( sw14, sw18 )
169 self.addLink( sw14, sw23 )
170 self.addLink( sw15, sw16 )
171 self.addLink( sw16, sw17 )
172 self.addLink( sw17, sw19 )
173 self.addLink( sw17, sw20 )
174 self.addLink( sw18, sw23 )
175 self.addLink( sw19, sw27 )
176 self.addLink( sw20, sw28 )
177 self.addLink( sw21, sw22 )
178 self.addLink( sw21, sw29 )
179 self.addLink( sw22, sw23 )
180 self.addLink( sw23, sw24 )
181 self.addLink( sw23, sw31 )
182 self.addLink( sw24, sw25 )
183 self.addLink( sw25, sw26 )
184 self.addLink( sw26, sw27 )
185 self.addLink( sw27, sw28 )
186 self.addLink( sw27, sw34 )
187 self.addLink( sw29, sw30 )
188 self.addLink( sw29, sw35 )
189 self.addLink( sw30, sw31 )
190 self.addLink( sw31, sw32 )
191 self.addLink( sw32, sw33 )
192 self.addLink( sw32, sw39 )
193 self.addLink( sw33, sw34 )
194 self.addLink( sw35, sw36 )
195 self.addLink( sw36, sw37 )
196 self.addLink( sw37, sw38 )
197 self.addLink( sw38, sw39 )
198
199 # connection between switches and peers
200 self.addLink( peer64514, sw32 )
201 self.addLink( peer64515, sw8 )
202 self.addLink( peer64516, sw28 )
203
204 # connection between BGP peer and hosts behind the BGP peer
205 self.addLink( peer64514, host64514 )
206 self.addLink( peer64515, host64515 )
207 self.addLink( peer64516, host64516 )
208
209 # Internal Connection To Hosts
210 self.addLink( swCtl100, peer64514 )
211 self.addLink( swCtl100, peer64515 )
212 self.addLink( swCtl100, peer64516 )
213 self.addLink( swCtl100, speaker1 )
214 self.addLink( swCtl100, speaker2 )
215
216
217
218 # add host64514 to control plane for ping test
219 self.addLink( swCtl100, host64514 )
220 self.addLink( swCtl100, root )
221
222
223def startsshd( host ):
224 "Start sshd on host"
225 info( '*** Starting sshd\n' )
226 name, intf, ip = host.name, host.defaultIntf(), host.IP()
227 banner = '/tmp/%s.banner' % name
228 host.cmd( 'echo "Welcome to %s at %s" > %s' % ( name, ip, banner ) )
229 host.cmd( '/usr/sbin/sshd -o "Banner %s"' % banner, '-o "UseDNS no"' )
230 info( '***', host.name, 'is running sshd on', intf, 'at', ip, '\n' )
231
232def startsshds ( hosts ):
233 for h in hosts:
234 startsshd( h )
235
236def stopsshd():
237 "Stop *all* sshd processes with a custom banner"
238 info( '*** Shutting down stale sshd/Banner processes ',
239 quietRun( "pkill -9 -f Banner" ), '\n' )
240
241def startquagga( host, num, config_file ):
242 info( '*** Starting Quagga on %s\n' % host )
243 host.cmd( "cd %s" % QUAGGA_CONFIG_DIR )
244 zebra_cmd = \
245 '%s/zebra -d -f ./zebra.conf -z %s/zserv%s.api -i %s/zebra%s.pid'\
246 % ( QUAGGA_DIR, QUAGGA_RUN_DIR, num, QUAGGA_RUN_DIR, num )
247 quagga_cmd = '%s/bgpd -d -f %s -z %s/zserv%s.api -i %s/bgpd%s.pid' \
248 % ( QUAGGA_DIR, config_file, QUAGGA_RUN_DIR, num, QUAGGA_RUN_DIR, num )
249
250 print zebra_cmd
251 print quagga_cmd
252
253 host.cmd( zebra_cmd )
254 host.cmd( quagga_cmd )
255
256def startquaggahost5( host, num ):
257 info( '*** Starting Quagga on %s\n' % host )
258 zebra_cmd = \
259 '%s/zebra -d -f ./zebra.conf -z %s/zserv%s.api -i %s/zebra%s.pid' \
260 % ( QUAGGA_DIR, QUAGGA_RUN_DIR, num, QUAGGA_RUN_DIR, num )
261 quagga_cmd = \
262 '%s/bgpd -d -f ./as4quaggas/quagga%s.conf -z %s/zserv%s.api -i %s/bgpd%s.pid'\
263 % ( QUAGGA_DIR, num, QUAGGA_RUN_DIR, num, QUAGGA_RUN_DIR, num )
264
265 host.cmd( zebra_cmd )
266 host.cmd( quagga_cmd )
267
268
269def stopquagga():
270 quietRun( 'sudo pkill -9 -f bgpd' )
271 quietRun( 'sudo pkill -9 -f zebra' )
272
273def sdn1net():
274 topo = SDNTopo()
275 info( '*** Creating network\n' )
276 # time.sleep( 30 )
277 net = Mininet( topo = topo, controller = RemoteController )
278
279
280 speaker1, speaker2, peer64514, peer64515, peer64516 = \
281 net.get( 'speaker1', 'speaker2' ,
282 'peer64514', 'peer64515', 'peer64516' )
283
284 # Adding addresses to host64513_1 interface connected to sw24
285 # for BGP peering
286 speaker1.setMAC( '00:00:00:00:00:01', 'speaker1-eth0' )
287 speaker1.cmd( 'ip addr add 10.0.4.101/24 dev speaker1-eth0' )
288 speaker1.cmd( 'ip addr add 10.0.5.101/24 dev speaker1-eth0' )
289 speaker1.cmd( 'ip addr add 10.0.6.101/24 dev speaker1-eth0' )
290
291 speaker1.defaultIntf().setIP( '10.1.4.101/24' )
292 speaker1.defaultIntf().setMAC( '00:00:00:00:00:01' )
293
294 # Net has to be start after adding the above link
295 net.start()
296
297 # setup configuration on the interface connected to switch
298 peer64514.cmd( "ifconfig peer64514-eth0 10.0.4.1 up" )
299 peer64514.setMAC( '00:00:00:00:00:04', 'peer64514-eth0' )
300 peer64515.cmd( "ifconfig peer64515-eth0 10.0.5.1 up" )
301 peer64515.setMAC( '00:00:00:00:00:05', 'peer64515-eth0' )
302 peer64516.cmd( "ifconfig peer64516-eth0 10.0.6.1 up" )
303 peer64516.setMAC( '00:00:00:00:00:06', 'peer64516-eth0' )
304
305 # setup configuration on the interface connected to hosts
306 peer64514.setIP( "4.0.0.254", 8, "peer64514-eth1" )
307 peer64514.setMAC( '00:00:00:00:00:44', 'peer64514-eth1' )
308 peer64515.setIP( "5.0.0.254", 8, "peer64515-eth1" )
309 peer64515.setMAC( '00:00:00:00:00:55', 'peer64515-eth1' )
310 peer64516.setIP( "6.0.0.254", 8, "peer64516-eth1" )
311 peer64516.setMAC( '00:00:00:00:00:66', 'peer64516-eth1' )
312
313 # enable forwarding on BGP peer hosts
314 peer64514.cmd( 'sysctl net.ipv4.conf.all.forwarding=1' )
315 peer64515.cmd( 'sysctl net.ipv4.conf.all.forwarding=1' )
316 peer64516.cmd( 'sysctl net.ipv4.conf.all.forwarding=1' )
317
318 # config interface for control plane connectivity
319 peer64514.setIP( "192.168.0.4", 24, "peer64514-eth2" )
320 peer64515.setIP( "192.168.0.5", 24, "peer64515-eth2" )
321 peer64516.setIP( "192.168.0.6", 24, "peer64516-eth2" )
322
323 # Setup hosts in each non-SDN AS
324 host64514, host64515, host64516 = \
325 net.get( 'host64514', 'host64515', 'host64516' )
326 host64514.cmd( 'ifconfig host64514-eth0 4.0.0.1 up' )
327 host64514.cmd( 'ip route add default via 4.0.0.254' )
328 host64514.setIP( '192.168.0.44', 24, 'host64514-eth1' ) # for control plane
329 host64515.cmd( 'ifconfig host64515-eth0 5.0.0.1 up' )
330 host64515.cmd( 'ip route add default via 5.0.0.254' )
331 host64516.cmd( 'ifconfig host64516-eth0 6.0.0.1 up' )
332 host64516.cmd( 'ip route add default via 6.0.0.254' )
333
334
335 # set up swCtl100 as a learning
336 swCtl100 = net.get( 'swCtl100' )
337 swCtl100.cmd( 'ovs-vsctl set-controller swCtl100 none' )
338 swCtl100.cmd( 'ovs-vsctl set-fail-mode swCtl100 standalone' )
339
340 # connect all switches to controller
341 '''
342 for i in range ( 1, numSw + 1 ):
343 swX = net.get( 'sw%s' % ( i ) )
344 swX.cmd( 'ovs-vsctl set-controller sw%s tcp:%s:6653' % ( i, onos1IP ) )
345 '''
346 # Start Quagga on border routers
347 '''
348 for i in range ( 64514, 64516 + 1 ):
349 startquagga( 'peer%s' % ( i ), i, 'quagga%s.conf' % ( i ) )
350 '''
351 startquagga( peer64514, 64514, 'quagga64514.conf' )
352 startquagga( peer64515, 64515, 'quagga64515.conf' )
353 startquagga( peer64516, 64516, 'quagga64516.conf' )
354
355 # start Quagga in SDN network
356 startquagga( speaker1, 64513, 'quagga-sdn.conf' )
357
358
359 root = net.get( 'root' )
360 root.intf( 'root-eth0' ).setIP( '1.1.1.2/24' )
361 root.cmd( 'ip addr add 192.168.0.100/24 dev root-eth0' )
362
363 speaker1.intf( 'speaker1-eth1' ).setIP( '1.1.1.1/24' )
364
365
366 stopsshd()
367
368 hosts = [ peer64514, peer64515, peer64516, host64514];
369 startsshds( hosts )
370 #
371 '''
372 forwarding1 = '%s:2000:%s:2000' % ( '1.1.1.2', onos1IP )
373 root.cmd( 'ssh -nNT -o "PasswordAuthentication no" \
374 -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding1, onos1IP ) )
375
376 '''
377 # time.sleep( 3000000000 )
378 CLI( net )
379
380
381 stopsshd()
382 stopquagga()
383 net.stop()
384
385if __name__ == '__main__':
386 setLogLevel( 'debug' )
387 sdn1net()