Admin | c0ed119 | 2015-10-10 14:18:26 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame] | 3 | import sys |
| 4 | |
Admin | c0ed119 | 2015-10-10 14:18:26 -0700 | [diff] [blame] | 5 | from mininet.topo import Topo |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame] | 6 | from mininet.node import RemoteController, UserSwitch |
Admin | c0ed119 | 2015-10-10 14:18:26 -0700 | [diff] [blame] | 7 | from mininet.net import Mininet |
| 8 | from mininet.util import irange |
| 9 | from mininet.cli import CLI |
| 10 | from mininet.log import setLogLevel |
| 11 | |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame] | 12 | from optparse import OptionParser |
| 13 | |
| 14 | |
Admin | c0ed119 | 2015-10-10 14:18:26 -0700 | [diff] [blame] | 15 | class OltTopo( Topo ): |
| 16 | "Single switch with OLT port 129 and configurable number of ONU ports" |
| 17 | |
| 18 | def build( self, k=1, **_opts ): |
| 19 | "k: number of onu" |
| 20 | self.k = k |
| 21 | switch = self.addSwitch( 's1' ) |
| 22 | for h in irange( 1, k ): |
| 23 | host = self.addHost( 'h%s' % h, inNamespace=False ) |
| 24 | self.addLink( host, switch ) |
| 25 | |
| 26 | olt_port = self.addHost( 'h129', inNamespace=False ) |
| 27 | self.addLink( olt_port, switch, port2=129 ) |
| 28 | |
| 29 | if __name__ == '__main__': |
Admin | c0ed119 | 2015-10-10 14:18:26 -0700 | [diff] [blame] | 30 | |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame] | 31 | parser = OptionParser() |
| 32 | parser.add_option("-u", "--user-switch", dest="user_switch", action="store_true", |
| 33 | default=False, help="use given user mode switch (CPqD) or mininet") |
| 34 | (options, args) = parser.parse_args() |
| 35 | |
| 36 | kargs = {} |
| 37 | |
| 38 | if options.user_switch: |
| 39 | kargs['switch'] = UserSwitch |
| 40 | |
| 41 | setLogLevel('debug') |
| 42 | |
| 43 | topo = OltTopo() |
| 44 | topo.build(k=2) |
| 45 | |
| 46 | net = Mininet( topo=topo, controller=RemoteController, **kargs ) |
Admin | c0ed119 | 2015-10-10 14:18:26 -0700 | [diff] [blame] | 47 | |
| 48 | net.start() |
| 49 | |
| 50 | CLI( net ) |
| 51 | |
| 52 | net.stop() |