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 |
hwchiu | 0d696b3 | 2017-12-07 21:31:07 +0800 | [diff] [blame^] | 16 | from functools import partial |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -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=TaggedDhcpClient, mac='00:aa:00:00:00:02', vlan=20) |
| 43 | 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] | 44 | h4 = self.addHost('h4', cls=DhcpClient, mac='00:aa:00:00:00:04') |
| 45 | # In order to emulate tagged Quagga VM in h4 |
| 46 | h4ovs = self.addSwitch('h4ovs', cls=OVSBridge) |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 47 | self.addLink(h1, s204) |
| 48 | self.addLink(h2, s204) |
| 49 | self.addLink(h3, s205) |
Charles Chan | 279fabf | 2017-04-24 15:33:14 -0700 | [diff] [blame] | 50 | self.addLink(h4ovs, s205) |
| 51 | self.addLink(h4ovs, h4) |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 52 | |
| 53 | # IPv6 Hosts |
| 54 | h1v6 = self.addHost('h1v6', cls=RoutedHost, mac='00:bb:00:00:00:01', ips=['2000::201/120'], gateway='2000::2ff') |
| 55 | h2v6 = self.addHost('h2v6', cls=RoutedHost, mac='00:bb:00:00:00:02', ips=['2000::202/120'], gateway='2000::2ff') |
| 56 | h3v6 = self.addHost('h3v6', cls=RoutedHost, mac='00:bb:00:00:00:03', ips=['2000::301/120'], gateway='2000::3ff') |
| 57 | h4v6 = self.addHost('h4v6', cls=RoutedHost, mac='00:bb:00:00:00:04', ips=['2000::302/120'], gateway='2000::3ff') |
| 58 | self.addLink(h1v6, s204) |
| 59 | self.addLink(h2v6, s204) |
| 60 | self.addLink(h3v6, s205) |
| 61 | self.addLink(h4v6, s205) |
| 62 | |
| 63 | # DHCP server |
| 64 | 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) |
| 65 | self.addLink(dhcp, s205) |
| 66 | |
| 67 | # Control plane switch (for quagga fpm) |
| 68 | cs0 = self.addSwitch('cs0', cls=OVSBridge) |
| 69 | |
| 70 | # Control plane NAT (for quagga fpm) |
| 71 | nat = self.addHost('nat', cls=NAT, |
| 72 | ip='172.16.0.1/12', |
| 73 | subnet=str(ip_network(u'172.16.0.0/12')), inNamespace=False) |
| 74 | self.addLink(cs0, nat) |
| 75 | |
| 76 | # Internal Quagga bgp1 |
Charles Chan | 279fabf | 2017-04-24 15:33:14 -0700 | [diff] [blame] | 77 | intfs = {'bgp1-eth0': {'ipAddrs': ['10.0.1.2/24', '2000::102/120'], 'mac': '00:88:00:00:00:02', 'vlan': '10'}, |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 78 | 'bgp1-eth1': {'ipAddrs': ['172.16.0.2/12']}} |
| 79 | bgp1 = self.addHost('bgp1', cls=BgpRouter, |
| 80 | interfaces=intfs, |
| 81 | quaggaConfFile='./bgpdbgp1.conf', |
| 82 | zebraConfFile='./zebradbgp1.conf') |
Charles Chan | 279fabf | 2017-04-24 15:33:14 -0700 | [diff] [blame] | 83 | self.addLink(bgp1, h4ovs) |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 84 | self.addLink(bgp1, cs0) |
| 85 | |
| 86 | # External Quagga r1 |
| 87 | intfs = {'r1-eth0': {'ipAddrs': ['10.0.1.1/24', '2000::101/120'], 'mac': '00:88:00:00:00:01'}, |
| 88 | 'r1-eth1': {'ipAddrs': ['10.0.99.1/16']}, |
| 89 | 'r1-eth2': {'ipAddrs': ['2000::9901/120']}} |
| 90 | r1 = self.addHost('r1', cls=BgpRouter, |
| 91 | interfaces=intfs, |
| 92 | quaggaConfFile='./bgpdr1.conf') |
| 93 | self.addLink(r1, s205) |
| 94 | |
| 95 | # External IPv4 Host behind r1 |
| 96 | rh1 = self.addHost('rh1', cls=RoutedHost, ips=['10.0.99.2/24'], gateway='10.0.99.1') |
| 97 | self.addLink(r1, rh1) |
| 98 | |
| 99 | # External IPv6 Host behind r1 |
| 100 | rh1v6 = self.addHost('rh1v6', cls=RoutedHost, ips=['2000::9902/120'], gateway='2000::9901') |
| 101 | self.addLink(r1, rh1v6) |
| 102 | |
| 103 | topos = { 'trellis' : Trellis } |
| 104 | |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 105 | if __name__ == "__main__": |
| 106 | setLogLevel('debug') |
| 107 | topo = Trellis() |
| 108 | |
hwchiu | 0d696b3 | 2017-12-07 21:31:07 +0800 | [diff] [blame^] | 109 | switch = partial(OVSSwitch, protocols='OpenFlow13') |
| 110 | net = Mininet(topo=topo, controller=None, switch=switch) |
Charles Chan | 6e29b32 | 2017-04-11 11:10:31 -0700 | [diff] [blame] | 111 | net.addController(RemoteController('c0', ip='192.168.56.11')) |
| 112 | net.addController(RemoteController('c1', ip='192.168.56.12')) |
| 113 | net.addController(RemoteController('c2', ip='192.168.56.13')) |
| 114 | |
| 115 | net.start() |
| 116 | CLI(net) |
| 117 | net.stop() |