2 from mininet.topo import Topo
3 from mininet.node import RemoteController
4 from mininet.net import Mininet
5 from mininet.util import dumpNodeConnections
6 from mininet.log import setLogLevel
7 from mininet.node import Node
11 from subprocess import call
12 from subprocess import check_output
14 def addController(sw, ip):
15 call(['ovs-vsctl', 'set-controller', sw, 'tcp:%s:6653' % ip ])
17 def addSwitch(net, name, dpid=None):
18 switch = net.addSwitch(name, dpid=dpid)
21 def addHost(net, switch, name, ip, mac):
22 host = net.addHost(name, ip=ip, mac=mac)
23 net.addLink(host, switch)
25 def setOFVersion(sw, version='OpenFlow13,OpenFlow12,OpenFlow10'):
26 call(['ovs-vsctl', 'set', 'bridge', sw, 'protocols={}'.format(version)])
28 def addTunnel(sw, sourceIp=None):
29 ifaceName = '{}_vxlan0'.format(sw)
30 cmd = ['ovs-vsctl', 'add-port', sw, ifaceName,
31 '--', 'set', 'Interface', ifaceName,
33 'options:remote_ip=flow',
35 if sourceIp is not None:
36 cmd.append('options:source_ip={}'.format(sourceIp))
39 #ovs-ofctl dump-ports-desc s1 -OOpenFlow13
41 def startMininet(switches, hosts, contIP='127.0.0.1'):
44 net = Mininet(controller=None,
52 swobj = addSwitch(net, sw['name'])
53 swobjs[sw['name']] = swobj
54 swports[sw['name']] = 0;
56 if host['switch'] not in swobjs:
58 sw = swobjs[host['switch']]
59 swports[host['switch']] += 1;
60 port = swports[host['switch']]
61 addHost(net, sw, host['name'], host['ip'], host['mac'])
67 addTunnel(sw['name'], sw['tunnelIp'])
69 for host in net.hosts:
70 gw = re.sub(r'.\d+$', ".1", host.IP())
71 host.cmd('route add default gw {}'.format(gw))
73 # ODL is very fragile so let's give it some time
76 # This is a workaround for a bug encountered during
77 # the Helium release. Setting the vSwitch from 1.0
78 # to 1.3 while it was connected to the controller
79 # exposed a bug in the openflowplugin, which resulted
80 # in the controller missing some of the ports on the
81 # vswitch. This change avoids the bug by switching
82 # the version before connecting the switch to the
85 setOFVersion(sw['name'])
86 addController(sw['name'], contIP)