Charles Chan | b0dd5ed | 2017-03-29 17:36:21 -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 | b0dd5ed | 2017-03-29 17:36:21 -0700 | [diff] [blame] | 10 | from mininet.link import TCLink |
| 11 | from mininet.nodelib import NAT |
| 12 | from ipaddress import ip_network |
| 13 | from routinglib import BgpRouter |
Yi Tseng | 45ee692 | 2017-07-17 14:49:17 -0700 | [diff] [blame] | 14 | from routinglib import RoutedHost, RoutedHost6 |
| 15 | from trellislib import DhcpClient, Dhcp6Client, DhcpRelay, DhcpServer, Dhcp6Server |
Charles Chan | ec57b95 | 2017-04-24 17:05:06 -0700 | [diff] [blame] | 16 | from trellislib import DualHomedDhcpClient |
Ray Milkey | 1df260d | 2018-03-28 11:52:34 -0700 | [diff] [blame] | 17 | from trellislib import get_mininet, parse_trellis_args, set_up_zebra_config |
hwchiu | 0d696b3 | 2017-12-07 21:31:07 +0800 | [diff] [blame] | 18 | from functools import partial |
Charles Chan | b0dd5ed | 2017-03-29 17:36:21 -0700 | [diff] [blame] | 19 | |
| 20 | class Trellis( Topo ): |
| 21 | "Trellis basic topology" |
| 22 | |
| 23 | def __init__( self, *args, **kwargs ): |
| 24 | Topo.__init__( self, *args, **kwargs ) |
| 25 | |
| 26 | # Spines |
| 27 | s226 = self.addSwitch('s226', dpid='226') |
| 28 | s227 = self.addSwitch('s227', dpid='227') |
| 29 | |
| 30 | # Leaves |
| 31 | s203 = self.addSwitch('s203', dpid='203') |
| 32 | s204 = self.addSwitch('s204', dpid='204') |
| 33 | s205 = self.addSwitch('s205', dpid='205') |
| 34 | s206 = self.addSwitch('s206', dpid='206') |
| 35 | |
| 36 | # Leaf-Spine Links |
| 37 | self.addLink(s226, s203) |
| 38 | self.addLink(s226, s203) |
| 39 | self.addLink(s226, s204) |
| 40 | self.addLink(s226, s204) |
| 41 | self.addLink(s226, s205) |
| 42 | self.addLink(s226, s205) |
| 43 | self.addLink(s226, s206) |
| 44 | self.addLink(s226, s206) |
| 45 | self.addLink(s227, s203) |
| 46 | self.addLink(s227, s203) |
| 47 | self.addLink(s227, s204) |
| 48 | self.addLink(s227, s204) |
| 49 | self.addLink(s227, s205) |
| 50 | self.addLink(s227, s205) |
| 51 | self.addLink(s227, s206) |
| 52 | self.addLink(s227, s206) |
| 53 | |
| 54 | # Leaf-Leaf Links |
| 55 | self.addLink(s203, s204) |
| 56 | self.addLink(s205, s206) |
| 57 | |
| 58 | # NOTE avoid using 10.0.1.0/24 which is the default subnet of quaggas |
| 59 | # NOTE avoid using 00:00:00:00:00:xx which is the default mac of host behind upstream router |
| 60 | # IPv4 Hosts |
| 61 | h1 = self.addHost('h1', cls=DhcpClient, mac='00:aa:00:00:00:01') |
| 62 | h2 = self.addHost('h2', cls=DhcpClient, mac='00:aa:00:00:00:02') |
| 63 | h3 = self.addHost('h3', cls=DhcpClient, mac='00:aa:00:00:00:03') |
| 64 | h4 = self.addHost('h4', cls=DhcpClient, mac='00:aa:00:00:00:04') |
| 65 | self.addLink(h1, s204) |
| 66 | self.addLink(h2, s204) |
| 67 | self.addLink(h3, s205) |
| 68 | self.addLink(h4, s205) |
| 69 | |
| 70 | # IPv6 Hosts |
Yi Tseng | 45ee692 | 2017-07-17 14:49:17 -0700 | [diff] [blame] | 71 | h1v6 = self.addHost('h1v6', cls=Dhcp6Client, mac='00:bb:00:00:00:01') |
| 72 | h2v6 = self.addHost('h2v6', cls=Dhcp6Client, mac='00:bb:00:00:00:02') |
| 73 | h3v6 = self.addHost('h3v6', cls=Dhcp6Client, mac='00:bb:00:00:00:03') |
| 74 | h4v6 = self.addHost('h4v6', cls=Dhcp6Client, mac='00:bb:00:00:00:04') |
Charles Chan | b0dd5ed | 2017-03-29 17:36:21 -0700 | [diff] [blame] | 75 | self.addLink(h1v6, s204) |
| 76 | self.addLink(h2v6, s204) |
| 77 | self.addLink(h3v6, s205) |
| 78 | self.addLink(h4v6, s205) |
| 79 | |
| 80 | # Dual-homed IPv4 Hosts |
| 81 | dh1 = self.addHost('dh1', cls=DualHomedDhcpClient, mac='00:cc:00:00:00:01') |
| 82 | self.addLink(dh1, s204) |
| 83 | self.addLink(dh1, s203) |
| 84 | |
| 85 | # DHCP server |
| 86 | dhcp = self.addHost('dhcp', cls=DhcpServer, mac='00:99:00:00:00:01', ips=['10.0.3.253/24'], gateway='10.0.3.254') |
Yi Tseng | 45ee692 | 2017-07-17 14:49:17 -0700 | [diff] [blame] | 87 | |
| 88 | # DHCPv6 server |
| 89 | dhcp6 = self.addHost('dhcp6', cls=Dhcp6Server, mac='00:99:66:00:00:01', ips=['2000::3fd/120'], gateway='2000::3ff') |
| 90 | |
| 91 | # Control plane switch (for DHCP servers) |
| 92 | cs1 = self.addSwitch('cs1', cls=OVSBridge) |
| 93 | self.addLink(cs1, s205) |
| 94 | self.addLink(dhcp, cs1) |
| 95 | self.addLink(dhcp6, cs1) |
Charles Chan | b0dd5ed | 2017-03-29 17:36:21 -0700 | [diff] [blame] | 96 | |
| 97 | # Control plane switch (for quagga fpm) |
| 98 | cs0 = self.addSwitch('cs0', cls=OVSBridge) |
| 99 | |
| 100 | # Control plane NAT (for quagga fpm) |
| 101 | nat = self.addHost('nat', cls=NAT, |
Charles Chan | 947d243 | 2018-08-17 18:13:31 -0700 | [diff] [blame] | 102 | ip='172.16.0.1/24', |
| 103 | subnet=str(ip_network(u'172.16.0.0/24')), inNamespace=False) |
Charles Chan | b0dd5ed | 2017-03-29 17:36:21 -0700 | [diff] [blame] | 104 | self.addLink(cs0, nat) |
| 105 | |
| 106 | # Internal Quagga bgp1 |
Charles Chan | c3122db | 2017-09-01 10:58:24 -0700 | [diff] [blame] | 107 | intfs = {'bgp1-eth0': [{'ipAddrs': ['10.0.1.2/24', '2000::102/120'], 'mac': '00:88:00:00:00:03', 'vlan': '110'}, |
| 108 | {'ipAddrs': ['10.0.7.2/24', '2000::702/120'], 'mac': '00:88:00:00:00:03', 'vlan': '170'}], |
Charles Chan | 947d243 | 2018-08-17 18:13:31 -0700 | [diff] [blame] | 109 | 'bgp1-eth1': {'ipAddrs': ['172.16.0.3/24']}} |
Charles Chan | b0dd5ed | 2017-03-29 17:36:21 -0700 | [diff] [blame] | 110 | bgp1 = self.addHost('bgp1', cls=BgpRouter, |
| 111 | interfaces=intfs, |
| 112 | quaggaConfFile='./bgpdbgp1.conf', |
| 113 | zebraConfFile='./zebradbgp1.conf') |
| 114 | self.addLink(bgp1, s205) |
| 115 | self.addLink(bgp1, cs0) |
| 116 | |
Charles Chan | c3122db | 2017-09-01 10:58:24 -0700 | [diff] [blame] | 117 | # Internal Quagga bgp2 |
| 118 | intfs = {'bgp2-eth0': [{'ipAddrs': ['10.0.5.2/24', '2000::502/120'], 'mac': '00:88:00:00:00:04', 'vlan': '150'}, |
| 119 | {'ipAddrs': ['10.0.6.2/24', '2000::602/120'], 'mac': '00:88:00:00:00:04', 'vlan': '160'}], |
Charles Chan | 947d243 | 2018-08-17 18:13:31 -0700 | [diff] [blame] | 120 | 'bgp2-eth1': {'ipAddrs': ['172.16.0.4/24']}} |
Charles Chan | c3122db | 2017-09-01 10:58:24 -0700 | [diff] [blame] | 121 | bgp2 = self.addHost('bgp2', cls=BgpRouter, |
| 122 | interfaces=intfs, |
| 123 | quaggaConfFile='./bgpdbgp2.conf', |
| 124 | zebraConfFile='./zebradbgp2.conf') |
| 125 | self.addLink(bgp2, s206) |
| 126 | self.addLink(bgp2, cs0) |
| 127 | |
Charles Chan | b0dd5ed | 2017-03-29 17:36:21 -0700 | [diff] [blame] | 128 | # External Quagga r1 |
| 129 | intfs = {'r1-eth0': {'ipAddrs': ['10.0.1.1/24', '2000::101/120'], 'mac': '00:88:00:00:00:01'}, |
Charles Chan | c3122db | 2017-09-01 10:58:24 -0700 | [diff] [blame] | 130 | 'r1-eth1': {'ipAddrs': ['10.0.5.1/24', '2000::501/120'], 'mac': '00:88:00:00:00:11'}, |
| 131 | 'r1-eth2': {'ipAddrs': ['10.0.99.1/16']}, |
| 132 | 'r1-eth3': {'ipAddrs': ['2000::9901/120']}, |
| 133 | 'r1-eth4': {'ipAddrs': ['2000::7701/120']}} |
Charles Chan | b0dd5ed | 2017-03-29 17:36:21 -0700 | [diff] [blame] | 134 | r1 = self.addHost('r1', cls=BgpRouter, |
| 135 | interfaces=intfs, |
| 136 | quaggaConfFile='./bgpdr1.conf') |
| 137 | self.addLink(r1, s205) |
Charles Chan | c3122db | 2017-09-01 10:58:24 -0700 | [diff] [blame] | 138 | self.addLink(r1, s206) |
Charles Chan | b0dd5ed | 2017-03-29 17:36:21 -0700 | [diff] [blame] | 139 | |
| 140 | # External IPv4 Host behind r1 |
| 141 | rh1 = self.addHost('rh1', cls=RoutedHost, ips=['10.0.99.2/24'], gateway='10.0.99.1') |
| 142 | self.addLink(r1, rh1) |
| 143 | |
| 144 | # External IPv6 Host behind r1 |
| 145 | rh1v6 = self.addHost('rh1v6', cls=RoutedHost, ips=['2000::9902/120'], gateway='2000::9901') |
| 146 | self.addLink(r1, rh1v6) |
| 147 | |
Charles Chan | c3122db | 2017-09-01 10:58:24 -0700 | [diff] [blame] | 148 | # Another external IPv6 Host behind r1 |
| 149 | rh11v6 = self.addHost('rh11v6', cls=RoutedHost, ips=['2000::7702/120'], gateway='2000::7701') |
| 150 | self.addLink(r1, rh11v6) |
| 151 | |
| 152 | # External Quagga r2 |
| 153 | intfs = {'r2-eth0': {'ipAddrs': ['10.0.6.1/24', '2000::601/120'], 'mac': '00:88:00:00:00:02'}, |
| 154 | 'r2-eth1': {'ipAddrs': ['10.0.7.1/24', '2000::701/120'], 'mac': '00:88:00:00:00:22'}, |
| 155 | 'r2-eth2': {'ipAddrs': ['10.0.99.1/16']}, |
| 156 | 'r2-eth3': {'ipAddrs': ['2000::9901/120']}, |
| 157 | 'r2-eth4': {'ipAddrs': ['2000::8801/120']}} |
| 158 | r2 = self.addHost('r2', cls=BgpRouter, |
| 159 | interfaces=intfs, |
| 160 | quaggaConfFile='./bgpdr2.conf') |
| 161 | self.addLink(r2, s206) |
| 162 | self.addLink(r2, s205) |
| 163 | |
| 164 | # External IPv4 Host behind r2 |
| 165 | rh2 = self.addHost('rh2', cls=RoutedHost, ips=['10.0.99.2/24'], gateway='10.0.99.1') |
| 166 | self.addLink(r2, rh2) |
| 167 | |
| 168 | # External IPv6 Host behind r2 |
| 169 | rh2v6 = self.addHost('rh126', cls=RoutedHost, ips=['2000::9902/120'], gateway='2000::9901') |
| 170 | self.addLink(r2, rh2v6) |
| 171 | |
| 172 | # Another external IPv6 Host behind r1 |
| 173 | rh22v6 = self.addHost('rh22v6', cls=RoutedHost, ips=['2000::8802/120'], gateway='2000::8801') |
| 174 | self.addLink(r2, rh22v6) |
| 175 | |
Charles Chan | b0dd5ed | 2017-03-29 17:36:21 -0700 | [diff] [blame] | 176 | topos = { 'trellis' : Trellis } |
| 177 | |
Charles Chan | b0dd5ed | 2017-03-29 17:36:21 -0700 | [diff] [blame] | 178 | if __name__ == "__main__": |
| 179 | setLogLevel('debug') |
| 180 | topo = Trellis() |
hwchiu | 0d696b3 | 2017-12-07 21:31:07 +0800 | [diff] [blame] | 181 | switch = partial(OVSSwitch, protocols='OpenFlow13') |
Ray Milkey | 1df260d | 2018-03-28 11:52:34 -0700 | [diff] [blame] | 182 | arguments = parse_trellis_args() |
| 183 | set_up_zebra_config(arguments.controllers) |
| 184 | net = get_mininet(arguments, topo, switch) |
Charles Chan | b0dd5ed | 2017-03-29 17:36:21 -0700 | [diff] [blame] | 185 | |
| 186 | net.start() |
| 187 | CLI(net) |
| 188 | net.stop() |