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