Tunnel between 2 ns-3s in remote PL hosts
[nepi.git] / src / nepi / resources / planetlab / ns3 / fdudptunnel.py
1 #
2 #    NEPI, a framework to manage network experiments
3 #    Copyright (C) 2013 INRIA
4 #
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.
9 #
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.
14 #
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/>.
17 #
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
20 from nepi.execution.attribute import Attribute, Flags, Types
21 from nepi.execution.resource import clsinit_copy, ResourceState
22 from nepi.resources.linux.ns3.fdudptunnel import LinuxNs3FdUdpTunnel
23 from nepi.util.sshfuncs import ProcStatus
24 from nepi.util.timefuncs import tnow, tdiffsec
25
26 import base64
27 import os
28 import socket
29 import time
30
31 @clsinit_copy
32 class PlanetlabNs3FdUdpTunnel(LinuxNs3FdUdpTunnel):
33     _rtype = "planetlab::ns3::FdUdpTunnel"
34     _help = "Constructs a tunnel between two Ns-3 FdNetdevices " \
35             "located in remote PlanetLab nodes using a UDP connection "
36     _platform = "planetlab::ns3"
37
38     def get_endpoints(self):
39         """ Returns the list of RM that are endpoints to the tunnel 
40         """
41         if not self._fd2 or not self._fd1:
42             from nepi.resources.ns3.ns3fdnetdevice import NS3BaseFdNetDevice
43             devices = self.get_connected(NS3BaseFdNetDevice.get_rtype())
44             if not devices or len(devices) != 2: 
45                 msg = "Tunnel must be connected to exactly two FdNetDevices"
46                 self.error(msg)
47                 raise RuntimeError, msg
48
49             self._fd1 = devices[0]
50             self._fd2 = devices[1]
51             self._pi = True
52  
53             # Set PI headers on
54             self._fd1.set("EncapsulationMode", "DixPi")
55             self._fd2.set("EncapsulationMode", "DixPi")
56         
57             simu = self._fd1.simulation
58             from nepi.resources.linux.node import LinuxNode
59             nodes = simu.get_connected(LinuxNode.get_rtype())
60             self._fd1node = nodes[0]
61      
62             simu = self._fd2.simulation
63             from nepi.resources.linux.node import LinuxNode
64             nodes = simu.get_connected(LinuxNode.get_rtype())
65             self._fd2node = nodes[0]
66
67             if self._fd1node.get("hostname") == \
68                     self._fd2node.get("hostname"):
69                 msg = "Tunnel requires endpoints on different hosts"
70                 self.error(msg)
71                 raise RuntimeError, msg
72
73         return [self._fd1, self._fd2]
74
75