def _switch_request_sync(self, interval): while self.is_active: request = event.EventSwitchRequest() LOG.debug('switch_request sync %s thread(%s)', request, id(hub.getcurrent())) reply = self.send_request(request) LOG.debug('switch_reply sync %s', reply) if len(reply.switches) > 0: for sw in reply.switches: LOG.debug(' %s', sw) hub.sleep(interval)
def _link_request_sync(self, interval): while self.is_active: request = event.EventLinkRequest() LOG.debug('link_request sync %s thread(%s)', request, id(hub.getcurrent())) reply = self.send_request(request) LOG.debug('link_reply sync %s', reply) if len(reply.links) > 0: for link in reply.links: LOG.debug(' %s', link) hub.sleep(interval)
def _switch_request_async(self, interval): while self.is_active: request = event.EventSwitchRequest() LOG.debug('switch_request async %s thread(%s)', request, id(hub.getcurrent())) self.send_event(request.dst, request) start = time.time() busy = interval / 2 i = 0 while i < busy: if time.time() > start + i: i += 1 LOG.debug(' thread is busy... %s/%s thread(%s)', i, busy, id(hub.getcurrent())) LOG.debug(' thread yield to switch_reply handler. thread(%s)', id(hub.getcurrent())) # yield hub.sleep(0) LOG.debug(' thread get back. thread(%s)', id(hub.getcurrent())) hub.sleep(interval - busy)
hub.sleep(40) for datapath in self.datapaths: if datapath==self.dpid: for port in self.datapaths[datapath].ports.values(): if port.port_no==self.port: ofp = self.datapaths[datapath].ofproto parser = self.datapaths[datapath].ofproto_parser config = ofp.OFPPC_PORT_DOWN mask = ofp.OFPPC_PORT_DOWN msg=parser.OFPPortMod(self.datapaths[datapath], port.port_no, port.hw_addr, config, mask,port.advertised) self.datapaths[datapath].send_msg(msg) hub.kill(hub.getcurrent()) def portstatsreq(self,datapath): for ports in datapath.ports: ofproto=datapath.ofproto parser = datapath.ofproto_parser req = parser.OFPPortStatsRequest(datapath,0,ofproto.OFPP_NONE) datapath.send_msg(req) def _monitor(self): for dp in self.datapaths.values(): self.portstatsreq(dp) @set_ev_cls(ofp_event.EventOFPPortStatsReply, handler.MAIN_DISPATCHER) def save_portstate(self,ev): if ev.msg.datapath.id not in self.stats: self.stats[ev.msg.datapath.id]=ev.msg.body if len(self.stats) == len(self.datapaths): self.calc_dpid()