Yi Tseng | c467142 | 2017-11-01 18:22:53 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import os |
| 4 | import sys |
| 5 | import argparse |
| 6 | sys.path.append('..') |
| 7 | |
Yi Tseng | c467142 | 2017-11-01 18:22:53 -0700 | [diff] [blame] | 8 | from mininet.topo import Topo |
| 9 | from mininet.net import Mininet |
| 10 | from mininet.cli import CLI |
| 11 | from mininet.log import setLogLevel |
| 12 | from mininet.node import Host, RemoteController |
| 13 | from routinglib import RoutedHost |
Yi Tseng | 37c843d | 2018-05-26 00:55:12 +0800 | [diff] [blame] | 14 | from trellislib import TaggedRoutedHost |
Yi Tseng | c467142 | 2017-11-01 18:22:53 -0700 | [diff] [blame] | 15 | from bmv2 import ONOSBmv2Switch |
| 16 | |
| 17 | PIPECONF_ID = 'org.onosproject.pipelines.fabric' |
| 18 | |
| 19 | class Trellis( Topo ): |
| 20 | "Trellis basic topology" |
| 21 | |
| 22 | def __init__( self, *args, **kwargs ): |
| 23 | Topo.__init__( self, *args, **kwargs ) |
| 24 | |
| 25 | # Spines |
Yi Tseng | 915dff5 | 2018-04-12 17:08:43 +0000 | [diff] [blame] | 26 | s226 = self.addSwitch('s226', cls=ONOSBmv2Switch, grpcport=55226, pipeconf=PIPECONF_ID, portcfg=True) |
| 27 | s227 = self.addSwitch('s227', cls=ONOSBmv2Switch, grpcport=55227, pipeconf=PIPECONF_ID, portcfg=True) |
Yi Tseng | c467142 | 2017-11-01 18:22:53 -0700 | [diff] [blame] | 28 | |
| 29 | # Leaves |
Yi Tseng | 915dff5 | 2018-04-12 17:08:43 +0000 | [diff] [blame] | 30 | s204 = self.addSwitch('s204', cls=ONOSBmv2Switch, grpcport=55204, pipeconf=PIPECONF_ID, portcfg=True) |
| 31 | s205 = self.addSwitch('s205', cls=ONOSBmv2Switch, grpcport=55205, pipeconf=PIPECONF_ID, portcfg=True) |
Yi Tseng | c467142 | 2017-11-01 18:22:53 -0700 | [diff] [blame] | 32 | |
| 33 | # Switch Links |
| 34 | self.addLink(s226, s204) |
| 35 | self.addLink(s226, s205) |
| 36 | self.addLink(s227, s204) |
| 37 | self.addLink(s227, s205) |
| 38 | |
| 39 | # NOTE avoid using 10.0.1.0/24 which is the default subnet of quaggas |
| 40 | # NOTE avoid using 00:00:00:00:00:xx which is the default mac of host behind upstream router |
| 41 | # IPv4 Hosts |
Yi Tseng | 73555a5 | 2018-02-12 15:58:02 -0800 | [diff] [blame] | 42 | h1 = self.addHost('h1', cls=RoutedHost, mac='00:aa:00:00:00:01', ips=['10.0.2.1/24'], gateway='10.0.2.254') |
Yi Tseng | 37c843d | 2018-05-26 00:55:12 +0800 | [diff] [blame] | 43 | h2 = self.addHost('h2', cls=TaggedRoutedHost, mac='00:aa:00:00:00:02', ips=['10.0.2.2/24'], gateway='10.0.2.254', vlan=10) |
Yi Tseng | 73555a5 | 2018-02-12 15:58:02 -0800 | [diff] [blame] | 44 | h3 = self.addHost('h3', cls=RoutedHost, mac='00:aa:00:00:00:03', ips=['10.0.3.1/24'], gateway='10.0.3.254') |
Yi Tseng | 37c843d | 2018-05-26 00:55:12 +0800 | [diff] [blame] | 45 | h4 = self.addHost('h4', cls=TaggedRoutedHost, mac='00:aa:00:00:00:04', ips=['10.0.3.2/24'], gateway='10.0.3.254', vlan=20) |
Yi Tseng | c467142 | 2017-11-01 18:22:53 -0700 | [diff] [blame] | 46 | self.addLink(h1, s204) |
| 47 | self.addLink(h2, s204) |
| 48 | self.addLink(h3, s205) |
| 49 | self.addLink(h4, s205) |
| 50 | |
| 51 | topos = { 'trellis' : Trellis } |
| 52 | |
| 53 | def main(args): |
| 54 | topo = Trellis() |
| 55 | controller = RemoteController('c0', ip=args.onos_ip) |
| 56 | |
| 57 | net = Mininet(topo=topo, controller=None) |
| 58 | net.addController(controller) |
| 59 | |
| 60 | net.start() |
| 61 | CLI(net) |
| 62 | net.stop() |
| 63 | |
| 64 | if __name__ == "__main__": |
| 65 | parser = argparse.ArgumentParser( |
| 66 | description='BMv2 mininet demo script (2 by 2 fabric)') |
| 67 | parser.add_argument('--onos-ip', help='ONOS-BMv2 controller IP address', |
| 68 | type=str, action="store", required=True) |
| 69 | args = parser.parse_args() |
| 70 | setLogLevel('debug') |
| 71 | |
| 72 | main(args) |