blob: 6fba7e768322ce4c7a72bfc540edec066ed22419 [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
hwchiu0d696b32017-12-07 21:31:07 +08009from mininet.node import RemoteController, OVSBridge, Host, OVSSwitch
Charles Chan6e29b322017-04-11 11:10:31 -070010from 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
Ray Milkey1df260d2018-03-28 11:52:34 -070016from trellislib import get_mininet, parse_trellis_args, set_up_zebra_config
hwchiu0d696b32017-12-07 21:31:07 +080017from functools import partial
Charles Chan6e29b322017-04-11 11:10:31 -070018
19class Trellis( Topo ):
20 "Trellis basic topology"
21
22 def __init__( self, *args, **kwargs ):
23 Topo.__init__( self, *args, **kwargs )
24
25 # Spines
26 s226 = self.addSwitch('s226', dpid='226')
27 s227 = self.addSwitch('s227', dpid='227')
28
29 # Leaves
30 s204 = self.addSwitch('s204', dpid='204')
31 s205 = self.addSwitch('s205', dpid='205')
32
33 # Switch Links
34 self.addLink(s226, s204)
35 self.addLink(s226, s205)
36 self.addLink(s227, s204)
37 self.addLink(s227, s205)
38
39 # NOTE avoid using 10.0.1.0/24 which is the default subnet of quaggas
40 # NOTE avoid using 00:00:00:00:00:xx which is the default mac of host behind upstream router
41 # IPv4 Hosts
42 h1 = self.addHost('h1', cls=DhcpClient, mac='00:aa:00:00:00:01')
43 h2 = self.addHost('h2', cls=TaggedDhcpClient, mac='00:aa:00:00:00:02', vlan=20)
44 h3 = self.addHost('h3', cls=DhcpClient, mac='00:aa:00:00:00:03')
Charles Chan279fabf2017-04-24 15:33:14 -070045 h4 = self.addHost('h4', cls=DhcpClient, mac='00:aa:00:00:00:04')
46 # In order to emulate tagged Quagga VM in h4
Charles Chana60fbd12019-10-22 21:56:35 -070047 h4ovs = self.addSwitch('h4ovs', cls=OVSBridge, datapath='user')
Charles Chan6e29b322017-04-11 11:10:31 -070048 self.addLink(h1, s204)
49 self.addLink(h2, s204)
50 self.addLink(h3, s205)
Charles Chan279fabf2017-04-24 15:33:14 -070051 self.addLink(h4ovs, s205)
52 self.addLink(h4ovs, h4)
Charles Chan6e29b322017-04-11 11:10:31 -070053
54 # IPv6 Hosts
55 h1v6 = self.addHost('h1v6', cls=RoutedHost, mac='00:bb:00:00:00:01', ips=['2000::201/120'], gateway='2000::2ff')
56 h2v6 = self.addHost('h2v6', cls=RoutedHost, mac='00:bb:00:00:00:02', ips=['2000::202/120'], gateway='2000::2ff')
57 h3v6 = self.addHost('h3v6', cls=RoutedHost, mac='00:bb:00:00:00:03', ips=['2000::301/120'], gateway='2000::3ff')
58 h4v6 = self.addHost('h4v6', cls=RoutedHost, mac='00:bb:00:00:00:04', ips=['2000::302/120'], gateway='2000::3ff')
59 self.addLink(h1v6, s204)
60 self.addLink(h2v6, s204)
61 self.addLink(h3v6, s205)
62 self.addLink(h4v6, s205)
63
64 # DHCP server
65 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)
66 self.addLink(dhcp, s205)
67
68 # Control plane switch (for quagga fpm)
Charles Chana60fbd12019-10-22 21:56:35 -070069 cs0 = self.addSwitch('cs0', cls=OVSBridge, datapath='user')
Charles Chan6e29b322017-04-11 11:10:31 -070070
71 # Control plane NAT (for quagga fpm)
72 nat = self.addHost('nat', cls=NAT,
Charles Chan947d2432018-08-17 18:13:31 -070073 ip='172.16.0.1/24',
74 subnet=str(ip_network(u'172.16.0.0/24')), inNamespace=False)
Charles Chan6e29b322017-04-11 11:10:31 -070075 self.addLink(cs0, nat)
76
77 # Internal Quagga bgp1
Charles Chan279fabf2017-04-24 15:33:14 -070078 intfs = {'bgp1-eth0': {'ipAddrs': ['10.0.1.2/24', '2000::102/120'], 'mac': '00:88:00:00:00:02', 'vlan': '10'},
Charles Chan947d2432018-08-17 18:13:31 -070079 'bgp1-eth1': {'ipAddrs': ['172.16.0.2/24']}}
Charles Chan6e29b322017-04-11 11:10:31 -070080 bgp1 = self.addHost('bgp1', cls=BgpRouter,
81 interfaces=intfs,
82 quaggaConfFile='./bgpdbgp1.conf',
83 zebraConfFile='./zebradbgp1.conf')
Charles Chan279fabf2017-04-24 15:33:14 -070084 self.addLink(bgp1, h4ovs)
Charles Chan6e29b322017-04-11 11:10:31 -070085 self.addLink(bgp1, cs0)
86
87 # External Quagga r1
88 intfs = {'r1-eth0': {'ipAddrs': ['10.0.1.1/24', '2000::101/120'], 'mac': '00:88:00:00:00:01'},
89 'r1-eth1': {'ipAddrs': ['10.0.99.1/16']},
90 'r1-eth2': {'ipAddrs': ['2000::9901/120']}}
91 r1 = self.addHost('r1', cls=BgpRouter,
92 interfaces=intfs,
93 quaggaConfFile='./bgpdr1.conf')
94 self.addLink(r1, s205)
95
96 # External IPv4 Host behind r1
97 rh1 = self.addHost('rh1', cls=RoutedHost, ips=['10.0.99.2/24'], gateway='10.0.99.1')
98 self.addLink(r1, rh1)
99
100 # External IPv6 Host behind r1
101 rh1v6 = self.addHost('rh1v6', cls=RoutedHost, ips=['2000::9902/120'], gateway='2000::9901')
102 self.addLink(r1, rh1v6)
103
104topos = { 'trellis' : Trellis }
105
Charles Chan6e29b322017-04-11 11:10:31 -0700106if __name__ == "__main__":
107 setLogLevel('debug')
108 topo = Trellis()
Charles Chana60fbd12019-10-22 21:56:35 -0700109 switch = partial(OVSSwitch, protocols='OpenFlow13', datapath='user')
Ray Milkey1df260d2018-03-28 11:52:34 -0700110 arguments = parse_trellis_args()
111 set_up_zebra_config(arguments.controllers)
112 net = get_mininet(arguments, topo, switch)
Charles Chan6e29b322017-04-11 11:10:31 -0700113
114 net.start()
115 CLI(net)
116 net.stop()