Adding examples/ns3/multi_host
[nepi.git] / examples / ns3 / multi_host / experiment_interconnected_ns3ns3.py
1 #\r
2 #    NEPI, a framework to manage network experiments\r
3 #    Copyright (C) 2013 INRIA\r
4 #\r
5 #    This program is free software: you can redistribute it and/or modify\r
6 #    it under the terms of the GNU General Public License version 2 as\r
7 #    published by the Free Software Foundation;\r
8 #\r
9 #    This program is distributed in the hope that it will be useful,\r
10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12 #    GNU General Public License for more details.\r
13 #\r
14 #    You should have received a copy of the GNU General Public License\r
15 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
16 #\r
17 # Author: Damien Saucez <damien.saucez@inria.fr>\r
18 #         Alina Quereilhac <alina.quereilhac@inria.fr>\r
19 \r
20 from experiment_interconnected import ExperimentInterconnected\r
21 \r
22 class ExperimentInterconnectedNs3Ns3(ExperimentInterconnected):\r
23     def connect_with_udp_tunnel(self, xp_remote):\r
24         # Connect the two experiments via a UDP tunnel direcly on the FD devices\r
25         tunnel = self.ec.register_resource("planetlab::ns3::FdUdpTunnel")\r
26         self.ec.register_connection(tunnel, self.fddev)\r
27         self.ec.register_connection(tunnel, xp_remote.fddev)\r
28 \r
29         return tunnel\r
30 \r
31     def interconnect(self, xp_remote):\r
32         """\r
33         Interconnect two ns3 simulations via a UDP tunnel\r
34         """\r
35         # sanity checks\r
36         #\r
37         # topology must be setup\r
38         if not self.topology_built:\r
39             raise Exception("Topology not setup on ", self)\r
40         if not xp_remote.topology_built:\r
41             raise Exception("Topology not setup on ", xp_remote )\r
42         #\r
43         # experiment cannot be interconnected to another experiment\r
44         if self.interconnected:\r
45             raise Exception("Experiment already interconnected on ", self)\r
46         if xp_remote.interconnected:\r
47             raise Exception("Experiment already interconnected on ", xp_remote)\r
48 \r
49         # IP for the AP of the two experiments\r
50         # XXX DSA: ugly\r
51         ip = ["10.0.0.1", "10.0.0.2"]\r
52 \r
53         # add an FD device on both local and remote experiments\r
54         self.add_fdnetdevice(ip[0], "30")\r
55         xp_remote.add_fdnetdevice(ip[1], "30")\r
56 \r
57         # Connect the two experiments via a UDP tunnel direcly on the FD devices\r
58         self.connect_with_udp_tunnel(xp_remote)\r
59 \r
60         # Add a route to the remote network on each experiment, via the FD device\r
61         self.add_route(self.nsnodes[0], xp_remote.netblock, xp_remote.prefix, ip[1])\r
62         xp_remote.add_route(xp_remote.nsnodes[0], self.netblock, self.prefix, ip[0])\r
63 \r
64         # Sanity check\r
65         self.interconnected = True\r