pingping-lin | f565dd8 | 2016-04-28 18:10:36 -0700 | [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 | AS 64515, reachable by 10.0.5.1 |
| 11 | AS 64516, reachable by 10.0.6.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/ReactiveRouting/Dependency/' |
| 29 | onos1IP = '10.128.4.52' |
| 30 | numSw = 39 |
| 31 | |
| 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 | host1 = self.addHost( 'host1' ) |
| 104 | host2 = self.addHost( 'host2' ) |
| 105 | host6 = self.addHost( 'host6' ) |
| 106 | host13 = self.addHost( 'host13' ) |
| 107 | |
| 108 | self.addLink( 'speaker1', sw24 ) |
| 109 | self.addLink( 'speaker2', sw24 ) |
| 110 | |
| 111 | # connect all switches |
| 112 | self.addLink( sw1, sw2 ) |
| 113 | self.addLink( sw1, sw6 ) |
| 114 | self.addLink( sw1, sw8 ) |
| 115 | self.addLink( sw2, sw3 ) |
| 116 | self.addLink( sw3, sw4 ) |
| 117 | self.addLink( sw3, sw5 ) |
| 118 | self.addLink( sw4, sw8 ) |
| 119 | self.addLink( sw5, sw7 ) |
| 120 | self.addLink( sw5, sw9 ) |
| 121 | self.addLink( sw6, sw13 ) |
| 122 | self.addLink( sw7, sw8 ) |
| 123 | self.addLink( sw8, sw11 ) |
| 124 | self.addLink( sw9, sw10 ) |
| 125 | self.addLink( sw10, sw12 ) |
| 126 | self.addLink( sw11, sw12 ) |
| 127 | self.addLink( sw11, sw14 ) |
| 128 | self.addLink( sw12, sw17 ) |
| 129 | self.addLink( sw13, sw14 ) |
| 130 | self.addLink( sw13, sw21 ) |
| 131 | self.addLink( sw14, sw15 ) |
| 132 | self.addLink( sw14, sw18 ) |
| 133 | self.addLink( sw14, sw23 ) |
| 134 | self.addLink( sw15, sw16 ) |
| 135 | self.addLink( sw16, sw17 ) |
| 136 | self.addLink( sw17, sw19 ) |
| 137 | self.addLink( sw17, sw20 ) |
| 138 | self.addLink( sw18, sw23 ) |
| 139 | self.addLink( sw19, sw27 ) |
| 140 | self.addLink( sw20, sw28 ) |
| 141 | self.addLink( sw21, sw22 ) |
| 142 | self.addLink( sw21, sw29 ) |
| 143 | self.addLink( sw22, sw23 ) |
| 144 | self.addLink( sw23, sw24 ) |
| 145 | self.addLink( sw23, sw31 ) |
| 146 | self.addLink( sw24, sw25 ) |
| 147 | self.addLink( sw25, sw26 ) |
| 148 | self.addLink( sw26, sw27 ) |
| 149 | self.addLink( sw27, sw28 ) |
| 150 | self.addLink( sw27, sw34 ) |
| 151 | self.addLink( sw29, sw30 ) |
| 152 | self.addLink( sw29, sw35 ) |
| 153 | self.addLink( sw30, sw31 ) |
| 154 | self.addLink( sw31, sw32 ) |
| 155 | self.addLink( sw32, sw33 ) |
| 156 | self.addLink( sw32, sw39 ) |
| 157 | self.addLink( sw33, sw34 ) |
| 158 | self.addLink( sw35, sw36 ) |
| 159 | self.addLink( sw36, sw37 ) |
| 160 | self.addLink( sw37, sw38 ) |
| 161 | self.addLink( sw38, sw39 ) |
| 162 | |
| 163 | # connection between switches and peers |
| 164 | self.addLink( peer64514, sw32 ) |
| 165 | self.addLink( peer64515, sw8 ) |
| 166 | self.addLink( peer64516, sw28 ) |
| 167 | |
| 168 | # connection between BGP peer and hosts behind the BGP peer |
| 169 | self.addLink( peer64514, host64514 ) |
| 170 | self.addLink( peer64515, host64515 ) |
| 171 | self.addLink( peer64516, host64516 ) |
| 172 | |
| 173 | self.addLink( sw1, host1 ) |
| 174 | self.addLink( sw2, host2 ) |
| 175 | self.addLink( sw6, host6 ) |
| 176 | self.addLink( sw13, host13 ) |
| 177 | |
| 178 | # Internal Connection To Hosts |
| 179 | self.addLink( swCtl100, peer64514 ) |
| 180 | self.addLink( swCtl100, peer64515 ) |
| 181 | self.addLink( swCtl100, peer64516 ) |
| 182 | self.addLink( swCtl100, speaker1 ) |
| 183 | self.addLink( swCtl100, speaker2 ) |
| 184 | |
| 185 | |
| 186 | |
| 187 | # add host64514 to control plane for ping test |
| 188 | self.addLink( swCtl100, host64514 ) |
| 189 | self.addLink( swCtl100, root ) |
| 190 | |
| 191 | |
| 192 | def startsshd( host ): |
| 193 | "Start sshd on host" |
| 194 | info( '*** Starting sshd\n' ) |
| 195 | name, intf, ip = host.name, host.defaultIntf(), host.IP() |
| 196 | banner = '/tmp/%s.banner' % name |
| 197 | host.cmd( 'echo "Welcome to %s at %s" > %s' % ( name, ip, banner ) ) |
| 198 | host.cmd( '/usr/sbin/sshd -o "Banner %s"' % banner, '-o "UseDNS no"' ) |
| 199 | info( '***', host.name, 'is running sshd on', intf, 'at', ip, '\n' ) |
| 200 | |
| 201 | def startsshds ( hosts ): |
| 202 | for h in hosts: |
| 203 | startsshd( h ) |
| 204 | |
| 205 | def stopsshd(): |
| 206 | "Stop *all* sshd processes with a custom banner" |
| 207 | info( '*** Shutting down stale sshd/Banner processes ', |
| 208 | quietRun( "pkill -9 -f Banner" ), '\n' ) |
| 209 | |
| 210 | def startquagga( host, num, config_file ): |
| 211 | info( '*** Starting Quagga on %s\n' % host ) |
| 212 | host.cmd( "cd %s" % QUAGGA_CONFIG_DIR ) |
| 213 | zebra_cmd = \ |
| 214 | '%s/zebra -d -f ./zebra.conf -z %s/zserv%s.api -i %s/zebra%s.pid'\ |
| 215 | % ( QUAGGA_DIR, QUAGGA_RUN_DIR, num, QUAGGA_RUN_DIR, num ) |
| 216 | quagga_cmd = '%s/bgpd -d -f %s -z %s/zserv%s.api -i %s/bgpd%s.pid' \ |
| 217 | % ( QUAGGA_DIR, config_file, QUAGGA_RUN_DIR, num, QUAGGA_RUN_DIR, num ) |
| 218 | |
| 219 | print zebra_cmd |
| 220 | print quagga_cmd |
| 221 | |
| 222 | host.cmd( zebra_cmd ) |
| 223 | host.cmd( quagga_cmd ) |
| 224 | |
| 225 | def startquaggahost5( host, num ): |
| 226 | info( '*** Starting Quagga on %s\n' % host ) |
| 227 | zebra_cmd = \ |
| 228 | '%s/zebra -d -f ./zebra.conf -z %s/zserv%s.api -i %s/zebra%s.pid' \ |
| 229 | % ( QUAGGA_DIR, QUAGGA_RUN_DIR, num, QUAGGA_RUN_DIR, num ) |
| 230 | quagga_cmd = \ |
| 231 | '%s/bgpd -d -f ./as4quaggas/quagga%s.conf -z %s/zserv%s.api -i %s/bgpd%s.pid'\ |
| 232 | % ( QUAGGA_DIR, num, QUAGGA_RUN_DIR, num, QUAGGA_RUN_DIR, num ) |
| 233 | |
| 234 | host.cmd( zebra_cmd ) |
| 235 | host.cmd( quagga_cmd ) |
| 236 | |
| 237 | |
| 238 | def stopquagga(): |
| 239 | quietRun( 'sudo pkill -9 -f bgpd' ) |
| 240 | quietRun( 'sudo pkill -9 -f zebra' ) |
| 241 | |
| 242 | def sdn1net(): |
| 243 | topo = SDNTopo() |
| 244 | info( '*** Creating network\n' ) |
| 245 | # time.sleep( 30 ) |
| 246 | net = Mininet( topo = topo, controller = RemoteController ) |
| 247 | |
| 248 | |
| 249 | speaker1, speaker2, peer64514, peer64515, peer64516 = \ |
| 250 | net.get( 'speaker1', 'speaker2' , |
| 251 | 'peer64514', 'peer64515', 'peer64516' ) |
| 252 | |
| 253 | # Adding addresses to host64513_1 interface connected to sw24 |
| 254 | # for BGP peering |
| 255 | speaker1.setMAC( '00:00:00:00:00:01', 'speaker1-eth0' ) |
| 256 | speaker1.cmd( 'ip addr add 10.0.4.101/24 dev speaker1-eth0' ) |
| 257 | speaker1.cmd( 'ip addr add 10.0.5.101/24 dev speaker1-eth0' ) |
| 258 | speaker1.cmd( 'ip addr add 10.0.6.101/24 dev speaker1-eth0' ) |
| 259 | |
| 260 | speaker1.defaultIntf().setIP( '10.1.4.101/24' ) |
| 261 | speaker1.defaultIntf().setMAC( '00:00:00:00:00:01' ) |
| 262 | |
| 263 | # Net has to be start after adding the above link |
| 264 | net.start() |
| 265 | |
| 266 | # setup configuration on the interface connected to switch |
| 267 | peer64514.cmd( "ifconfig peer64514-eth0 10.0.4.1 up" ) |
| 268 | peer64514.setMAC( '00:00:00:00:00:04', 'peer64514-eth0' ) |
| 269 | peer64515.cmd( "ifconfig peer64515-eth0 10.0.5.1 up" ) |
| 270 | peer64515.setMAC( '00:00:00:00:00:05', 'peer64515-eth0' ) |
| 271 | peer64516.cmd( "ifconfig peer64516-eth0 10.0.6.1 up" ) |
| 272 | peer64516.setMAC( '00:00:00:00:00:06', 'peer64516-eth0' ) |
| 273 | |
| 274 | # setup configuration on the interface connected to hosts |
| 275 | peer64514.setIP( "4.0.0.254", 8, "peer64514-eth1" ) |
| 276 | peer64514.setMAC( '00:00:00:00:00:44', 'peer64514-eth1' ) |
| 277 | peer64515.setIP( "5.0.0.254", 8, "peer64515-eth1" ) |
| 278 | peer64515.setMAC( '00:00:00:00:00:55', 'peer64515-eth1' ) |
| 279 | peer64516.setIP( "6.0.0.254", 8, "peer64516-eth1" ) |
| 280 | peer64516.setMAC( '00:00:00:00:00:66', 'peer64516-eth1' ) |
| 281 | |
| 282 | # enable forwarding on BGP peer hosts |
| 283 | peer64514.cmd( 'sysctl net.ipv4.conf.all.forwarding=1' ) |
| 284 | peer64515.cmd( 'sysctl net.ipv4.conf.all.forwarding=1' ) |
| 285 | peer64516.cmd( 'sysctl net.ipv4.conf.all.forwarding=1' ) |
| 286 | |
| 287 | # config interface for control plane connectivity |
| 288 | peer64514.setIP( "192.168.0.4", 24, "peer64514-eth2" ) |
| 289 | peer64515.setIP( "192.168.0.5", 24, "peer64515-eth2" ) |
| 290 | peer64516.setIP( "192.168.0.6", 24, "peer64516-eth2" ) |
| 291 | |
| 292 | # Setup hosts in each non-SDN AS |
| 293 | host64514, host64515, host64516 = \ |
| 294 | net.get( 'host64514', 'host64515', 'host64516' ) |
| 295 | host64514.cmd( 'ifconfig host64514-eth0 4.0.0.1 up' ) |
| 296 | host64514.cmd( 'ip route add default via 4.0.0.254' ) |
| 297 | host64514.setIP( '192.168.0.44', 24, 'host64514-eth1' ) # for control plane |
| 298 | host64515.cmd( 'ifconfig host64515-eth0 5.0.0.1 up' ) |
| 299 | host64515.cmd( 'ip route add default via 5.0.0.254' ) |
| 300 | host64516.cmd( 'ifconfig host64516-eth0 6.0.0.1 up' ) |
| 301 | host64516.cmd( 'ip route add default via 6.0.0.254' ) |
| 302 | |
| 303 | host1, host2, host6, host13 = \ |
| 304 | net.get( 'host1', 'host2', 'host6', 'host13' ) |
| 305 | host1.cmd( 'ifconfig host1-eth0 201.0.0.1 up' ) |
| 306 | host1.cmd( 'route add default gw 201.0.0.254' ) |
| 307 | host2.cmd( 'ifconfig host2-eth0 202.0.0.1 up' ) |
| 308 | host2.cmd( 'route add default gw 202.0.0.254' ) |
| 309 | host6.cmd( 'ifconfig host6-eth0 206.0.0.1 up' ) |
| 310 | host6.cmd( 'route add default gw 206.0.0.254' ) |
| 311 | host13.cmd( 'ifconfig host13-eth0 213.0.0.13 up' ) |
| 312 | host13.cmd( 'route add default gw 213.0.0.254' ) |
| 313 | |
| 314 | |
| 315 | # set up swCtl100 as a learning |
| 316 | swCtl100 = net.get( 'swCtl100' ) |
| 317 | swCtl100.cmd( 'ovs-vsctl set-controller swCtl100 none' ) |
| 318 | swCtl100.cmd( 'ovs-vsctl set-fail-mode swCtl100 standalone' ) |
| 319 | |
| 320 | # connect all switches to controller |
| 321 | |
| 322 | for i in range ( 1, numSw + 1 ): |
| 323 | swX = net.get( 'sw%s' % ( i ) ) |
| 324 | swX.cmd( 'ovs-vsctl set-controller sw%s tcp:%s:6653' % ( i, onos1IP ) ) |
| 325 | |
| 326 | # Start Quagga on border routers |
| 327 | ''' |
| 328 | for i in range ( 64514, 64516 + 1 ): |
| 329 | startquagga( 'peer%s' % ( i ), i, 'quagga%s.conf' % ( i ) ) |
| 330 | ''' |
| 331 | startquagga( peer64514, 64514, 'quagga64514.conf' ) |
| 332 | startquagga( peer64515, 64515, 'quagga64515.conf' ) |
| 333 | startquagga( peer64516, 64516, 'quagga64516.conf' ) |
| 334 | |
| 335 | # start Quagga in SDN network |
| 336 | startquagga( speaker1, 64513, 'quagga-sdn.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 | speaker1.intf( 'speaker1-eth1' ).setIP( '1.1.1.1/24' ) |
| 344 | |
| 345 | |
| 346 | stopsshd() |
| 347 | |
| 348 | hosts = [ peer64514, peer64515, peer64516, host64514]; |
| 349 | startsshds( hosts ) |
| 350 | # |
| 351 | |
| 352 | forwarding1 = '%s:2000:%s:2000' % ( '1.1.1.2', onos1IP ) |
| 353 | root.cmd( 'ssh -nNT -o "PasswordAuthentication no" \ |
| 354 | -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding1, onos1IP ) ) |
| 355 | |
| 356 | # time.sleep( 3000000000 ) |
| 357 | CLI( net ) |
| 358 | |
| 359 | |
| 360 | stopsshd() |
| 361 | stopquagga() |
| 362 | net.stop() |
| 363 | |
| 364 | if __name__ == '__main__': |
| 365 | setLogLevel( 'debug' ) |
| 366 | sdn1net() |