+ 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(
+ remote_endpoint, connection_run_home,
+ cipher, cipher_key, bwlimit, txqueuelen)
+
+ # upload command to connect.sh script
+ 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, self.run_home)
+
+ # check if execution errors occurred
+ msg = "Failed to connect endpoints "
+
+ if proc.poll():
+ self.error(msg, out, err)
+ raise RuntimeError, msg
+
+ # Wait for pid file to be generated
+ 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 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
+
+ port = self.wait_local_port()
+
+ return port
+
+ 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"))
+
+ # Planetlab TAPs always use PI headers
+ from nepi.resources.planetlab.tap import PlanetlabTap
+ if self.is_rm_instance(PlanetlabTap.get_rtype()):
+ self.set("pi", True)
+
+ remote_ip = remote_endpoint.node.get("ip")
+
+ local_port_file = os.path.join(self.run_home,
+ "local_port")
+
+ remote_port_file = os.path.join(self.run_home,
+ "remote_port")
+
+ ret_file = os.path.join(self.run_home,
+ "ret_file")
+
+ # Generate UDP connect command
+ # Use the start command to configure TAP with peer info
+ start_command = self._start_command
+
+ command = ["( "]
+ command.append(start_command)
+
+ # Use pl-vid-udp-connect.py to stablish the tunnel between endpoints
+ command.append(") & (")
+ command.append("sudo -S")
+ command.append("PYTHONPATH=$PYTHONPATH:${SRC}")
+ command.append("python ${SRC}/linux-udp-connect.py")
+ command.append("-N %s" % self.get("deviceName"))
+ command.append("-t %s" % self.vif_type)
+ if self.get("pi"):
+ command.append("-p")
+ command.append("-l %s " % local_port_file)
+ command.append("-r %s " % remote_port_file)
+ command.append("-H %s " % remote_ip)
+ command.append("-R %s " % ret_file)
+ if cipher:
+ command.append("-c %s " % cipher)
+ if cipher_key:
+ command.append("-k %s " % cipher_key)
+ if txqueuelen:
+ command.append("-q %s " % txqueuelen)
+ if bwlimit:
+ command.append("-b %s " % bwlimit)
+
+ command.append(")")
+
+ command = " ".join(command)
+ command = self.replace_paths(command)
+
+ return command
+