def _handle_FlowStatsReceived(self, event): self.listaPortas = [] stats = flow_stats_to_list(event.stats) #Todas as regras em uma lista #log.info("%s: FlowStatsReceived -> %s", self.nome, stats) self.numRegras = len(stats) if (self.nome == "Switch HW"): self.flowStatsHW(event) f = open("info_hw.txt", "a+") f.write("%d HW %d %d %d %d\n" % (time.time() - TEMPOINI, sHW.getNumregras(), sHW.getNumAceitas(), sHW.getNumBloqueadas(), self.bytesEnviados)) f.close() #self.iniciarTimer() elif (self.nome == "Switch SW"): self.flowStatsSW(event) f = open("info_hw.txt", "a+") f.write("%d SW %d %d %d %d\n" % (time.time() - TEMPOINI, sSW.getNumregras(), sSW.getNumAceitas(), sSW.getNumBloqueadas(), self.bytesEnviados)) f.close() #self.iniciarTimer() elif (self.nome == "Switch UL"): self.flowStatsUL(event) elif (self.nome == "Switch DL"): self.flowStatsDL(event)
def _handle_flowstats_received(event): stats = flow_stats_to_list(event.stats) log.debug("FlowStatsReceived from %s: %s", dpidToStr(event.connection.dpid), stats) for f in event.stats: if f.match.tp_dst == 80 or f.match.tp_src == 80: print "Received web traffic"
def _handle_FlowStatsReceived (event): switch = event.connection.dpid connection = connections[switch] stats = flow_stats_to_list(event.stats) # Get number of bytes/packets in flows bytes = 0 flows = 0 packet = 0 for key in connection['bytes']: connection['bytes'][key] = 0 total_bytes = 0 for f in event.stats: port = f.match.in_port if port == None: continue connection['bytes'][port] = connection['bytes'].get(port, 0) + f.byte_count visual.event({ "name": "flow", "id": switch, "bytes":connection['bytes'], "ports":connection['ports'] })
def _handle_FlowStatsReceived(self, event): stats = flow_stats_to_list(event.stats) log.info("GOT STATS") #log.info(stats) switch = event.dpid local = [e for e in self.flows if e.switch == switch] for flow in stats: f = lib.match_to_flow(flow['match']) #log.info("{0} became {1}".format(flow,f)) if not f: continue try: entry = next(e for e in local if e.flow == f) log.info("just getting old entry for {0}".format(f)) except StopIteration: log.info("making a new entry for {0}".format(f)) entry = lib.Entry(switch, f) self.flows.append(entry) bc = int(flow['byte_count']) log.info("old total: {0}, new total: {1}, diff: {2}, recent: {3}".format(entry.total, bc, bc-entry.total, (bc-entry.total)/self.period)) entry.recent = (bc - entry.total) / self.period entry.total = bc
def _handle_portstats_received(self, event): """Handles a PortStatsRequest at the switch and computes throughput. Fills or updates the dictionnary `self.current_port_throughput` with throughputs of each link of the switch in Kbps. The throughput is calculated every `self.time_interval` seconds. BUG: The switch receives the PortStatsReceived object of all the switches controlled by this controller. Parameters ---------- event: PortStatsReceived Event listening to PortStatsReceived from openflow Returns ------- None """ log.debug(" S{} - PortStatsReceived from switch S{}".format( self.switch_id, event.connection.dpid)) for stat in flow_stats_to_list(event.stats): current_bytes = stat['tx_bytes'] key = (event.dpid, stat['port_no']) if key in self.current_port_throughput: throughput = (current_bytes - self.current_port_throughput[key] ) / self.time_interval / 10**3 self.current_port_throughput[key] = throughput else: # Initilisation self.current_port_throughput[key] = current_bytes return
def _handle_FlowStatsReceived(self, event): """ Handle OFPT_STATS_REPLY messages from switches. Add a new entry if flow is previously unseen, else update the old. """ stats = flow_stats_to_list(event.stats) switch = event.dpid local = [e for e in self.flows if e.switch == switch] log.info("stats on switch {0}".format(switch)) log.info(stats) for flow in stats: f = lib.match_to_flow(flow['match']) if not f: continue try: entry = next(e for e in local if e.flow == f) except StopIteration: entry = lib.Entry(switch, f) self.flows.append(entry) bc = int(flow['byte_count']) * 8 # want everything in bits entry.recent = (bc - entry.total) / self.period entry.total = bc if entry.recent <= 20000: self.flows.remove(entry)
def flowStatsSW (self, event): stats = flow_stats_to_list(event.stats) #Todas as regras em uma lista #log.info("%s: FlowStatsReceived -> %s", self.nome, stats) self.numRegras = len(stats) log.info ("%s: Numero de regras instaladas: %d", self.nome, self.numRegras) for regra in event.stats: if (regra.cookie == 55 or (regra.match.nw_proto != 6 and regra.match.nw_proto != 17)): continue #Ignora as regras fixas e regras de arp
def flowStatsHW(self, event): stats = flow_stats_to_list(event.stats) #Todas as regras em uma lista #log.info("%s: FlowStatsReceived -> %s", self.nome, stats) self.numRegras = len(stats) log.info("%s: Numero de regras instaladas: %d", self.nome, self.numRegras) log.info("%s: Numero de regras bloqueadas: %d", self.nome, self.numBloqueadas)
def _handle_PortStatsReceived(self, event): stats = of_json.flow_stats_to_list(event.stats) ports = [] for port in stats: ports.append( PortStatsMessage( rx_packets=port["rx_packets"], tx_packets=port["tx_packets"], rx_bytes=port["rx_bytes"], tx_bytes=port["tx_bytes"], port_no=port["port_no"])) message = SwitchStatsMessage(dpidToStr(event.connection.dpid), ports) send(message, self.stream)
def _handle_PortStatsReceived (self, event) : stats = of_json.flow_stats_to_list(event.stats) ports = [] for port in stats: ports.append(PortStatsMessage( rx_packets=port["rx_packets"], tx_packets=port["tx_packets"], rx_bytes=port["rx_bytes"], tx_bytes=port["tx_bytes"], port_no=port["port_no"] )) message = SwitchStatsMessage(dpidToStr(event.connection.dpid), ports) send(message, self.stream)
def _handle_FlowStatsReceived (event): switch = event.connection.dpid connection = connections[switch] stats = flow_stats_to_list(event.stats) # log.debug("FlowStatsReceived from %s", dpid_to_str(switch)) # Get number of bytes/packets in flows bytes = 0 flows = 0 packet = 0 for f in event.stats: if f.match.tp_dst == 80 or f.match.tp_src == 80: bytes += f.byte_count packet += f.packet_count flows += 1 # log.info("Web traffic from %s: %s bytes (%s packets) over %s flows", # dpid_to_str(event.connection.dpid), bytes, packet, flows) visual.event({ "name": "flow", "id": switch, "bytes":connection['bytes'], "ports":connection['ports'] })
def _handle_portstats_received(event): stats = flow_stats_to_list(event.stats) log.debug("PortStatsReceived from %s: %s", dpidToStr(event.connection.dpid), stats)
def _handle_PortStatsReceived (event): switch = event.connection.dpid connection = connections[switch] stats = flow_stats_to_list(event.stats) log.info("Port stats received from %s", dpid_to_str(switch))
def _handle_PortStatsReceived (event): switch = event.connection.dpid connection = connections[switch] stats = flow_stats_to_list(event.stats)
def _handle_FlowStatsReceived(event): stats = flow_stats_to_list(event.stats) #Todas as regras em uma lista log.info("FlowStatsReceived -> %s", stats)