applied the except and raise fixers to the master branch to close the gap with py3
[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 version 2 as
7 #    published by the Free Software Foundation;
8 #
9 #    This program is distributed in the hope that it will be useful,
10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #    GNU General Public License for more details.
13 #
14 #    You should have received a copy of the GNU General Public License
15 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
18
19 from nepi.execution.attribute import Attribute, Flags, Types
20 from nepi.execution.resource import clsinit_copy, ResourceState
21 from nepi.resources.linux.ns3.fdudptunnel import LinuxNs3FdUdpTunnel
22 from nepi.util.sshfuncs import ProcStatus
23 from nepi.util.timefuncs import tnow, tdiffsec
24
25 import base64
26 import os
27 import socket
28 import time
29
30 @clsinit_copy
31 class PlanetlabNs3FdUdpTunnel(LinuxNs3FdUdpTunnel):
32     _rtype = "planetlab::ns3::FdUdpTunnel"
33     _help = "Constructs a tunnel between two Ns-3 FdNetdevices " \
34             "located in remote PlanetLab nodes using a UDP connection "
35     _platform = "planetlab::ns3"
36
37     def get_endpoints(self):
38         """ Returns the list of RM that are endpoints to the tunnel 
39         """
40         if not self._fd2 or not self._fd1:
41             from nepi.resources.ns3.ns3fdnetdevice import NS3BaseFdNetDevice
42             devices = self.get_connected(NS3BaseFdNetDevice.get_rtype())
43             if not devices or len(devices) != 2: 
44                 msg = "Tunnel must be connected to exactly two FdNetDevices"
45                 self.error(msg)
46                 raise RuntimeError(msg)
47
48             self._fd1 = devices[0]
49             self._fd2 = devices[1]
50             self._pi = True
51  
52             # Set PI headers on
53             self._fd1.set("EncapsulationMode", "DixPi")
54             self._fd2.set("EncapsulationMode", "DixPi")
55         
56             simu = self._fd1.simulation
57             from nepi.resources.linux.node import LinuxNode
58             nodes = simu.get_connected(LinuxNode.get_rtype())
59             self._fd1node = nodes[0]
60      
61             simu = self._fd2.simulation
62             from nepi.resources.linux.node import LinuxNode
63             nodes = simu.get_connected(LinuxNode.get_rtype())
64             self._fd2node = nodes[0]
65
66             if self._fd1node.get("hostname") == \
67                     self._fd2node.get("hostname"):
68                 msg = "Tunnel requires endpoints on different hosts"
69                 self.error(msg)
70                 raise RuntimeError(msg)
71
72         return [self._fd1, self._fd2]
73
74