blob: 2e9d8bc904a14a7097d561590e625f21abf2ef32 [file] [log] [blame]
Charles Chan6f149a92017-03-24 19:35:41 -07001#!/usr/bin/python
2
3import sys
4sys.path.append('..')
5from mininet.topo import Topo
6from mininet.net import Mininet
7from mininet.cli import CLI
8from mininet.log import setLogLevel
hwchiu0d696b32017-12-07 21:31:07 +08009from mininet.node import RemoteController, OVSBridge, Host, OVSSwitch
Charles Chan6f149a92017-03-24 19:35:41 -070010from mininet.nodelib import NAT
11from ipaddress import ip_network
12from routinglib import BgpRouter
Yi Tseng45ee6922017-07-17 14:49:17 -070013from routinglib import RoutedHost, RoutedHost6
14from trellislib import DhcpClient, Dhcp6Client, DhcpRelay, DhcpServer, Dhcp6Server
hwchiu0d696b32017-12-07 21:31:07 +080015from functools import partial
Charles Chan6f149a92017-03-24 19:35:41 -070016
17class Trellis( Topo ):
18 "Trellis basic topology"
19
20 def __init__( self, *args, **kwargs ):
21 Topo.__init__( self, *args, **kwargs )
22
23 # Spines
24 s226 = self.addSwitch('s226', dpid='226')
25 s227 = self.addSwitch('s227', dpid='227')
26
27 # Leaves
28 s204 = self.addSwitch('s204', dpid='204')
29 s205 = self.addSwitch('s205', dpid='205')
30
31 # Switch Links
32 self.addLink(s226, s204)
33 self.addLink(s226, s205)
34 self.addLink(s227, s204)
35 self.addLink(s227, s205)
36
37 # NOTE avoid using 10.0.1.0/24 which is the default subnet of quaggas
38 # NOTE avoid using 00:00:00:00:00:xx which is the default mac of host behind upstream router
39 # IPv4 Hosts
40 h1 = self.addHost('h1', cls=DhcpClient, mac='00:aa:00:00:00:01')
41 h2 = self.addHost('h2', cls=DhcpClient, mac='00:aa:00:00:00:02')
42 h3 = self.addHost('h3', cls=DhcpClient, mac='00:aa:00:00:00:03')
43 h4 = self.addHost('h4', cls=DhcpClient, mac='00:aa:00:00:00:04')
44 self.addLink(h1, s204)
45 self.addLink(h2, s204)
46 self.addLink(h3, s205)
47 self.addLink(h4, s205)
48
49 # IPv6 Hosts
Yi Tseng45ee6922017-07-17 14:49:17 -070050 h1v6 = self.addHost('h1v6', cls=Dhcp6Client, mac='00:bb:00:00:00:01')
51 h2v6 = self.addHost('h2v6', cls=Dhcp6Client, mac='00:bb:00:00:00:02')
52 h3v6 = self.addHost('h3v6', cls=Dhcp6Client, mac='00:bb:00:00:00:03')
53 h4v6 = self.addHost('h4v6', cls=Dhcp6Client, mac='00:bb:00:00:00:04')
Charles Chan6f149a92017-03-24 19:35:41 -070054 self.addLink(h1v6, s204)
55 self.addLink(h2v6, s204)
56 self.addLink(h3v6, s205)
57 self.addLink(h4v6, s205)
58
59 # DHCP server
60 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 Tseng45ee6922017-07-17 14:49:17 -070061
62 # DHCPv6 server
63 dhcp6 = self.addHost('dhcp6', cls=Dhcp6Server, mac='00:99:66:00:00:01', ips=['2000::3fd/120'], gateway='2000::3ff')
64
65 # Control plane switch (for DHCP servers)
66 cs1 = self.addSwitch('cs1', cls=OVSBridge)
67 self.addLink(cs1, s205)
68 self.addLink(dhcp, cs1)
69 self.addLink(dhcp6, cs1)
Charles Chan6f149a92017-03-24 19:35:41 -070070
71 # Control plane switch (for quagga fpm)
72 cs0 = self.addSwitch('cs0', cls=OVSBridge)
73
74 # Control plane NAT (for quagga fpm)
75 nat = self.addHost('nat', cls=NAT,
76 ip='172.16.0.1/12',
77 subnet=str(ip_network(u'172.16.0.0/12')), inNamespace=False)
78 self.addLink(cs0, nat)
79
80 # Internal Quagga bgp1
81 intfs = {'bgp1-eth0': {'ipAddrs': ['10.0.1.2/24', '2000::102/120'], 'mac': '00:88:00:00:00:02'},
82 'bgp1-eth1': {'ipAddrs': ['172.16.0.2/12']}}
83 bgp1 = self.addHost('bgp1', cls=BgpRouter,
84 interfaces=intfs,
85 quaggaConfFile='./bgpdbgp1.conf',
86 zebraConfFile='./zebradbgp1.conf')
87 self.addLink(bgp1, s205)
88 self.addLink(bgp1, cs0)
89
90 # External Quagga r1
91 intfs = {'r1-eth0': {'ipAddrs': ['10.0.1.1/24', '2000::101/120'], 'mac': '00:88:00:00:00:01'},
92 'r1-eth1': {'ipAddrs': ['10.0.99.1/16']},
93 'r1-eth2': {'ipAddrs': ['2000::9901/120']}}
94 r1 = self.addHost('r1', cls=BgpRouter,
95 interfaces=intfs,
96 quaggaConfFile='./bgpdr1.conf')
97 self.addLink(r1, s205)
98
99 # External IPv4 Host behind r1
100 rh1 = self.addHost('rh1', cls=RoutedHost, ips=['10.0.99.2/24'], gateway='10.0.99.1')
101 self.addLink(r1, rh1)
102
103 # External IPv6 Host behind r1
104 rh1v6 = self.addHost('rh1v6', cls=RoutedHost, ips=['2000::9902/120'], gateway='2000::9901')
105 self.addLink(r1, rh1v6)
106
107topos = { 'trellis' : Trellis }
108
Charles Chan6f149a92017-03-24 19:35:41 -0700109if __name__ == "__main__":
110 setLogLevel('debug')
111 topo = Trellis()
112
hwchiu0d696b32017-12-07 21:31:07 +0800113 switch = partial(OVSSwitch, protocols='OpenFlow13')
114 net = Mininet(topo=topo, controller=None, switch=switch)
Charles Chan6f149a92017-03-24 19:35:41 -0700115 net.addController(RemoteController('c0', ip='192.168.56.11'))
116 net.addController(RemoteController('c1', ip='192.168.56.12'))
117 net.addController(RemoteController('c2', ip='192.168.56.13'))
118
119 net.start()
120 CLI(net)
121 net.stop()