Changed the endpoint_ip and endpoint_prefix attributes of TAP/TUN endpoints for ip...
[nepi.git] / src / nepi / resources / planetlab / tap.py
index 4df138b..2f2975a 100644 (file)
@@ -18,8 +18,7 @@
 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
 
 from nepi.execution.attribute import Attribute, Flags, Types
-from nepi.execution.resource import clsinit_copy, ResourceState, \
-        reschedule_delay
+from nepi.execution.resource import clsinit_copy, ResourceState 
 from nepi.resources.linux.application import LinuxApplication
 from nepi.resources.planetlab.node import PlanetlabNode
 from nepi.util.timefuncs import tnow, tdiffsec
@@ -31,13 +30,13 @@ PYTHON_VSYS_VERSION = "1.0"
 
 @clsinit_copy
 class PlanetlabTap(LinuxApplication):
-    _rtype = "PlanetlabTap"
+    _rtype = "planetlab::Tap"
     _help = "Creates a TAP device on a PlanetLab host"
     _backend = "planetlab"
 
     @classmethod
     def _register_attributes(cls):
-        endpoint_ip = Attribute("endpoint_ip", "IP of the endpoint. This is the attribute " 
+        ip = Attribute("ip", "IP of the endpoint. This is the attribute " 
                                 "you should use to establish a tunnel or a remote "
                                 "connection between endpoint",
               flags = Flags.Design)
@@ -45,8 +44,7 @@ class PlanetlabTap(LinuxApplication):
         mac = Attribute("mac", "MAC Address",
                 flags = Flags.Design)
 
-        endpoint_prefix = Attribute("endpoint_prefix", "IPv4 network prefix of the endpoint",
-                type = Types.Integer,
+        prefix = Attribute("prefix", "IPv4 network prefix of the endpoint",
                 flags = Flags.Design)
 
         mtu = Attribute("mtu", "Maximum transmition unit for device",
@@ -85,9 +83,9 @@ class PlanetlabTap(LinuxApplication):
                 "Bash script to be executed before releasing the resource",
                 flags = Flags.Design)
 
-        cls._register_attribute(endpoint_ip)
+        cls._register_attribute(ip)
         cls._register_attribute(mac)
-        cls._register_attribute(endpoint_prefix)
+        cls._register_attribute(prefix)
         cls._register_attribute(mtu)
         cls._register_attribute(devname)
         cls._register_attribute(up)
@@ -193,7 +191,7 @@ class PlanetlabTap(LinuxApplication):
 
     def do_deploy(self):
         if not self.node or self.node.state < ResourceState.PROVISIONED:
-            self.ec.schedule(reschedule_delay, self.deploy)
+            self.ec.schedule(self.reschedule_delay, self.deploy)
         else:
             if not self.get("command"):
                 self.set("command", self._start_command)
@@ -261,7 +259,7 @@ class PlanetlabTap(LinuxApplication):
 
         for rm in rms:
             if rm.state < ResourceState.STOPPED:
-                self.ec.schedule(reschedule_delay, self.release)
+                self.ec.schedule(self.reschedule_delay, self.release)
                 return 
 
         super(PlanetlabTap, self).do_release()
@@ -343,14 +341,12 @@ class PlanetlabTap(LinuxApplication):
 
         return True
 
-
     def initiate_udp_connection(self, remote_endpoint, connection_app_home, 
             connection_run_home, cipher, cipher_key, bwlimit, txqueuelen):
         port = self.udp_connect(remote_endpoint, connection_app_home, 
             connection_run_home, cipher, cipher_key, bwlimit, txqueuelen)
         return port
 
-
     def udp_connect(self, remote_endpoint, connection_app_home, 
             connection_run_home, cipher, cipher_key, bwlimit, txqueuelen):
         udp_connect_command = self._udp_connect_command(
@@ -394,9 +390,10 @@ class PlanetlabTap(LinuxApplication):
     def _udp_connect_command(self, remote_endpoint, connection_run_home, 
             cipher, cipher_key, bwlimit, txqueuelen):
 
-        # Set the remote endpoint
-        self.set("pointopoint", remote_endpoint.get("endpoint_ip"))
+        # Set the remote endpoint, (private) IP of the device
+        self.set("pointopoint", remote_endpoint.get("ip"))
 
+        # Public IP of the node
         remote_ip = remote_endpoint.node.get("ip")
 
         local_port_file = os.path.join(self.run_home, 
@@ -501,11 +498,10 @@ class PlanetlabTap(LinuxApplication):
 
         return result
 
-
-
     def _gre_connect_command(self, remote_endpoint, connection_run_home): 
-        # Set the remote endpoint
-        self.set("pointopoint", remote_endpoint.get("endpoint_ip"))
+        # Set the remote endpoint, (private) IP of the device
+        self.set("pointopoint", remote_endpoint.get("ip"))
+        # Public IP of the node
         self.set("greRemote", remote_endpoint.node.get("ip"))
 
         # Generate GRE connect command
@@ -527,7 +523,6 @@ class PlanetlabTap(LinuxApplication):
 
         return command
 
-
     @property
     def _start_command(self):
         if self.gre_enabled:
@@ -536,8 +531,8 @@ class PlanetlabTap(LinuxApplication):
             command = ["sudo -S python ${SRC}/pl-vif-create.py"]
             
             command.append("-t %s" % self.vif_type)
-            command.append("-a %s" % self.get("endpoint_ip"))
-            command.append("-n %d" % self.get("endpoint_prefix"))
+            command.append("-a %s" % self.get("ip"))
+            command.append("-n %s" % self.get("prefix"))
             command.append("-f %s " % self.vif_name_file)
             command.append("-S %s " % self.sock_name)
 
@@ -579,8 +574,8 @@ class PlanetlabTap(LinuxApplication):
         command.append("-u %s" % self.node.get("username"))
         command.append("-N %s" % device_name)
         command.append("-t %s" % self.vif_type)
-        command.append("-a %s" % self.get("endpoint_ip"))
-        command.append("-n %d" % self.get("endpoint_prefix"))
+        command.append("-a %s" % self.get("ip"))
+        command.append("-n %s" % self.get("prefix"))
 
         if self.get("snat") == True:
             command.append("-s")