X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=src%2Fnepi%2Fresources%2Fplanetlab%2Ftap.py;h=4df138bb89b288e3304fa3ff2f3f73d025d9e726;hb=4f61ec12520928b3403ee2a75c9e4ce1b30907a3;hp=5a47663cf2b7c13b109dce252af82ffa339ec71f;hpb=4c05030074b51677a854bfd9d71c9a83de44c90c;p=nepi.git diff --git a/src/nepi/resources/planetlab/tap.py b/src/nepi/resources/planetlab/tap.py index 5a47663c..4df138bb 100644 --- a/src/nepi/resources/planetlab/tap.py +++ b/src/nepi/resources/planetlab/tap.py @@ -343,6 +343,14 @@ 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( @@ -350,14 +358,14 @@ class PlanetlabTap(LinuxApplication): cipher, cipher_key, bwlimit, txqueuelen) # upload command to connect.sh script - shfile = os.path.join(connection_app_home, "udp-connect.sh") + shfile = os.path.join(self.app_home, "udp-connect.sh") self.node.upload_command(udp_connect_command, shfile = shfile, overwrite = False) # invoke connect script cmd = "bash %s" % shfile - (out, err), proc = self.node.run(cmd, connection_run_home) + (out, err), proc = self.node.run(cmd, self.run_home) # check if execution errors occurred msg = "Failed to connect endpoints " @@ -367,19 +375,21 @@ class PlanetlabTap(LinuxApplication): raise RuntimeError, msg # Wait for pid file to be generated - pid, ppid = self.node.wait_pid(connection_run_home) + self._pid, self._ppid = self.node.wait_pid(self.run_home) # If the process is not running, check for error information # on the remote machine - if not pid or not ppid: - (out, err), proc = self.node.check_errors(connection_run_home) + if not self._pid or not self._ppid: + (out, err), proc = self.node.check_errors(self.run_home) # Out is what was written in the stderr file if err: msg = " Failed to start command '%s' " % command self.error(msg, out, err) raise RuntimeError, msg - return pid, ppid + port = self.wait_local_port() + + return port def _udp_connect_command(self, remote_endpoint, connection_run_home, cipher, cipher_key, bwlimit, txqueuelen): @@ -389,13 +399,13 @@ class PlanetlabTap(LinuxApplication): remote_ip = remote_endpoint.node.get("ip") - local_port_file = os.path.join(connection_run_home, + local_port_file = os.path.join(self.run_home, "local_port") - remote_port_file = os.path.join(connection_run_home, + remote_port_file = os.path.join(self.run_home, "remote_port") - ret_file = os.path.join(connection_run_home, + ret_file = os.path.join(self.run_home, "ret_file") # Generate UDP connect command @@ -432,6 +442,67 @@ class PlanetlabTap(LinuxApplication): return command + def establish_udp_connection(self, remote_endpoint, port): + # upload remote port number to file + rem_port = "%s\n" % port + self.node.upload(rem_port, + os.path.join(self.run_home, "remote_port"), + text = True, + overwrite = False) + + def verify_connection(self): + self.wait_result() + + def terminate_connection(self): + if self._pid and self._ppid: + (out, err), proc = self.node.kill(self._pid, self._ppid, + sudo = True) + + # check if execution errors occurred + if proc.poll() and err: + msg = " Failed to Kill the Tap" + self.error(msg, out, err) + raise RuntimeError, msg + + def check_status(self): + return self.node.status(self._pid, self._ppid) + + def wait_local_port(self): + """ Waits until the local_port file for the endpoint is generated, + and returns the port number + + """ + return self.wait_file("local_port") + + def wait_result(self): + """ Waits until the return code file for the endpoint is generated + + """ + return self.wait_file("ret_file") + + def wait_file(self, filename): + """ Waits until file on endpoint is generated """ + result = None + delay = 1.0 + + for i in xrange(20): + (out, err), proc = self.node.check_output( + self.run_home, filename) + if out: + result = out.strip() + break + else: + time.sleep(delay) + delay = delay * 1.5 + else: + msg = "Couldn't retrieve %s" % filename + self.error(msg, out, err) + raise RuntimeError, msg + + return result + + + def _gre_connect_command(self, remote_endpoint, connection_run_home): # Set the remote endpoint self.set("pointopoint", remote_endpoint.get("endpoint_ip")) @@ -456,6 +527,7 @@ class PlanetlabTap(LinuxApplication): return command + @property def _start_command(self): if self.gre_enabled: