blob: fbc1c7f3620d45b092298e04d2b08a8b2d5f9a98 [file] [log] [blame]
Charles Chanebfcc912017-04-24 12:39:52 -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 Chanebfcc912017-04-24 12:39:52 -070010from mininet.nodelib import NAT
11from ipaddress import ip_network
12from routinglib import BgpRouter
13from routinglib import RoutedHost
Yi Tseng9e332d82017-07-28 17:52:21 -070014from trellislib import DhcpClient, DhcpServer, DhcpRelay
Ray Milkey1df260d2018-03-28 11:52:34 -070015from trellislib import get_mininet, parse_trellis_args, set_up_zebra_config
hwchiu0d696b32017-12-07 21:31:07 +080016from functools import partial
Charles Chanebfcc912017-04-24 12:39:52 -070017
18class 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
Yi Tseng9e332d82017-07-28 17:52:21 -070038 intfs = {
39 'relay-eth0': {
40 'ipAddrs': ['10.0.4.254/24']
41 },
42 'relay-eth1': {
43 'ipAddrs': ['10.0.2.100/24']
44 }
45 }
46 dhcpRelay = self.addHost('relay', cls=DhcpRelay, serverIp='10.0.99.3',
47 gateway='10.0.2.254', interfaces=intfs)
48
Charles Chanebfcc912017-04-24 12:39:52 -070049 # NOTE avoid using 10.0.1.0/24 which is the default subnet of quaggas
50 # NOTE avoid using 00:00:00:00:00:xx which is the default mac of host behind upstream router
51 # IPv4 Hosts
52 h1 = self.addHost('h1', cls=DhcpClient, mac='00:aa:00:00:00:01')
53 h2 = self.addHost('h2', cls=DhcpClient, mac='00:aa:00:00:00:02')
54 h3 = self.addHost('h3', cls=DhcpClient, mac='00:aa:00:00:00:03')
55 h4 = self.addHost('h4', cls=DhcpClient, mac='00:aa:00:00:00:04')
Yi Tseng9e332d82017-07-28 17:52:21 -070056 self.addLink(h1, dhcpRelay)
57 self.addLink(dhcpRelay, s204)
Charles Chanebfcc912017-04-24 12:39:52 -070058 self.addLink(h2, s204)
59 self.addLink(h3, s205)
60 self.addLink(h4, s205)
61
62 # IPv6 Hosts
63 h1v6 = self.addHost('h1v6', cls=RoutedHost, mac='00:bb:00:00:00:01', ips=['2000::201/120'], gateway='2000::2ff')
64 h2v6 = self.addHost('h2v6', cls=RoutedHost, mac='00:bb:00:00:00:02', ips=['2000::202/120'], gateway='2000::2ff')
65 h3v6 = self.addHost('h3v6', cls=RoutedHost, mac='00:bb:00:00:00:03', ips=['2000::301/120'], gateway='2000::3ff')
66 h4v6 = self.addHost('h4v6', cls=RoutedHost, mac='00:bb:00:00:00:04', ips=['2000::302/120'], gateway='2000::3ff')
67 self.addLink(h1v6, s204)
68 self.addLink(h2v6, s204)
69 self.addLink(h3v6, s205)
70 self.addLink(h4v6, s205)
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 switch behind r1
101 rs0 = self.addSwitch('rs0', cls=OVSBridge)
102 self.addLink(r1, rs0)
103
104 # External IPv4 Host behind r1
105 rh1 = self.addHost('rh1', cls=RoutedHost, ips=['10.0.99.2/24'], gateway='10.0.99.1')
106 self.addLink(rs0, rh1)
107
108 # External DHCP server behind r1
109 dhcp = self.addHost('dhcp', cls=DhcpServer, mac='00:99:00:00:00:01', ips=['10.0.99.3/24'], gateway='10.0.99.1')
110 self.addLink(rs0, dhcp)
111
112 # External IPv6 Host behind r1
113 rh1v6 = self.addHost('rh1v6', cls=RoutedHost, ips=['2000::9902/120'], gateway='2000::9901')
114 self.addLink(r1, rh1v6)
115
116topos = { 'trellis' : Trellis }
117
Charles Chanebfcc912017-04-24 12:39:52 -0700118if __name__ == "__main__":
119 setLogLevel('debug')
120 topo = Trellis()
hwchiu0d696b32017-12-07 21:31:07 +0800121 switch = partial(OVSSwitch, protocols='OpenFlow13')
Ray Milkey1df260d2018-03-28 11:52:34 -0700122 arguments = parse_trellis_args()
123 set_up_zebra_config(arguments.controllers)
124 net = get_mininet(arguments, topo, switch)
Charles Chanebfcc912017-04-24 12:39:52 -0700125
126 net.start()
127 CLI(net)
128 net.stop()