blob: 29ce6847e2e799c31ed71ae42bc9b53faff2b4b8 [file] [log] [blame]
Charles Chan6f149a92017-03-24 19:35:41 -07001#!/usr/bin/python
2
3import sys
Andrea Campanella6adf0022018-06-19 16:24:17 +02004from time import sleep
5
Charles Chan6f149a92017-03-24 19:35:41 -07006sys.path.append('..')
7from mininet.topo import Topo
8from mininet.net import Mininet
9from mininet.cli import CLI
10from mininet.log import setLogLevel
hwchiu0d696b32017-12-07 21:31:07 +080011from mininet.node import RemoteController, OVSBridge, Host, OVSSwitch
Charles Chan6f149a92017-03-24 19:35:41 -070012from mininet.nodelib import NAT
13from ipaddress import ip_network
14from routinglib import BgpRouter
Yi Tseng45ee6922017-07-17 14:49:17 -070015from routinglib import RoutedHost, RoutedHost6
Andrea Campanella6adf0022018-06-19 16:24:17 +020016from trellislib import DhcpClient, Dhcp6Client, DhcpRelay, DhcpServer, Dhcp6Server, DoubleTaggedRoutedHost
Ray Milkey1df260d2018-03-28 11:52:34 -070017from trellislib import get_mininet, parse_trellis_args, set_up_zebra_config
hwchiu0d696b32017-12-07 21:31:07 +080018from functools import partial
Charles Chan6f149a92017-03-24 19:35:41 -070019
20class Trellis( Topo ):
21 "Trellis basic topology"
22
23 def __init__( self, *args, **kwargs ):
24 Topo.__init__( self, *args, **kwargs )
25
26 # Spines
27 s226 = self.addSwitch('s226', dpid='226')
28 s227 = self.addSwitch('s227', dpid='227')
29
30 # Leaves
31 s204 = self.addSwitch('s204', dpid='204')
32 s205 = self.addSwitch('s205', dpid='205')
33
34 # Switch Links
35 self.addLink(s226, s204)
36 self.addLink(s226, s205)
37 self.addLink(s227, s204)
38 self.addLink(s227, s205)
39
40 # NOTE avoid using 10.0.1.0/24 which is the default subnet of quaggas
41 # NOTE avoid using 00:00:00:00:00:xx which is the default mac of host behind upstream router
42 # IPv4 Hosts
43 h1 = self.addHost('h1', cls=DhcpClient, mac='00:aa:00:00:00:01')
44 h2 = self.addHost('h2', cls=DhcpClient, mac='00:aa:00:00:00:02')
45 h3 = self.addHost('h3', cls=DhcpClient, mac='00:aa:00:00:00:03')
46 h4 = self.addHost('h4', cls=DhcpClient, mac='00:aa:00:00:00:04')
Andrea Campanella6adf0022018-06-19 16:24:17 +020047 dth5 = self.addHost('dth5', cls=DoubleTaggedRoutedHost, mac='00:aa:00:00:00:05', ips=['10.0.2.3/24'], gateway='10.0.2.254', outerVlan=100, innerVlan=200)
Charles Chan6f149a92017-03-24 19:35:41 -070048 self.addLink(h1, s204)
49 self.addLink(h2, s204)
50 self.addLink(h3, s205)
51 self.addLink(h4, s205)
Andrea Campanella6adf0022018-06-19 16:24:17 +020052 self.addLink(dth5, s204)
Charles Chan6f149a92017-03-24 19:35:41 -070053
54 # IPv6 Hosts
Yi Tseng45ee6922017-07-17 14:49:17 -070055 h1v6 = self.addHost('h1v6', cls=Dhcp6Client, mac='00:bb:00:00:00:01')
56 h2v6 = self.addHost('h2v6', cls=Dhcp6Client, mac='00:bb:00:00:00:02')
57 h3v6 = self.addHost('h3v6', cls=Dhcp6Client, mac='00:bb:00:00:00:03')
58 h4v6 = self.addHost('h4v6', cls=Dhcp6Client, mac='00:bb:00:00:00:04')
Charles Chan6f149a92017-03-24 19:35:41 -070059 self.addLink(h1v6, s204)
60 self.addLink(h2v6, s204)
61 self.addLink(h3v6, s205)
62 self.addLink(h4v6, s205)
63
64 # DHCP server
65 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 -070066
67 # DHCPv6 server
68 dhcp6 = self.addHost('dhcp6', cls=Dhcp6Server, mac='00:99:66:00:00:01', ips=['2000::3fd/120'], gateway='2000::3ff')
69
70 # Control plane switch (for DHCP servers)
71 cs1 = self.addSwitch('cs1', cls=OVSBridge)
72 self.addLink(cs1, s205)
73 self.addLink(dhcp, cs1)
74 self.addLink(dhcp6, cs1)
Charles Chan6f149a92017-03-24 19:35:41 -070075
76 # Control plane switch (for quagga fpm)
77 cs0 = self.addSwitch('cs0', cls=OVSBridge)
78
79 # Control plane NAT (for quagga fpm)
80 nat = self.addHost('nat', cls=NAT,
81 ip='172.16.0.1/12',
82 subnet=str(ip_network(u'172.16.0.0/12')), inNamespace=False)
83 self.addLink(cs0, nat)
84
85 # Internal Quagga bgp1
86 intfs = {'bgp1-eth0': {'ipAddrs': ['10.0.1.2/24', '2000::102/120'], 'mac': '00:88:00:00:00:02'},
87 'bgp1-eth1': {'ipAddrs': ['172.16.0.2/12']}}
88 bgp1 = self.addHost('bgp1', cls=BgpRouter,
89 interfaces=intfs,
90 quaggaConfFile='./bgpdbgp1.conf',
91 zebraConfFile='./zebradbgp1.conf')
92 self.addLink(bgp1, s205)
93 self.addLink(bgp1, cs0)
94
95 # External Quagga r1
96 intfs = {'r1-eth0': {'ipAddrs': ['10.0.1.1/24', '2000::101/120'], 'mac': '00:88:00:00:00:01'},
97 'r1-eth1': {'ipAddrs': ['10.0.99.1/16']},
98 'r1-eth2': {'ipAddrs': ['2000::9901/120']}}
99 r1 = self.addHost('r1', cls=BgpRouter,
100 interfaces=intfs,
101 quaggaConfFile='./bgpdr1.conf')
102 self.addLink(r1, s205)
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(r1, rh1)
107
108 # External IPv6 Host behind r1
109 rh1v6 = self.addHost('rh1v6', cls=RoutedHost, ips=['2000::9902/120'], gateway='2000::9901')
110 self.addLink(r1, rh1v6)
111
112topos = { 'trellis' : Trellis }
113
Charles Chan6f149a92017-03-24 19:35:41 -0700114if __name__ == "__main__":
115 setLogLevel('debug')
116 topo = Trellis()
hwchiu0d696b32017-12-07 21:31:07 +0800117 switch = partial(OVSSwitch, protocols='OpenFlow13')
Ray Milkey1df260d2018-03-28 11:52:34 -0700118 arguments = parse_trellis_args()
119 set_up_zebra_config(arguments.controllers)
120 net = get_mininet(arguments, topo, switch)
Charles Chan6f149a92017-03-24 19:35:41 -0700121
122 net.start()
Andrea Campanella6adf0022018-06-19 16:24:17 +0200123 sleep(3)
124 print 'ping %s' % net.get('h1').IP()
125 net.get('dth5').cmd('ping -c 1 %s'% net.get('h1').IP())
Charles Chan6f149a92017-03-24 19:35:41 -0700126 CLI(net)
127 net.stop()