def stopFlow(self, flow): """Instructs host to stop iperf client session (flow). """ flow2 = Flow( src=flow["src"].ip.compressed, dst=flow["dst"].ip.compressed, sport=flow["sport"], dport=flow["dport"], size=flow["size"], start_time=flow["start_time"], duration=flow["duration"], ) url = "http://%s:%s/stopflow" % (flow2["src"], dconf.Hosts_JsonPort) t = time.strftime("%H:%M:%S", time.gmtime()) log.info("%s - Stopping Flow\n" % t) log.info("\t Sending request to host to stop flow %s\n" % str(flow["src"])) log.info("\t * Flow: %s\n" % self.toLogFlowNames(flow)) log.info("\t * Url: %s\n" % url) # Send request to host to start new iperf client session try: requests.post(url, json=flow2.toJSON()) except Exception: log.info("ERROR: Stop flow request could not be sent to Host!\n")
def _createFlow(self, flow): """Creates the corresponding iperf command to actually install the given flow in the network. This function has to call self.informLBController! """ # Sleep after it is your time to start time.sleep(flow["start_time"]) # Call to informLBController if it is active if self._lbc_ip: self.informLBController(flow) # time.sleep(0.2) # Create new flow with hosts ip's instead of interfaces # Iperf only understands ip's flow2 = Flow( src=flow["src"].ip.compressed, dst=flow["dst"].ip.compressed, sport=flow["sport"], dport=flow["dport"], size=flow["size"], start_time=flow["start_time"], duration=flow["duration"], ) url = "http://%s:%s/startflow" % (flow2["src"], dconf.Hosts_JsonPort) t = time.strftime("%H:%M:%S", time.gmtime()) log.info("%s - Starting Flow\n" % t) log.info("\t Sending request to host %s\n" % str(flow["src"])) log.info("\t * Flow: %s\n" % self.toLogFlowNames(flow)) log.info("\t * Url: %s\n" % url) # Send request to host to start new iperf client session try: requests.post(url, json=flow2.toJSON()) except Exception: log.info("ERROR: Request could not be sent to Host!\n") log.info("LOG: Exception in user code:\n") log.info("-" * 60 + "\n") log.info(traceback.print_exc()) log.info("-" * 60 + "\n")