Jonathan Hart | ce97e5b | 2016-04-19 01:41:31 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | from mininet.topo import Topo |
| 4 | from mininet.node import RemoteController, OVSSwitch, OVSBridge |
| 5 | from mininet.log import setLogLevel, info |
| 6 | from mininet.net import Mininet |
| 7 | from routinglib import RoutingCli as CLI |
| 8 | from routinglib import AutonomousSystem, BasicAutonomousSystem, SdnAutonomousSystem |
| 9 | from routinglib import generateRoutes |
| 10 | |
| 11 | onoses = [ '192.168.56.11', '192.168.56.12', '192.168.56.13' ] |
| 12 | |
| 13 | class Dec14DemoTopo( Topo ): |
| 14 | |
| 15 | "Topology from the Dec 14 SDN-IP demo" |
| 16 | |
| 17 | def __init__( self, **kwargs ): |
| 18 | Topo.__init__( self, **kwargs ) |
| 19 | coreMesh = [] |
| 20 | |
| 21 | for i in range( 1, 5 ): |
| 22 | coreMesh.append( self.addSwitch( 's%s' %i ) ) |
| 23 | |
| 24 | # create full mesh between middle 4 switches |
| 25 | remaining = list( coreMesh ) |
| 26 | while True: |
| 27 | first = remaining[ 0 ] |
| 28 | for switch in tuple( remaining ): |
| 29 | if switch is not first: |
| 30 | self.addLink( switch, first ) |
| 31 | remaining.remove( first ) |
| 32 | if not remaining: |
| 33 | break |
| 34 | |
| 35 | |
| 36 | s5 = self.addSwitch( 's5', dpid='00:00:00:00:00:00:00:05' ) |
| 37 | s6 = self.addSwitch( 's6', dpid='00:00:00:00:00:00:00:06' ) |
| 38 | s7 = self.addSwitch( 's7', dpid='00:00:00:00:00:00:00:07' ) |
| 39 | self.addLink( s5, s6 ) |
| 40 | self.addLink( s6, s7 ) |
| 41 | |
| 42 | s8 = self.addSwitch( 's8', dpid='00:00:00:00:00:00:00:08' ) |
| 43 | s9 = self.addSwitch( 's9', dpid='00:00:00:00:00:00:00:09' ) |
| 44 | s10 = self.addSwitch( 's10', dpid='00:00:00:00:00:00:00:10' ) |
| 45 | self.addLink( s8, s9 ) |
| 46 | self.addLink( s9, s10 ) |
| 47 | |
| 48 | self.addLink( s5, s8 ) |
| 49 | |
| 50 | # add links between core mesh and satellite switches |
| 51 | self.addLink( coreMesh[ 0 ], s5 ) |
| 52 | self.addLink( coreMesh[ 0 ], s6 ) |
| 53 | self.addLink( coreMesh[ 0 ], s7 ) |
| 54 | self.addLink( coreMesh[ 1 ], s8 ) |
| 55 | self.addLink( coreMesh[ 1 ], s9 ) |
| 56 | self.addLink( coreMesh[ 1 ], s10 ) |
| 57 | self.addLink( coreMesh[ 2 ], s7 ) |
| 58 | self.addLink( coreMesh[ 3 ], s10 ) |
| 59 | |
| 60 | # SDN AS |
| 61 | sdnAs = SdnAutonomousSystem(onoses, numBgpSpeakers=3, asNum=65000, externalOnos=True) |
| 62 | cs0 = self.addSwitch('cs0', cls=OVSBridge) |
| 63 | |
| 64 | numRoutesPerAs = 32 |
| 65 | |
| 66 | # Add external ASes |
| 67 | as1 = BasicAutonomousSystem(1, generateRoutes(u'192.168.1.0/24', numRoutesPerAs)) |
| 68 | AutonomousSystem.addPeering(as1, sdnAs) |
| 69 | AutonomousSystem.addPeering(as1, sdnAs, router2=3, intf1=2) |
| 70 | as1.addLink(s5) |
| 71 | as1.addLink(s6) |
| 72 | as1.build(self) |
| 73 | |
| 74 | as2 = BasicAutonomousSystem(2, generateRoutes(u'192.168.2.0/24', numRoutesPerAs)) |
| 75 | AutonomousSystem.addPeering(as2, sdnAs) |
| 76 | AutonomousSystem.addPeering(as2, sdnAs, router2=2) |
| 77 | as2.addLink(s7) |
| 78 | as2.build(self) |
| 79 | |
| 80 | as3 = BasicAutonomousSystem(3, generateRoutes(u'192.168.3.0/24', numRoutesPerAs)) |
| 81 | AutonomousSystem.addPeering(as3, sdnAs, router2=2) |
| 82 | AutonomousSystem.addPeering(as3, sdnAs, router2=3) |
| 83 | as3.addLink(s8) |
| 84 | as3.build(self) |
| 85 | |
| 86 | as4 = BasicAutonomousSystem(4, generateRoutes(u'192.168.4.0/24', numRoutesPerAs), numRouters=2) |
| 87 | AutonomousSystem.addPeering(as4, sdnAs) |
| 88 | AutonomousSystem.addPeering(as4, sdnAs, router1=2, router2=3) |
| 89 | as4.addLink(s9) |
| 90 | as4.addLink(s10, router=2) |
| 91 | as4.build(self) |
| 92 | |
| 93 | # add links between nets |
| 94 | #self.addLink( BGP1, coreMesh[ 0 ], port2=10 ) |
| 95 | #self.addLink( BGP2, coreMesh[ 1 ], port2=10 ) |
| 96 | #self.addLink( BGP3, coreMesh[ 2 ], port2=10 ) |
| 97 | |
| 98 | sdnAs.build(self, coreMesh[0], cs0) |
| 99 | # TODO multihome the BGP speakers to different switches |
| 100 | |
| 101 | def run(): |
| 102 | topo = Dec14DemoTopo( ) |
| 103 | net = Mininet( topo=topo, switch=OVSSwitch, controller=None ) |
| 104 | |
| 105 | for i in range(len(onoses)): |
| 106 | net.addController( RemoteController( 'c%s' % (i+1), ip=onoses[i], checkListening=False ) ) |
| 107 | |
| 108 | net.start() |
| 109 | |
| 110 | CLI( net ) |
| 111 | |
| 112 | net.stop() |
| 113 | info( 'done\n' ) |
| 114 | |
| 115 | if __name__ == '__main__': |
| 116 | setLogLevel( 'debug' ) |
| 117 | run() |
| 118 | |
| 119 | |