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.net import Mininet |
| 5 | from mininet.cli import CLI |
| 6 | from mininet.log import setLogLevel, info |
| 7 | from mininet.node import RemoteController, OVSBridge |
| 8 | from routinglib import BasicAutonomousSystem |
| 9 | from routinglib import SdnAutonomousSystem, AutonomousSystem |
| 10 | from routinglib import generateRoutes |
| 11 | |
| 12 | |
| 13 | class BgpRouterTopo( Topo ): |
| 14 | "Single switch topology for testing the BgpRouter" |
| 15 | |
| 16 | def __init__( self, *args, **kwargs ): |
| 17 | Topo.__init__( self, *args, **kwargs ) |
| 18 | # Router switch |
| 19 | s1 = self.addSwitch('s1', dpid='00000000000000a1') |
| 20 | |
| 21 | # Control plane switch for BGP daemon |
| 22 | s7 = self.addSwitch('s7', dpid='00000000000000a7') |
| 23 | |
| 24 | # SDN AS |
| 25 | onosIps = ['192.168.56.11'] |
| 26 | sdnAs = SdnAutonomousSystem(onosIps, numBgpSpeakers=1, asNum=65000) |
| 27 | |
| 28 | numRoutesPerAs = 1 |
| 29 | |
| 30 | # Normal ASes |
| 31 | as1 = BasicAutonomousSystem(1, |
| 32 | generateRoutes(u'10.1.0.0/16', numRoutesPerAs)) |
| 33 | AutonomousSystem.addPeering(as1, sdnAs, useVlans=True) |
| 34 | as1.addLink(s1) |
| 35 | as1.build(self) |
| 36 | |
| 37 | as2 = BasicAutonomousSystem(2, |
| 38 | generateRoutes(u'10.2.0.0/16', numRoutesPerAs)) |
| 39 | AutonomousSystem.addPeering(as2, sdnAs, useVlans=True) |
| 40 | as2.addLink(s1) |
| 41 | as2.build(self) |
| 42 | |
| 43 | as3 = BasicAutonomousSystem(3, |
| 44 | generateRoutes(u'10.3.0.0/16', numRoutesPerAs)) |
| 45 | AutonomousSystem.addPeering(as3, sdnAs, useVlans=True) |
| 46 | as3.addLink(s1) |
| 47 | as3.build(self) |
| 48 | |
| 49 | as4 = BasicAutonomousSystem(4, |
| 50 | generateRoutes(u'10.4.0.0/16', numRoutesPerAs)) |
| 51 | AutonomousSystem.addPeering(as4, sdnAs, useVlans=False) |
| 52 | as4.addLink(s1) |
| 53 | as4.build(self) |
| 54 | |
| 55 | # SDN AS (internal BGP speaker) connects to control plane switch |
| 56 | cs0 = self.addSwitch('cs0', cls=OVSBridge) |
| 57 | sdnAs.build(self, s7, cs0) |
| 58 | |
| 59 | if __name__ == "__main__": |
| 60 | setLogLevel('debug') |
| 61 | topo = BgpRouterTopo() |
| 62 | |
| 63 | net = Mininet(topo=topo, controller=None) |
| 64 | net.addController(RemoteController('c0', ip='192.168.56.11')) |
| 65 | |
| 66 | net.start() |
| 67 | |
| 68 | CLI(net) |
| 69 | |
| 70 | net.stop() |
| 71 | |
| 72 | info("done\n") |