| #!/usr/bin/python |
| |
| import sys |
| |
| from mininet.topo import Topo |
| from mininet.node import RemoteController, UserSwitch |
| from mininet.net import Mininet |
| from mininet.util import irange |
| from mininet.cli import CLI |
| from mininet.log import setLogLevel |
| |
| from optparse import OptionParser |
| |
| |
| class OltTopo( Topo ): |
| "Single switch with OLT port 129 and configurable number of ONU ports" |
| |
| def build( self, k=1, **_opts ): |
| "k: number of onu" |
| self.k = k |
| switch = self.addSwitch( 's1' ) |
| for h in irange( 1, k ): |
| host = self.addHost( 'h%s' % h, inNamespace=False ) |
| self.addLink( host, switch ) |
| |
| olt_port = self.addHost( 'h129', inNamespace=False ) |
| self.addLink( olt_port, switch, port2=129 ) |
| |
| if __name__ == '__main__': |
| |
| parser = OptionParser() |
| parser.add_option("-u", "--user-switch", dest="user_switch", action="store_true", |
| default=False, help="use given user mode switch (CPqD) or mininet") |
| (options, args) = parser.parse_args() |
| |
| kargs = {} |
| |
| if options.user_switch: |
| kargs['switch'] = UserSwitch |
| |
| setLogLevel('debug') |
| |
| topo = OltTopo() |
| topo.build(k=2) |
| |
| net = Mininet( topo=topo, controller=RemoteController, **kargs ) |
| |
| net.start() |
| |
| CLI( net ) |
| |
| net.stop() |