Charles Chan | 6f149a9 | 2017-03-24 19:35:41 -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 | 6f149a9 | 2017-03-24 19:35:41 -0700 | [diff] [blame] | 10 | from mininet.nodelib import NAT |
| 11 | from ipaddress import ip_network |
| 12 | from routinglib import BgpRouter |
Yi Tseng | 45ee692 | 2017-07-17 14:49:17 -0700 | [diff] [blame] | 13 | from routinglib import RoutedHost, RoutedHost6 |
| 14 | from trellislib import DhcpClient, Dhcp6Client, DhcpRelay, DhcpServer, Dhcp6Server |
Ray Milkey | 1df260d | 2018-03-28 11:52:34 -0700 | [diff] [blame] | 15 | from trellislib import get_mininet, parse_trellis_args, set_up_zebra_config |
hwchiu | 0d696b3 | 2017-12-07 21:31:07 +0800 | [diff] [blame] | 16 | from functools import partial |
Charles Chan | 6f149a9 | 2017-03-24 19:35:41 -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 | s204 = self.addSwitch('s204', dpid='204') |
| 30 | s205 = self.addSwitch('s205', dpid='205') |
| 31 | |
| 32 | # Switch Links |
| 33 | self.addLink(s226, s204) |
| 34 | self.addLink(s226, s205) |
| 35 | self.addLink(s227, s204) |
| 36 | self.addLink(s227, s205) |
| 37 | |
| 38 | # NOTE avoid using 10.0.1.0/24 which is the default subnet of quaggas |
| 39 | # NOTE avoid using 00:00:00:00:00:xx which is the default mac of host behind upstream router |
| 40 | # IPv4 Hosts |
| 41 | h1 = self.addHost('h1', cls=DhcpClient, mac='00:aa:00:00:00:01') |
| 42 | h2 = self.addHost('h2', cls=DhcpClient, mac='00:aa:00:00:00:02') |
| 43 | h3 = self.addHost('h3', cls=DhcpClient, mac='00:aa:00:00:00:03') |
| 44 | h4 = self.addHost('h4', cls=DhcpClient, mac='00:aa:00:00:00:04') |
| 45 | self.addLink(h1, s204) |
| 46 | self.addLink(h2, s204) |
| 47 | self.addLink(h3, s205) |
| 48 | self.addLink(h4, s205) |
| 49 | |
| 50 | # IPv6 Hosts |
Yi Tseng | 45ee692 | 2017-07-17 14:49:17 -0700 | [diff] [blame] | 51 | h1v6 = self.addHost('h1v6', cls=Dhcp6Client, mac='00:bb:00:00:00:01') |
| 52 | h2v6 = self.addHost('h2v6', cls=Dhcp6Client, mac='00:bb:00:00:00:02') |
| 53 | h3v6 = self.addHost('h3v6', cls=Dhcp6Client, mac='00:bb:00:00:00:03') |
| 54 | h4v6 = self.addHost('h4v6', cls=Dhcp6Client, mac='00:bb:00:00:00:04') |
Charles Chan | 6f149a9 | 2017-03-24 19:35:41 -0700 | [diff] [blame] | 55 | self.addLink(h1v6, s204) |
| 56 | self.addLink(h2v6, s204) |
| 57 | self.addLink(h3v6, s205) |
| 58 | self.addLink(h4v6, s205) |
| 59 | |
| 60 | # DHCP server |
| 61 | 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] | 62 | |
| 63 | # DHCPv6 server |
| 64 | dhcp6 = self.addHost('dhcp6', cls=Dhcp6Server, mac='00:99:66:00:00:01', ips=['2000::3fd/120'], gateway='2000::3ff') |
| 65 | |
| 66 | # Control plane switch (for DHCP servers) |
| 67 | cs1 = self.addSwitch('cs1', cls=OVSBridge) |
| 68 | self.addLink(cs1, s205) |
| 69 | self.addLink(dhcp, cs1) |
| 70 | self.addLink(dhcp6, cs1) |
Charles Chan | 6f149a9 | 2017-03-24 19:35:41 -0700 | [diff] [blame] | 71 | |
| 72 | # Control plane switch (for quagga fpm) |
| 73 | cs0 = self.addSwitch('cs0', cls=OVSBridge) |
| 74 | |
| 75 | # Control plane NAT (for quagga fpm) |
| 76 | nat = self.addHost('nat', cls=NAT, |
| 77 | ip='172.16.0.1/12', |
| 78 | subnet=str(ip_network(u'172.16.0.0/12')), inNamespace=False) |
| 79 | self.addLink(cs0, nat) |
| 80 | |
| 81 | # Internal Quagga bgp1 |
| 82 | intfs = {'bgp1-eth0': {'ipAddrs': ['10.0.1.2/24', '2000::102/120'], 'mac': '00:88:00:00:00:02'}, |
| 83 | 'bgp1-eth1': {'ipAddrs': ['172.16.0.2/12']}} |
| 84 | bgp1 = self.addHost('bgp1', cls=BgpRouter, |
| 85 | interfaces=intfs, |
| 86 | quaggaConfFile='./bgpdbgp1.conf', |
| 87 | zebraConfFile='./zebradbgp1.conf') |
| 88 | self.addLink(bgp1, s205) |
| 89 | self.addLink(bgp1, cs0) |
| 90 | |
| 91 | # External Quagga r1 |
| 92 | intfs = {'r1-eth0': {'ipAddrs': ['10.0.1.1/24', '2000::101/120'], 'mac': '00:88:00:00:00:01'}, |
| 93 | 'r1-eth1': {'ipAddrs': ['10.0.99.1/16']}, |
| 94 | 'r1-eth2': {'ipAddrs': ['2000::9901/120']}} |
| 95 | r1 = self.addHost('r1', cls=BgpRouter, |
| 96 | interfaces=intfs, |
| 97 | quaggaConfFile='./bgpdr1.conf') |
| 98 | self.addLink(r1, s205) |
| 99 | |
| 100 | # External IPv4 Host behind r1 |
| 101 | rh1 = self.addHost('rh1', cls=RoutedHost, ips=['10.0.99.2/24'], gateway='10.0.99.1') |
| 102 | self.addLink(r1, rh1) |
| 103 | |
| 104 | # External IPv6 Host behind r1 |
| 105 | rh1v6 = self.addHost('rh1v6', cls=RoutedHost, ips=['2000::9902/120'], gateway='2000::9901') |
| 106 | self.addLink(r1, rh1v6) |
| 107 | |
| 108 | topos = { 'trellis' : Trellis } |
| 109 | |
Charles Chan | 6f149a9 | 2017-03-24 19:35:41 -0700 | [diff] [blame] | 110 | if __name__ == "__main__": |
| 111 | setLogLevel('debug') |
| 112 | topo = Trellis() |
hwchiu | 0d696b3 | 2017-12-07 21:31:07 +0800 | [diff] [blame] | 113 | switch = partial(OVSSwitch, protocols='OpenFlow13') |
Ray Milkey | 1df260d | 2018-03-28 11:52:34 -0700 | [diff] [blame] | 114 | arguments = parse_trellis_args() |
| 115 | set_up_zebra_config(arguments.controllers) |
| 116 | net = get_mininet(arguments, topo, switch) |
Charles Chan | 6f149a9 | 2017-03-24 19:35:41 -0700 | [diff] [blame] | 117 | |
| 118 | net.start() |
| 119 | CLI(net) |
| 120 | net.stop() |