blob: e8caf95a6ad4bf697e8c517ddd63a7f6ae11b107 [file] [log] [blame]
Charles Chan6e29b322017-04-11 11:10:31 -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
15from trellislib import TaggedDhcpClient, TaggedDhcpServer
Charles Chan6e29b322017-04-11 11:10:31 -070016
17class Trellis( Topo ):
18 "Trellis basic topology"
19
20 def __init__( self, *args, **kwargs ):
21 Topo.__init__( self, *args, **kwargs )
22
23 # Spines
24 s226 = self.addSwitch('s226', dpid='226')
25 s227 = self.addSwitch('s227', dpid='227')
26
27 # Leaves
28 s204 = self.addSwitch('s204', dpid='204')
29 s205 = self.addSwitch('s205', dpid='205')
30
31 # Switch Links
32 self.addLink(s226, s204)
33 self.addLink(s226, s205)
34 self.addLink(s227, s204)
35 self.addLink(s227, s205)
36
37 # NOTE avoid using 10.0.1.0/24 which is the default subnet of quaggas
38 # NOTE avoid using 00:00:00:00:00:xx which is the default mac of host behind upstream router
39 # IPv4 Hosts
40 h1 = self.addHost('h1', cls=DhcpClient, mac='00:aa:00:00:00:01')
41 h2 = self.addHost('h2', cls=TaggedDhcpClient, mac='00:aa:00:00:00:02', vlan=20)
42 h3 = self.addHost('h3', cls=DhcpClient, mac='00:aa:00:00:00:03')
Charles Chan279fabf2017-04-24 15:33:14 -070043 h4 = self.addHost('h4', cls=DhcpClient, mac='00:aa:00:00:00:04')
44 # In order to emulate tagged Quagga VM in h4
45 h4ovs = self.addSwitch('h4ovs', cls=OVSBridge)
Charles Chan6e29b322017-04-11 11:10:31 -070046 self.addLink(h1, s204)
47 self.addLink(h2, s204)
48 self.addLink(h3, s205)
Charles Chan279fabf2017-04-24 15:33:14 -070049 self.addLink(h4ovs, s205)
50 self.addLink(h4ovs, h4)
Charles Chan6e29b322017-04-11 11:10:31 -070051
52 # IPv6 Hosts
53 h1v6 = self.addHost('h1v6', cls=RoutedHost, mac='00:bb:00:00:00:01', ips=['2000::201/120'], gateway='2000::2ff')
54 h2v6 = self.addHost('h2v6', cls=RoutedHost, mac='00:bb:00:00:00:02', ips=['2000::202/120'], gateway='2000::2ff')
55 h3v6 = self.addHost('h3v6', cls=RoutedHost, mac='00:bb:00:00:00:03', ips=['2000::301/120'], gateway='2000::3ff')
56 h4v6 = self.addHost('h4v6', cls=RoutedHost, mac='00:bb:00:00:00:04', ips=['2000::302/120'], gateway='2000::3ff')
57 self.addLink(h1v6, s204)
58 self.addLink(h2v6, s204)
59 self.addLink(h3v6, s205)
60 self.addLink(h4v6, s205)
61
62 # DHCP server
63 dhcp = self.addHost('dhcp', cls=TaggedDhcpServer, mac='00:99:00:00:00:01', ips=['10.0.3.253/24'], gateway='10.0.3.254', vlan=30)
64 self.addLink(dhcp, s205)
65
66 # Control plane switch (for quagga fpm)
67 cs0 = self.addSwitch('cs0', cls=OVSBridge)
68
69 # Control plane NAT (for quagga fpm)
70 nat = self.addHost('nat', cls=NAT,
71 ip='172.16.0.1/12',
72 subnet=str(ip_network(u'172.16.0.0/12')), inNamespace=False)
73 self.addLink(cs0, nat)
74
75 # Internal Quagga bgp1
Charles Chan279fabf2017-04-24 15:33:14 -070076 intfs = {'bgp1-eth0': {'ipAddrs': ['10.0.1.2/24', '2000::102/120'], 'mac': '00:88:00:00:00:02', 'vlan': '10'},
Charles Chan6e29b322017-04-11 11:10:31 -070077 'bgp1-eth1': {'ipAddrs': ['172.16.0.2/12']}}
78 bgp1 = self.addHost('bgp1', cls=BgpRouter,
79 interfaces=intfs,
80 quaggaConfFile='./bgpdbgp1.conf',
81 zebraConfFile='./zebradbgp1.conf')
Charles Chan279fabf2017-04-24 15:33:14 -070082 self.addLink(bgp1, h4ovs)
Charles Chan6e29b322017-04-11 11:10:31 -070083 self.addLink(bgp1, cs0)
84
85 # External Quagga r1
86 intfs = {'r1-eth0': {'ipAddrs': ['10.0.1.1/24', '2000::101/120'], 'mac': '00:88:00:00:00:01'},
87 'r1-eth1': {'ipAddrs': ['10.0.99.1/16']},
88 'r1-eth2': {'ipAddrs': ['2000::9901/120']}}
89 r1 = self.addHost('r1', cls=BgpRouter,
90 interfaces=intfs,
91 quaggaConfFile='./bgpdr1.conf')
92 self.addLink(r1, s205)
93
94 # External IPv4 Host behind r1
95 rh1 = self.addHost('rh1', cls=RoutedHost, ips=['10.0.99.2/24'], gateway='10.0.99.1')
96 self.addLink(r1, rh1)
97
98 # External IPv6 Host behind r1
99 rh1v6 = self.addHost('rh1v6', cls=RoutedHost, ips=['2000::9902/120'], gateway='2000::9901')
100 self.addLink(r1, rh1v6)
101
102topos = { 'trellis' : Trellis }
103
Charles Chan6e29b322017-04-11 11:10:31 -0700104if __name__ == "__main__":
105 setLogLevel('debug')
106 topo = Trellis()
107
108 net = Mininet(topo=topo, controller=None)
109 net.addController(RemoteController('c0', ip='192.168.56.11'))
110 net.addController(RemoteController('c1', ip='192.168.56.12'))
111 net.addController(RemoteController('c2', ip='192.168.56.13'))
112
113 net.start()
114 CLI(net)
115 net.stop()