Adding examples/ns3/multi_host
[nepi.git] / examples / ns3 / multi_host / experiment_interconnected_ns3ns3.py
diff --git a/examples/ns3/multi_host/experiment_interconnected_ns3ns3.py b/examples/ns3/multi_host/experiment_interconnected_ns3ns3.py
new file mode 100644 (file)
index 0000000..ab2a8a2
--- /dev/null
@@ -0,0 +1,65 @@
+#\r
+#    NEPI, a framework to manage network experiments\r
+#    Copyright (C) 2013 INRIA\r
+#\r
+#    This program is free software: you can redistribute it and/or modify\r
+#    it under the terms of the GNU General Public License version 2 as\r
+#    published by the Free Software Foundation;\r
+#\r
+#    This program is distributed in the hope that it will be useful,\r
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+#    GNU General Public License for more details.\r
+#\r
+#    You should have received a copy of the GNU General Public License\r
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+#\r
+# Author: Damien Saucez <damien.saucez@inria.fr>\r
+#         Alina Quereilhac <alina.quereilhac@inria.fr>\r
+\r
+from experiment_interconnected import ExperimentInterconnected\r
+\r
+class ExperimentInterconnectedNs3Ns3(ExperimentInterconnected):\r
+    def connect_with_udp_tunnel(self, xp_remote):\r
+        # Connect the two experiments via a UDP tunnel direcly on the FD devices\r
+        tunnel = self.ec.register_resource("planetlab::ns3::FdUdpTunnel")\r
+        self.ec.register_connection(tunnel, self.fddev)\r
+        self.ec.register_connection(tunnel, xp_remote.fddev)\r
+\r
+        return tunnel\r
+\r
+    def interconnect(self, xp_remote):\r
+        """\r
+        Interconnect two ns3 simulations via a UDP tunnel\r
+        """\r
+        # sanity checks\r
+        #\r
+        # topology must be setup\r
+        if not self.topology_built:\r
+            raise Exception("Topology not setup on ", self)\r
+        if not xp_remote.topology_built:\r
+            raise Exception("Topology not setup on ", xp_remote )\r
+        #\r
+        # experiment cannot be interconnected to another experiment\r
+        if self.interconnected:\r
+            raise Exception("Experiment already interconnected on ", self)\r
+        if xp_remote.interconnected:\r
+            raise Exception("Experiment already interconnected on ", xp_remote)\r
+\r
+        # IP for the AP of the two experiments\r
+        # XXX DSA: ugly\r
+        ip = ["10.0.0.1", "10.0.0.2"]\r
+\r
+        # add an FD device on both local and remote experiments\r
+        self.add_fdnetdevice(ip[0], "30")\r
+        xp_remote.add_fdnetdevice(ip[1], "30")\r
+\r
+        # Connect the two experiments via a UDP tunnel direcly on the FD devices\r
+        self.connect_with_udp_tunnel(xp_remote)\r
+\r
+        # Add a route to the remote network on each experiment, via the FD device\r
+        self.add_route(self.nsnodes[0], xp_remote.netblock, xp_remote.prefix, ip[1])\r
+        xp_remote.add_route(xp_remote.nsnodes[0], self.netblock, self.prefix, ip[0])\r
+\r
+        # Sanity check\r
+        self.interconnected = True\r