File: run_mininet.py

package info (click to toggle)
python-os-ken 4.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,396 kB
  • sloc: python: 100,059; erlang: 14,517; ansic: 594; sh: 338; makefile: 136
file content (52 lines) | stat: -rwxr-xr-x 1,410 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3

import sys

from mininet.cli import CLI
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.node import OVSSwitch
from mininet.node import UserSwitch

from oslo_config import cfg
from os_ken import version
from os_ken.ofproto.ofproto_common import OFP_TCP_PORT


if '__main__' == __name__:

    opts = [
        cfg.StrOpt('switch', default='ovs',
                   help='test switch [ovs|cpqd]'),
        cfg.StrOpt('protocols', default='OpenFlow13',
                   help='"protocols" option for ovs-vsctl (e.g. OpenFlow13)')
    ]
    conf = cfg.ConfigOpts()
    conf.register_cli_opts(opts)
    conf(project='os_ken', version='run_mininet.py %s' % version)
    conf(sys.argv[1:])
    switch_type = {'ovs': OVSSwitch, 'cpqd': UserSwitch}
    switch = switch_type.get(conf.switch, None)
    if switch is None:
        raise ValueError('Invalid switch type. [%s]', conf.switch)

    net = Mininet(switch=switch, controller=RemoteController)

    c0 = net.addController('c0', port=OFP_TCP_PORT)

    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')

    net.addLink(s1, s2)
    net.addLink(s1, s2)
    net.addLink(s1, s2)

    net.start()

    if conf.switch == 'ovs':
        s1.cmd('ovs-vsctl set Bridge s1 protocols=%s' % conf.protocols)
        s2.cmd('ovs-vsctl set Bridge s2 protocols=%s' % conf.protocols)

    CLI(net)

    net.stop()