def handle_response(self, response): """Handle an incoming poller response message. Args: message, a poller response message Returns: None """ # update cache setattr(self.block, self.MODULE_NAME, CQM()) map_entry_block = getattr(self.block, self.MODULE_NAME) # update this object self.maps = CQM() for entry in response.img_entries: addr = EtherAddress(entry[0]) value = {'addr': addr, 'last_rssi_std': entry[1], 'last_rssi_avg': entry[2], 'last_packets': entry[3], 'hist_packets': entry[4], 'mov_rssi': entry[5]} map_entry_block[addr] = value self.maps[addr] = value # call callback self.handle_callback(self)
def __init__(self): Module.__init__(self) # parameters self._block = None # data structures self.maps = CQM()
def __init__(self): super().__init__() # parameters self._block = None # data structures self.maps = CQM()
def handle_poller_response(self, message): """Handle an incoming poller response message. Args: message, a poller response message Returns: None """ if message.poller_id not in self.modules: return wtp_addr = EtherAddress(message.wtp) if wtp_addr not in RUNTIME.wtps: return wtp = RUNTIME.wtps[wtp_addr] hwaddr = EtherAddress(message.hwaddr) incoming = ResourcePool() incoming.add(ResourceBlock(wtp, hwaddr, message.channel, message.band)) matching = (wtp.supports & incoming).pop() LOG.info("Received %s response from %s (id=%u)", self.MODULE_NAME, matching, message.poller_id) # find poller object poller = self.modules[message.poller_id] # handle the message map_type = self.MODULE_NAME setattr(poller.block, map_type, CQM()) map_entry = getattr(poller.block, map_type) for entry in message.img_entries: addr = EtherAddress(entry[0]) if not addr.match(poller.addrs): continue value = {'addr': addr, 'last_rssi_std': entry[1] / 1000.0, 'last_rssi_avg': entry[2] / 1000.0, 'last_packets': entry[3], 'hist_packets': entry[4], 'ewma_rssi': entry[5] / 1000.0, 'sma_rssi': entry[6] / 1000.0} map_entry[addr] = value # call callback handle_callback(poller, poller)
def handle_response(self, response): """Handle an incoming poller response message. Args: message, a poller response message Returns: None """ wtp_addr = EtherAddress(response.wtp) if wtp_addr not in RUNTIME.wtps: return wtp = RUNTIME.wtps[wtp_addr] hwaddr = EtherAddress(response.hwaddr) block = ResourceBlock(wtp, hwaddr, response.channel, response.band) incoming = ResourcePool() incoming.add(block) matching = (wtp.supports & incoming).pop() if not matching: return # handle the message setattr(self.block, self.MODULE_NAME, CQM()) map_entry = getattr(self.block, self.MODULE_NAME) for entry in response.img_entries: addr = EtherAddress(entry[0]) if not addr.match(self.addrs): continue value = {'addr': addr, 'last_rssi_std': entry[1] / 1000.0, 'last_rssi_avg': entry[2] / 1000.0, 'last_packets': entry[3], 'hist_packets': entry[4], 'ewma_rssi': entry[5] / 1000.0, 'sma_rssi': entry[6] / 1000.0} map_entry[addr] = value # call callback self.handle_callback(self)
class Maps(Module): """ A maps poller. """ MODULE_NAME = None REQUIRED = ['module_type', 'worker', 'tenant_id', 'block'] PT_REQUEST = None def __init__(self): Module.__init__(self) # parameters self._block = None # data structures self.maps = CQM() def __eq__(self, other): return super().__eq__(other) and self.block == other.block @property def block(self): return self._block @block.setter def block(self, value): if isinstance(value, ResourceBlock): self._block = value elif isinstance(value, dict): wtp = RUNTIME.wtps[EtherAddress(value['wtp'])] if 'hwaddr' not in value: raise ValueError("Missing field: hwaddr") if 'channel' not in value: raise ValueError("Missing field: channel") if 'band' not in value: raise ValueError("Missing field: band") if 'wtp' not in value: raise ValueError("Missing field: wtp") # Check if block is valid incoming = ResourceBlock(wtp, EtherAddress(value['hwaddr']), int(value['channel']), int(value['band'])) match = [block for block in wtp.supports if block == incoming] if not match: raise ValueError("No block specified") if len(match) > 1: raise ValueError("More than one block specified") self._block = match[0] def to_dict(self): """ Return a JSON-serializable dictionary. """ out = super().to_dict() out['maps'] = {str(k): v for k, v in self.maps.items()} out['block'] = self.block.to_dict() return out def run_once(self): """ Send out request. """ if self.tenant_id not in RUNTIME.tenants: self.log.info("Tenant %s not found", self.tenant_id) self.unload() return tenant = RUNTIME.tenants[self.tenant_id] wtp = self.block.radio if wtp.addr not in tenant.wtps: self.log.info("WTP %s not found", wtp.addr) self.unload() return if not wtp.connection or wtp.connection.stream.closed(): self.log.info("WTP %s not connected", wtp.addr) self.unload() return req = Container(version=PT_VERSION, type=self.PT_REQUEST, length=22, seq=wtp.seq, module_id=self.module_id, wtp=wtp.addr.to_raw(), hwaddr=self.block.hwaddr.to_raw(), channel=self.block.channel, band=self.block.band) self.log.info("Sending %s request to %s (id=%u)", self.MODULE_NAME, self.block, self.module_id) msg = POLLER_REQUEST.build(req) wtp.connection.stream.write(msg) def handle_response(self, response): """Handle an incoming poller response message. Args: message, a poller response message Returns: None """ # update cache setattr(self.block, self.MODULE_NAME, CQM()) map_entry_block = getattr(self.block, self.MODULE_NAME) # update this object self.maps = CQM() for entry in response.img_entries: addr = EtherAddress(entry[0]) value = {'addr': addr, 'last_rssi_std': entry[1], 'last_rssi_avg': entry[2], 'last_packets': entry[3], 'hist_packets': entry[4], 'mov_rssi': entry[5]} map_entry_block[addr] = value self.maps[addr] = value # call callback self.handle_callback(self)
class Maps(Module): """ A maps poller. """ MODULE_NAME = None REQUIRED = ['module_type', 'worker', 'tenant_id', 'block'] PT_REQUEST = None def __init__(self): Module.__init__(self) # parameters self._block = None # data structures self.maps = CQM() def __eq__(self, other): return super().__eq__(other) and self.block == other.block @property def block(self): return self._block @block.setter def block(self, value): if isinstance(value, ResourceBlock): self._block = value elif isinstance(value, dict): wtp = RUNTIME.wtps[EtherAddress(value['wtp'])] if 'hwaddr' not in value: raise ValueError("Missing field: hwaddr") if 'channel' not in value: raise ValueError("Missing field: channel") if 'band' not in value: raise ValueError("Missing field: band") if 'wtp' not in value: raise ValueError("Missing field: wtp") incoming = ResourcePool() block = ResourceBlock(wtp, EtherAddress(value['hwaddr']), int(value['channel']), int(value['band'])) incoming.add(block) match = wtp.supports & incoming if not match: raise ValueError("No block specified") if len(match) > 1: raise ValueError("More than one block specified") self._block = match.pop() def to_dict(self): """ Return a JSON-serializable dictionary. """ out = super().to_dict() out['maps'] = {str(k): v for k, v in self.maps.items()} out['block'] = self.block.to_dict() return out def run_once(self): """ Send out request. """ if self.tenant_id not in RUNTIME.tenants: self.log.info("Tenant %s not found", self.tenant_id) self.unload() return tenant = RUNTIME.tenants[self.tenant_id] wtp = self.block.radio if wtp.addr not in tenant.wtps: self.log.info("WTP %s not found", wtp.addr) self.unload() return if not wtp.connection or wtp.connection.stream.closed(): self.log.info("WTP %s not connected", wtp.addr) return req = Container(version=PT_VERSION, type=self.PT_REQUEST, length=20, seq=wtp.seq, module_id=self.module_id, wtp=wtp.addr.to_raw(), hwaddr=self.block.hwaddr.to_raw(), channel=self.block.channel, band=self.block.band) self.log.info("Sending %s request to %s (id=%u)", self.MODULE_NAME, self.block, self.module_id) msg = POLLER_REQUEST.build(req) wtp.connection.stream.write(msg) def handle_response(self, response): """Handle an incoming poller response message. Args: message, a poller response message Returns: None """ # update cache setattr(self.block, self.MODULE_NAME, CQM()) map_entry_block = getattr(self.block, self.MODULE_NAME) # update this object self.maps = CQM() for entry in response.img_entries: addr = EtherAddress(entry[0]) value = {'addr': addr, 'last_rssi_std': entry[1], 'last_rssi_avg': entry[2], 'last_packets': entry[3], 'hist_packets': entry[4], 'mov_rssi': entry[5]} map_entry_block[addr] = value self.maps[addr] = value # call callback self.handle_callback(self)