2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2013 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.attribute import Attribute, Flags, Types
21 from nepi.execution.resource import clsinit_copy, ResourceState, \
23 from nepi.resources.linux.tunnel import LinuxTunnel
24 from nepi.util.sshfuncs import ProcStatus
25 from nepi.util.timefuncs import tnow, tdiffsec
33 class LinuxGRETunnel(LinuxTunnel):
34 _rtype = "LinuxGRETunnel"
35 _help = "Constructs a tunnel between two Linux endpoints using a UDP connection "
38 def log_message(self, msg):
39 return " guid %d - GRE tunnel %s - %s - %s " % (self.guid,
40 self.endpoint1.node.get("hostname"),
41 self.endpoint2.node.get("hostname"),
44 def get_endpoints(self):
45 """ Returns the list of RM that are endpoints to the tunnel
48 for guid in self.connections:
49 rm = self.ec.get_resource(guid)
50 if hasattr(rm, "gre_connect"):
54 def initiate_connection(self, endpoint, remote_endpoint):
55 # Return the command to execute to initiate the connection to the
57 connection_run_home = self.run_home(endpoint)
58 connection_app_home = self.app_home(endpoint)
59 data = endpoint.gre_connect(remote_endpoint,
64 def establish_connection(self, endpoint, remote_endpoint, data):
67 def verify_connection(self, endpoint, remote_endpoint):
68 remote_ip = socket.gethostbyname(remote_endpoint.node.get("hostname"))
70 command = "ping -c 4 %s" % remote_ip
71 (out, err), proc = endpoint.node.execute(command,
74 m = re.search("(\d+)% packet loss", str(out))
75 if not m or int(m.groups()[0]) == 100:
76 msg = " Erroro establishing GRE Tunnel"
77 self.error(msg, out, err)
78 raise RuntimeError, msg
80 def terminate_connection(self, endpoint, remote_endpoint):
83 def check_state_connection(self):
86 def valid_connection(self, guid):