initial attempt to add a remote interface to mininet
authorpeusterm <manuel.peuster@uni-paderborn.de>
Fri, 11 Dec 2015 13:32:34 +0000 (14:32 +0100)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Fri, 11 Dec 2015 13:32:34 +0000 (14:32 +0100)
dockernetrpc/__init__.py [new file with mode: 0644]
dockernetrpc/__main__.py [new file with mode: 0644]
dockernetrpc/example_client.py [new file with mode: 0644]
dockernetrpc/rpc.py [new file with mode: 0644]
emuvim/__init__.py [new file with mode: 0644]

diff --git a/dockernetrpc/__init__.py b/dockernetrpc/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/dockernetrpc/__main__.py b/dockernetrpc/__main__.py
new file mode 100644 (file)
index 0000000..56d0fea
--- /dev/null
@@ -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 (file)
index 0000000..55973e1
--- /dev/null
@@ -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 (file)
index 0000000..da0518f
--- /dev/null
@@ -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 (file)
index 0000000..e69de29