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