+++ /dev/null
-import time
-import zerorpc
-
-
-def main():
- # create connection to remote Mininet instance
- c = zerorpc.Client()
- c.connect("tcp://127.0.0.1:4242")
-
- # do some API tests
- h1 = c.addHost('h1')
- h2 = c.addHost('h2')
- d1 = c.addDocker('d1', "ubuntu", "10.0.0.253")
-
- s1 = c.addSwitch("s1")
-
- c.addLink(h1, s1)
- c.addLink(h2, s1)
- c.addLink(d1, s1)
-
- c.start_net()
- c.CLI()
-
- # check functionality at runtime
- """
- d2 = c.addDocker('d2', dimage="ubuntu")
- h3 = c.addHost('h3', ip='10.0.0.200')
- c.addLink(d2, s1, params1={"ip": "10.0.0.251/8"})
-
- time.sleep(2)
- c.removeLink(node1="h1", node2="s1")
- c.removeHost('h1')
- #c.removeHost('d1')
- """
-
- time.sleep(2)
- c.stop_net()
-
-
-if __name__ == '__main__':
- main()
+++ /dev/null
-# 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
-import os
-import zerorpc
-
-
-class RemoteMininetNetwork(object):
-
- def __init__(self):
- # set mininet loglevel
- mininet.log.setLogLevel( 'info' )
- self.net = Mininet( controller=Controller )
- self.net.addController( 'c0' )
-
- def start_net(self):
- self.net.start()
-
- def CLI(self):
- CLI(self.net)
-
- def stop_net(self):
- try:
- self.net.stop()
- except Exception as e:
- print e
-
- def addHost(self, name, ip=None):
- return str(self.net.addHost(name, ip=ip))
-
- def addDocker(self, name, dimage, ip):
- return str(self.net.addDocker(name, dimage=dimage, ip=ip))
-
- def addSwitch(self, name):
- # 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))
-
- def addLink(self, node1, node2, port1=None, port2=None):
- return str(self.net.addLink(node1, node2,
- port1, port2))
-
- def removeHost(self, name):
- return self.net.removeHost(name)
-
- 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():
- s = zerorpc.Server(RemoteMininetNetwork())
- s.bind("tcp://0.0.0.0:4242")
- s.run()