2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.resource import ResourceState, clsinit_copy
21 from nepi.resources.linux.ns3.tun_tap_fd_link import LinuxTunTapFdLink
30 class PlanetlabTunTapFdLink(LinuxTunTapFdLink):
31 """ Interconnects a TAP or TUN PlanetLab device to a FdNetDevice
33 _rtype = "planetlab::ns3::TunTapFdLink"
35 def __init__(self, ec, guid):
36 super(PlanetlabTunTapFdLink, self).__init__(ec, guid)
39 def fdnetdevice(self):
40 if not self._fdnetdevice:
41 from nepi.resources.ns3.ns3fdnetdevice import NS3BaseFdNetDevice
42 devices = self.get_connected(NS3BaseFdNetDevice.get_rtype())
43 if not devices or len(devices) != 1:
44 msg = "planetlab::ns3::TunTapFdLink must be connected to exactly one FdNetDevice"
46 raise RuntimeError, msg
48 self._fdnetdevice = devices[0]
51 self._fdnetdevice.set("EncapsulationMode", "DixPi")
53 simu = self._fdnetdevice.simulation
54 from nepi.resources.planetlab.node import PlanetlabNode
55 nodes = simu.get_connected(PlanetlabNode.get_rtype())
56 self._fd_node = nodes[0]
58 return self._fdnetdevice
63 from nepi.resources.planetlab.tap import PlanetlabTap
64 devices = self.get_connected(PlanetlabTap.get_rtype())
66 if not devices or len(devices) != 1:
67 msg = "planetlab::ns3::TunTapFdLink must be connected to exactly one PlanetlabTap"
69 raise RuntimeError, msg
71 self._tap = devices[0]
75 def upload_sources(self):
78 # vif-passfd python script
79 pl_vif_passfd = os.path.join(os.path.dirname(__file__),
84 scripts.append(pl_vif_passfd)
87 scripts = ";".join(scripts)
89 self.node.upload(scripts,
90 os.path.join(self.node.src_dir),
94 def _start_command(self):
95 address = base64.b64encode(self.send_address)
98 # Use pl-vif-passfd.py to send fd from TAP to FdNetDevice
99 command.append("sudo -S")
100 command.append("PYTHONPATH=$PYTHONPATH:${SRC}")
101 command.append("python ${SRC}/pl-vif-passfd.py")
102 command.append("-a %s" % address)
103 command.append("-S %s " % self.tap.sock_name)
105 command = " ".join(command)
106 command = self.replace_paths(command)