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 | |
| 8 | if 'ONOS_ROOT' not in os.environ: |
| 9 | print "Environment var $ONOS_ROOT not set" |
| 10 | exit() |
| 11 | else: |
| 12 | ONOS_ROOT = os.environ["ONOS_ROOT"] |
| 13 | sys.path.append(ONOS_ROOT + "/tools/dev/mininet") |
| 14 | |
| 15 | from mininet.topo import Topo |
| 16 | from mininet.net import Mininet |
| 17 | from mininet.cli import CLI |
| 18 | from mininet.log import setLogLevel |
| 19 | from mininet.node import Host, RemoteController |
| 20 | from routinglib import RoutedHost |
| 21 | from bmv2 import ONOSBmv2Switch |
| 22 | |
| 23 | PIPECONF_ID = 'org.onosproject.pipelines.fabric' |
| 24 | |
| 25 | class Trellis( Topo ): |
| 26 | "Trellis basic topology" |
| 27 | |
| 28 | def __init__( self, *args, **kwargs ): |
| 29 | Topo.__init__( self, *args, **kwargs ) |
| 30 | |
| 31 | # Spines |
| 32 | s226 = self.addSwitch('s226', cls=ONOSBmv2Switch, deviceId='226', grpcPort=55226, pipeconfId=PIPECONF_ID, netcfgDelay=0.5) |
| 33 | s227 = self.addSwitch('s227', cls=ONOSBmv2Switch, deviceId='227', grpcPort=55227, pipeconfId=PIPECONF_ID, netcfgDelay=0.5) |
| 34 | |
| 35 | # Leaves |
| 36 | s204 = self.addSwitch('s204', cls=ONOSBmv2Switch, deviceId='204', grpcPort=55204, pipeconfId=PIPECONF_ID, netcfgDelay=0.5) |
| 37 | s205 = self.addSwitch('s205', cls=ONOSBmv2Switch, deviceId='205', grpcPort=55205, pipeconfId=PIPECONF_ID, netcfgDelay=0.5) |
| 38 | |
| 39 | # Switch Links |
| 40 | self.addLink(s226, s204) |
| 41 | self.addLink(s226, s205) |
| 42 | self.addLink(s227, s204) |
| 43 | self.addLink(s227, s205) |
| 44 | |
| 45 | # NOTE avoid using 10.0.1.0/24 which is the default subnet of quaggas |
| 46 | # NOTE avoid using 00:00:00:00:00:xx which is the default mac of host behind upstream router |
| 47 | # IPv4 Hosts |
| 48 | h1 = self.addHost('h1', cls=RoutedHost, mac='00:aa:00:00:00:01', ips=['10.0.10.1/24'], gateway='10.0.10.254') |
| 49 | h2 = self.addHost('h2', cls=RoutedHost, mac='00:aa:00:00:00:02', ips=['10.0.10.2/24'], gateway='10.0.10.254') |
| 50 | h3 = self.addHost('h3', cls=RoutedHost, mac='00:aa:00:00:00:03', ips=['10.0.20.1/24'], gateway='10.0.20.254') |
| 51 | h4 = self.addHost('h4', cls=RoutedHost, mac='00:aa:00:00:00:04', ips=['10.0.20.2/24'], gateway='10.0.20.254') |
| 52 | self.addLink(h1, s204) |
| 53 | self.addLink(h2, s204) |
| 54 | self.addLink(h3, s205) |
| 55 | self.addLink(h4, s205) |
| 56 | |
| 57 | topos = { 'trellis' : Trellis } |
| 58 | |
| 59 | def main(args): |
| 60 | topo = Trellis() |
| 61 | controller = RemoteController('c0', ip=args.onos_ip) |
| 62 | |
| 63 | net = Mininet(topo=topo, controller=None) |
| 64 | net.addController(controller) |
| 65 | |
| 66 | net.start() |
| 67 | CLI(net) |
| 68 | net.stop() |
| 69 | |
| 70 | if __name__ == "__main__": |
| 71 | parser = argparse.ArgumentParser( |
| 72 | description='BMv2 mininet demo script (2 by 2 fabric)') |
| 73 | parser.add_argument('--onos-ip', help='ONOS-BMv2 controller IP address', |
| 74 | type=str, action="store", required=True) |
| 75 | args = parser.parse_args() |
| 76 | setLogLevel('debug') |
| 77 | |
| 78 | main(args) |