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