blob: 7739d5849ea699141ea859163cde10d1576fb332 [file] [log] [blame]
Luca Prete3d402dc2016-12-13 16:25:03 -08001#!/usr/bin/env python
2
3from mininet.cli import CLI
4from mininet.log import setLogLevel
5from mininet.node import Link, Host
6from mininet.net import Mininet
7from mininet.node import RemoteController, OVSSwitch, OVSBridge
8from mininet.term import makeTerm
9from mininet.topo import Topo
10from functools import partial
11from routinglib import RoutingCli as CLI
12from routinglib import AutonomousSystem, BasicAutonomousSystem, SdnAutonomousSystem
13from routinglib import generateRoutes
14
15class SdnIpTopo( Topo ):
16
17 "SDN-IP topology"
18
19 def __init__( self, onoses, **kwargs ):
20 Topo.__init__( self, **kwargs )
21 coreMesh = []
22
23 # Create first 4 switches
24 for i in range( 1, 5 ):
25 coreMesh.append( self.addSwitch( 's%s' %i ) )
26
27 # create full mesh between middle 4 switches
28 remaining = list( coreMesh )
29 while True:
30 first = remaining[ 0 ]
31 for switch in tuple( remaining ):
32 if switch is not first:
33 self.addLink( switch, first )
34 remaining.remove( first )
35 if not remaining:
36 break
37
38 # Add more switches
39 s5 = self.addSwitch( 's5', dpid='00:00:00:00:00:00:00:05' )
40 s6 = self.addSwitch( 's6', dpid='00:00:00:00:00:00:00:06' )
41 s7 = self.addSwitch( 's7', dpid='00:00:00:00:00:00:00:07' )
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:0A' )
45
46 # Add more links
47 self.addLink( s5, s6 )
48 self.addLink( s5, s8 )
49 self.addLink( s6, s7 )
50 self.addLink( s8, s9 )
51 self.addLink( s9, s10 )
52 self.addLink( coreMesh[ 0 ], s5 )
53 self.addLink( coreMesh[ 0 ], s6 )
54 self.addLink( coreMesh[ 0 ], s7 )
55 self.addLink( coreMesh[ 1 ], s8 )
56 self.addLink( coreMesh[ 1 ], s9 )
57 self.addLink( coreMesh[ 1 ], s10 )
58 self.addLink( coreMesh[ 2 ], s7 )
59 self.addLink( coreMesh[ 3 ], s10 )
60
61 # SDN AS
62 sdnAs = SdnAutonomousSystem(onoses, numBgpSpeakers=3, asNum=65000, externalOnos=True)
63 cs0 = self.addSwitch('cs0', cls=OVSBridge)
64
65 numRoutesPerAs = 32
66
67 # Add external ASes
68 as1 = BasicAutonomousSystem(1, generateRoutes(u'192.168.1.0/24', numRoutesPerAs))
69 AutonomousSystem.addPeering(as1, sdnAs)
70 AutonomousSystem.addPeering(as1, sdnAs, router2=3, intf1=2)
71 as1.addLink(s5)
72 as1.addLink(s6)
73 as1.build(self)
74
75 as2 = BasicAutonomousSystem(2, generateRoutes(u'192.168.2.0/24', numRoutesPerAs))
76 AutonomousSystem.addPeering(as2, sdnAs)
77 AutonomousSystem.addPeering(as2, sdnAs, router2=2)
78 as2.addLink(s7)
79 as2.build(self)
80
81 as3 = BasicAutonomousSystem(3, generateRoutes(u'192.168.3.0/24', numRoutesPerAs))
82 AutonomousSystem.addPeering(as3, sdnAs, router2=2)
83 AutonomousSystem.addPeering(as3, sdnAs, router2=3)
84 as3.addLink(s8)
85 as3.build(self)
86
87 as4 = BasicAutonomousSystem(4, generateRoutes(u'192.168.4.0/24', numRoutesPerAs), numRouters=2)
88 AutonomousSystem.addPeering(as4, sdnAs)
89 AutonomousSystem.addPeering(as4, sdnAs, router1=2, router2=3)
90 as4.addLink(s9)
91 as4.addLink(s10, router=2)
92 as4.build(self)
93
94 # add links between nets
95 #self.addLink( BGP1, coreMesh[ 0 ], port2=10 )
96 #self.addLink( BGP2, coreMesh[ 1 ], port2=10 )
97 #self.addLink( BGP3, coreMesh[ 2 ], port2=10 )
98
99 sdnAs.build(self, coreMesh[ 0 ], cs0)
100 # TODO multihome the BGP speakers to different switches
101
102topos = { 'sdnip': ( lambda: SdnIpTopo() ) }
103
104if __name__ == '__main__':
105 setLogLevel( 'debug' )
106 from onosnet import run, parse_args
107 run(SdnIpTopo(onoses=parse_args().ipAddrs))