- def host_to_switch_connect(self, tap_endpoint, sw_endpoint):
- # Collect info from rem_endpoint
- remote_ip = socket.gethostbyname(self.node_endpoint1.get("hostname"))
-
- # Collect info from endpoint
- local_port_file = os.path.join(self.run_home(self.node_endpoint2), "local_port")
- rem_port_file = os.path.join(self.run_home(self.node_endpoint2), "remote_port")
- ret_file = os.path.join(self.run_home(self.node_endpoint2), "ret_file")
- cipher = self.get("cipher")
- cipher_key = self.get("cipherKey")
- bwlimit = self.get("bwLimit")
- txqueuelen = self.get("txQueueLen")
-
- rem_port = str(self.get_port_info( sw_endpoint,tap_endpoint))
-
- # Upload the remote port in a file
- self.node_endpoint2.upload(rem_port, rem_port_file,
- text = True,
- overwrite = False)
-
- udp_connect_command = tap_endpoint.udp_connect_command(
- remote_ip, local_port_file, rem_port_file,
- ret_file, cipher, cipher_key, bwlimit, txqueuelen)
-
- # upload command to host_connect.sh script
- shfile = os.path.join(self.app_home(self.node_endpoint2), "host_connect.sh")
- self.node_endpoint2.upload(udp_connect_command, shfile,
- text = True,
- overwrite = False)
-
- # invoke connect script
- cmd = "bash %s" % shfile
- (out, err), proc = self.node_endpoint2.run(cmd, self.run_home(self.node_endpoint2),
- sudo = True,
- stdout = "udp_stdout",
- stderr = "udp_stderr")
-
- # check if execution errors
- if proc.poll():
- msg = "Failed to connect endpoints"
- self.error(msg, out, err)
- raise RuntimeError, msg
-
- msg = "Connection on host %s configured" % self.node_endpoint2.get("hostname")
- self.debug(msg)
-
- # Wait for pid file to be generated
- pid, ppid = self.node_endpoint2.wait_pid(self.run_home(self.node_endpoint2))
-
- # 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_endpoint2.check_errors(self.run_home(self.node_endpoint2))
- # 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)
-
- def switch_to_switch_connect(self, endpoint, rem_endpoint):
- """ Get switch connect command
- """
- # Get and configure switch connection command
-
- local_port_name, remote_ip, remote_port_num = self.get_port_info(endpoint, rem_endpoint)
-
-
- switch_connect_command = endpoint.switch_connect_command(
- local_port_name, remote_ip, remote_port_num)
- node_endpoint = self.get_node(endpoint)
-
- # Upload command to the file sw_connect.sh
- shfile = os.path.join(self.app_home(node_endpoint), "sw_connect.sh")
- node_endpoint.upload(switch_connect_command,
- shfile,
- text = True,
- overwrite = False)
-
- #invoke connect script
- cmd = "bash %s" % shfile
- (out, err), proc = node_endpoint.run(cmd, self.run_home(node_endpoint),
- sudo = True,
- stdout = "sw_stdout",
- stderr = "sw_stderr")
-
- # check if execution errors occured
- if proc.poll():
- msg = "Failed to connect endpoints"
- self.error(msg, out, err)
- raise RuntimeError, msg
-
- # For debugging
- msg = "Connection on port %s configured" % local_port_name
- self.info(msg)
-
- def wait_local_port(self):