blob: 2fab97b5508ed7e5ce585af788a2ee1887d08d29 [file] [log] [blame]
Charles Chan6f149a92017-03-24 19:35:41 -07001#!/usr/bin/python
2
3import sys
4sys.path.append('..')
5from mininet.topo import Topo
6from mininet.net import Mininet
7from mininet.cli import CLI
8from mininet.log import setLogLevel
9from mininet.node import RemoteController, OVSBridge, Host
10from mininet.nodelib import NAT
11from ipaddress import ip_network
12from routinglib import BgpRouter
13from routinglib import RoutedHost
Charles Chanec57b952017-04-24 17:05:06 -070014from trellislib import DhcpClient, DhcpServer
Charles Chan6f149a92017-03-24 19:35:41 -070015
16class Trellis( Topo ):
17 "Trellis basic topology"
18
19 def __init__( self, *args, **kwargs ):
20 Topo.__init__( self, *args, **kwargs )
21
22 # Spines
23 s226 = self.addSwitch('s226', dpid='226')
24 s227 = self.addSwitch('s227', dpid='227')
25
26 # Leaves
27 s204 = self.addSwitch('s204', dpid='204')
28 s205 = self.addSwitch('s205', dpid='205')
29
30 # Switch Links
31 self.addLink(s226, s204)
32 self.addLink(s226, s205)
33 self.addLink(s227, s204)
34 self.addLink(s227, s205)
35
36 # NOTE avoid using 10.0.1.0/24 which is the default subnet of quaggas
37 # NOTE avoid using 00:00:00:00:00:xx which is the default mac of host behind upstream router
38 # IPv4 Hosts
39 h1 = self.addHost('h1', cls=DhcpClient, mac='00:aa:00:00:00:01')
40 h2 = self.addHost('h2', cls=DhcpClient, mac='00:aa:00:00:00:02')
41 h3 = self.addHost('h3', cls=DhcpClient, mac='00:aa:00:00:00:03')
42 h4 = self.addHost('h4', cls=DhcpClient, mac='00:aa:00:00:00:04')
43 self.addLink(h1, s204)
44 self.addLink(h2, s204)
45 self.addLink(h3, s205)
46 self.addLink(h4, s205)
47
48 # IPv6 Hosts
49 h1v6 = self.addHost('h1v6', cls=RoutedHost, mac='00:bb:00:00:00:01', ips=['2000::201/120'], gateway='2000::2ff')
50 h2v6 = self.addHost('h2v6', cls=RoutedHost, mac='00:bb:00:00:00:02', ips=['2000::202/120'], gateway='2000::2ff')
51 h3v6 = self.addHost('h3v6', cls=RoutedHost, mac='00:bb:00:00:00:03', ips=['2000::301/120'], gateway='2000::3ff')
52 h4v6 = self.addHost('h4v6', cls=RoutedHost, mac='00:bb:00:00:00:04', ips=['2000::302/120'], gateway='2000::3ff')
53 self.addLink(h1v6, s204)
54 self.addLink(h2v6, s204)
55 self.addLink(h3v6, s205)
56 self.addLink(h4v6, s205)
57
58 # DHCP server
59 dhcp = self.addHost('dhcp', cls=DhcpServer, mac='00:99:00:00:00:01', ips=['10.0.3.253/24'], gateway='10.0.3.254')
60 self.addLink(dhcp, s205)
61
62 # Control plane switch (for quagga fpm)
63 cs0 = self.addSwitch('cs0', cls=OVSBridge)
64
65 # Control plane NAT (for quagga fpm)
66 nat = self.addHost('nat', cls=NAT,
67 ip='172.16.0.1/12',
68 subnet=str(ip_network(u'172.16.0.0/12')), inNamespace=False)
69 self.addLink(cs0, nat)
70
71 # Internal Quagga bgp1
72 intfs = {'bgp1-eth0': {'ipAddrs': ['10.0.1.2/24', '2000::102/120'], 'mac': '00:88:00:00:00:02'},
73 'bgp1-eth1': {'ipAddrs': ['172.16.0.2/12']}}
74 bgp1 = self.addHost('bgp1', cls=BgpRouter,
75 interfaces=intfs,
76 quaggaConfFile='./bgpdbgp1.conf',
77 zebraConfFile='./zebradbgp1.conf')
78 self.addLink(bgp1, s205)
79 self.addLink(bgp1, cs0)
80
81 # External Quagga r1
82 intfs = {'r1-eth0': {'ipAddrs': ['10.0.1.1/24', '2000::101/120'], 'mac': '00:88:00:00:00:01'},
83 'r1-eth1': {'ipAddrs': ['10.0.99.1/16']},
84 'r1-eth2': {'ipAddrs': ['2000::9901/120']}}
85 r1 = self.addHost('r1', cls=BgpRouter,
86 interfaces=intfs,
87 quaggaConfFile='./bgpdr1.conf')
88 self.addLink(r1, s205)
89
90 # External IPv4 Host behind r1
91 rh1 = self.addHost('rh1', cls=RoutedHost, ips=['10.0.99.2/24'], gateway='10.0.99.1')
92 self.addLink(r1, rh1)
93
94 # External IPv6 Host behind r1
95 rh1v6 = self.addHost('rh1v6', cls=RoutedHost, ips=['2000::9902/120'], gateway='2000::9901')
96 self.addLink(r1, rh1v6)
97
98topos = { 'trellis' : Trellis }
99
Charles Chan6f149a92017-03-24 19:35:41 -0700100if __name__ == "__main__":
101 setLogLevel('debug')
102 topo = Trellis()
103
104 net = Mininet(topo=topo, controller=None)
105 net.addController(RemoteController('c0', ip='192.168.56.11'))
106 net.addController(RemoteController('c1', ip='192.168.56.12'))
107 net.addController(RemoteController('c2', ip='192.168.56.13'))
108
109 net.start()
110 CLI(net)
111 net.stop()