import Pyro4
+import time
def main():
# do some API tests
h1 = rmn.addHost('h1')
h2 = rmn.addHost('h2')
- #d1 = rmn.addDocker('d1', ip='10.0.0.253', dimage="ubuntu")
+ d1 = rmn.addDocker('d1', ip='10.0.0.253', dimage="ubuntu")
s1 = rmn.addSwitch("s1")
rmn.addLink(h1, s1)
rmn.addLink(h2, s1)
+ rmn.addLink(d1, s1)
rmn.start()
+ # check functionality at runtime
+ """
+ d2 = rmn.addDocker('d2', dimage="ubuntu")
h3 = rmn.addHost('h3', ip='10.0.0.200')
- rmn.addLink(h3, s1)
+ rmn.addLink(d2, s1, params1={"ip": "10.0.0.251/8"})
+ time.sleep(2)
+ rmn.removeLink(node1="h1", node2="s1")
+ rmn.removeHost('h1')
+ #rmn.removeHost('d1')
+ """
+
+ time.sleep(2)
rmn.stop()
# We need a properly installed Dockernet
from mininet.net import Mininet
from mininet.node import Controller, Docker, OVSSwitch
+from mininet.link import *
from mininet.cli import CLI
import mininet.log
import logging
def start(self):
self.net.start()
- def stop(self):
+ def CLI(self):
CLI(self.net)
- self.net.stop()
+
+ def stop(self):
+ try:
+ self.net.stop()
+ except Exception as e:
+ print e
+
def addHost(self, name, cls=None, **params):
return str(self.net.addHost(name, cls=cls, **params))
def addDocker(self, name, **params):
return str(self.net.addDocker(name, **params))
- def addSwitch(self, name, cls=None, **params):
- return str(self.net.addSwitch(name, cls=cls, **params))
+ def addSwitch(self, name, **params):
+ # we have to use OVSSwitch to be able to do link attachments
+ # at runtime (switch.attach) method
+ return str(self.net.addSwitch(name, cls=OVSSwitch, **params))
def addLink(self, node1, node2, port1=None, port2=None,
cls=None, **params):
return str(self.net.addLink(node1, node2,
port1, port2, cls=cls, **params))
+ def removeHost(self, name, **params):
+ return self.net.removeHost(name, **params)
+
+ def removeLink(self, link=None, node1=None, node2=None):
+ n1, n2 = self.net.get(node1), self.net.get(node2)
+ return self.net.removeLink(node1=n1, node2=n2)
+
def start_server():
daemon = Pyro4.Daemon()