Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import sys |
| 4 | sys.path.append('..') |
| 5 | from mininet.topo import Topo |
| 6 | from mininet.net import Mininet |
| 7 | from mininet.cli import CLI |
| 8 | from mininet.log import setLogLevel |
hwchiu | 0d696b3 | 2017-12-07 21:31:07 +0800 | [diff] [blame] | 9 | from mininet.node import RemoteController, OVSBridge, Host, OVSSwitch |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 10 | from mininet.nodelib import NAT |
| 11 | from ipaddress import ip_network |
| 12 | from routinglib import BgpRouter |
| 13 | from routinglib import RoutedHost |
Charles Chan | ec57b95 | 2017-04-24 17:05:06 -0700 | [diff] [blame] | 14 | from trellislib import DhcpClient, DhcpServer |
| 15 | from trellislib import TaggedDhcpClient, TaggedDhcpServer |
Ray Milkey | 1df260d | 2018-03-28 11:52:34 -0700 | [diff] [blame] | 16 | from trellislib import get_mininet, parse_trellis_args, set_up_zebra_config |
hwchiu | 0d696b3 | 2017-12-07 21:31:07 +0800 | [diff] [blame] | 17 | from functools import partial |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 18 | |
| 19 | class 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 Chan | 279fabf | 2017-04-24 15:33:14 -0700 | [diff] [blame] | 45 | h4 = self.addHost('h4', cls=DhcpClient, mac='00:aa:00:00:00:04') |
| 46 | # In order to emulate tagged Quagga VM in h4 |
Charles Chan | a60fbd1 | 2019-10-22 21:56:35 -0700 | [diff] [blame] | 47 | h4ovs = self.addSwitch('h4ovs', cls=OVSBridge, datapath='user') |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 48 | self.addLink(h1, s204) |
| 49 | self.addLink(h2, s204) |
| 50 | self.addLink(h3, s205) |
Charles Chan | 279fabf | 2017-04-24 15:33:14 -0700 | [diff] [blame] | 51 | self.addLink(h4ovs, s205) |
| 52 | self.addLink(h4ovs, h4) |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 53 | |
| 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 Chan | a60fbd1 | 2019-10-22 21:56:35 -0700 | [diff] [blame] | 69 | cs0 = self.addSwitch('cs0', cls=OVSBridge, datapath='user') |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 70 | |
| 71 | # Control plane NAT (for quagga fpm) |
| 72 | nat = self.addHost('nat', cls=NAT, |
Charles Chan | 947d243 | 2018-08-17 18:13:31 -0700 | [diff] [blame] | 73 | ip='172.16.0.1/24', |
| 74 | subnet=str(ip_network(u'172.16.0.0/24')), inNamespace=False) |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 75 | self.addLink(cs0, nat) |
| 76 | |
| 77 | # Internal Quagga bgp1 |
Charles Chan | 279fabf | 2017-04-24 15:33:14 -0700 | [diff] [blame] | 78 | intfs = {'bgp1-eth0': {'ipAddrs': ['10.0.1.2/24', '2000::102/120'], 'mac': '00:88:00:00:00:02', 'vlan': '10'}, |
Charles Chan | 947d243 | 2018-08-17 18:13:31 -0700 | [diff] [blame] | 79 | 'bgp1-eth1': {'ipAddrs': ['172.16.0.2/24']}} |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 80 | bgp1 = self.addHost('bgp1', cls=BgpRouter, |
| 81 | interfaces=intfs, |
| 82 | quaggaConfFile='./bgpdbgp1.conf', |
| 83 | zebraConfFile='./zebradbgp1.conf') |
Charles Chan | 279fabf | 2017-04-24 15:33:14 -0700 | [diff] [blame] | 84 | self.addLink(bgp1, h4ovs) |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 85 | 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 | |
| 104 | topos = { 'trellis' : Trellis } |
| 105 | |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 106 | if __name__ == "__main__": |
| 107 | setLogLevel('debug') |
| 108 | topo = Trellis() |
Charles Chan | a60fbd1 | 2019-10-22 21:56:35 -0700 | [diff] [blame] | 109 | switch = partial(OVSSwitch, protocols='OpenFlow13', datapath='user') |
Ray Milkey | 1df260d | 2018-03-28 11:52:34 -0700 | [diff] [blame] | 110 | arguments = parse_trellis_args() |
| 111 | set_up_zebra_config(arguments.controllers) |
| 112 | net = get_mininet(arguments, topo, switch) |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 113 | |
| 114 | net.start() |
| 115 | CLI(net) |
| 116 | net.stop() |