From: peusterm Date: Fri, 11 Dec 2015 13:32:34 +0000 (+0100) Subject: initial attempt to add a remote interface to mininet X-Git-Tag: v3.1~185^2~36 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=44f341588a94136cf299485cd81790afde83ab62;p=osm%2Fvim-emu.git initial attempt to add a remote interface to mininet --- diff --git a/dockernetrpc/__init__.py b/dockernetrpc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dockernetrpc/__main__.py b/dockernetrpc/__main__.py new file mode 100644 index 0000000..56d0fea --- /dev/null +++ b/dockernetrpc/__main__.py @@ -0,0 +1,12 @@ +import time +import logging +import rpc + +logging.basicConfig(level=logging.DEBUG) + + +def main(): + rpc.start_server() + +if __name__ == '__main__': + main() diff --git a/dockernetrpc/example_client.py b/dockernetrpc/example_client.py new file mode 100644 index 0000000..55973e1 --- /dev/null +++ b/dockernetrpc/example_client.py @@ -0,0 +1,27 @@ +import Pyro4 + + +def main(): + # create connection to remote Mininet instance + rmn = Pyro4.Proxy("PYRONAME:remote.mininet") + + # do some API tests + h1 = rmn.addHost('h1') + h2 = rmn.addHost('h2') + #d1 = rmn.addDocker('d1', ip='10.0.0.253', dimage="ubuntu") + + s1 = rmn.addSwitch("s1") + + rmn.addLink(h1, s1) + rmn.addLink(h2, s1) + + rmn.start() + + h3 = rmn.addHost('h3', ip='10.0.0.200') + rmn.addLink(h3, s1) + + rmn.stop() + + +if __name__ == '__main__': + main() diff --git a/dockernetrpc/rpc.py b/dockernetrpc/rpc.py new file mode 100644 index 0000000..da0518f --- /dev/null +++ b/dockernetrpc/rpc.py @@ -0,0 +1,52 @@ +# We need a properly installed Dockernet +from mininet.net import Mininet +from mininet.node import Controller, Docker, OVSSwitch +from mininet.cli import CLI +import mininet.log +import logging +import os +import Pyro4 + + +class RemoteMininetNetwork(object): + + def __init__(self): + mininet.log.setLogLevel( 'debug' ) + self.net = Mininet( controller=Controller ) + self.net.addController( 'c0' ) + + def start(self): + self.net.start() + + def stop(self): + CLI(self.net) + self.net.stop() + + 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 addLink(self, node1, node2, port1=None, port2=None, + cls=None, **params): + return str(self.net.addLink(node1, node2, + port1, port2, cls=cls, **params)) + + +def start_server(): + daemon = Pyro4.Daemon() + # ATTENTION: + # we need a PyroNS instance to be running: pyro4-ns (in new terminal) + ns = Pyro4.locateNS() + uri = daemon.register(RemoteMininetNetwork()) + # map object URI to a nice name + ns.register("remote.mininet", uri) + + logging.info("Server URI is: %s", uri) + + # Start the server... + daemon.requestLoop() diff --git a/emuvim/__init__.py b/emuvim/__init__.py new file mode 100644 index 0000000..e69de29