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 _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)
def get_switch(app, dpid=None): rep = app.send_request(event.EventSwitchRequest(dpid)) return rep.switches
def get_switches(self): rep = self.send_request(event.EventSwitchRequest(None)) return rep.switches