2 # NEPI, a framework to manage network experiments
\r
3 # Copyright (C) 2013 INRIA
\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
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
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
17 # Author: Damien Saucez <damien.saucez@inria.fr>
\r
18 # Alina Quereilhac <alina.quereilhac@inria.fr>
\r
21 from experiment_interconnected import ExperimentInterconnected
\r
23 class ExperimentInterconnectedNs3Planetlab(ExperimentInterconnected):
\r
24 def add_tap_device(self, node, ip, prefix, pointopoint):
\r
26 Add a point-to-point tap device on the planetlab node. This tap device
\r
27 is used to exchange traffic with the simulated network
\r
29 # Create the tap device
\r
30 dev = self.ec.register_resource("planetlab::Tap")
\r
32 # Define the local network associated with the TAP device
\r
33 self.ec.set(dev, "ip", ip)
\r
34 self.ec.set(dev, "prefix", prefix)
\r
36 # Define the other side of the tap (the simulated network device)
\r
37 self.ec.set(dev, "pointopoint", pointopoint)
\r
39 # Associate the TAP device with the Planetlab node
\r
40 self.ec.register_connection(node, dev)
\r
44 def connect_with_tuntap(self, tap):
\r
46 Connect the simulated network with the Planetlab node via the TAP of
\r
47 the Planetlab node and the FD device of the simulated network
\r
50 crosslink = self.ec.register_resource("planetlab::ns3::TunTapFdLink")
\r
52 # Associate it with the Planetlab tap device on one side
\r
53 self.ec.register_connection(crosslink, tap)
\r
55 # Associate it with the simulated network FD device on the other side
\r
56 self.ec.register_connection(crosslink, self.fddev)
\r
60 def interconnect(self, netblock_pl, prefix_pl):
\r
62 Interconnect a simulated network with a Planetlab network via a tap device
\r
66 # topology must be setup
\r
67 if not self.topology_built:
\r
68 raise Exception("Topology not setup on ", self)
\r
70 # experiment cannot be interconnected to another experiment
\r
71 if self.interconnected:
\r
72 raise Exception("Experiment already interconnected on ", self)
\r
75 ip_simulated = str(ipaddr.IPv4Address(netblock_pl) + 1)
\r
76 ip_pl = str(ipaddr.IPv4Address(ip_simulated) + 1)
\r
78 # Add a TAP interface on the Planetlab machine to connect the real
\r
79 # application with the simulated network
\r
80 tap = self.add_tap_device(self.node, ip_pl, prefix_pl, ip_simulated)
\r
82 # Add an FD device on the simulator to connect to the real
\r
83 self.add_fdnetdevice(ip_simulated, prefix_pl)
\r
85 # Connect both Planetlab and simulated network via the tap device
\r
86 self.connect_with_tuntap(tap)
\r
88 # Route traffic for the Planetlab node to the Planetlab machine
\r
89 self.add_route(self.nsnodes[0], netblock_pl, prefix_pl, self.ip_ap)
\r
91 # Route traffic for the simulated node to the simulator
\r
92 self.add_vroute(tap, self.netblock, self.prefix, ip_simulated)
\r
95 self.interconnected = True
\r