def handle_ifid_packet(self, pld, meta): """ Update the interface state for the corresponding interface. :param pld: The IFIDPayload. :type pld: IFIDPayload """ ifid = pld.p.relayIF with self.ifid_state_lock: if ifid not in self.ifid_state: raise SCIONKeyError("Invalid IF %d in IFIDPayload" % ifid) br = self.ifid2br[ifid] br.interface.to_if_id = pld.p.origIF prev_state = self.ifid_state[ifid].update() if prev_state == InterfaceState.INACTIVE: logging.info("IF %d activated", ifid) elif prev_state in [ InterfaceState.TIMED_OUT, InterfaceState.REVOKED ]: logging.info("IF %d came back up.", ifid) if not prev_state == InterfaceState.ACTIVE: if self.zk.have_lock(): # Inform BRs about the interface coming up. state_info = IFStateInfo.from_values( ifid, True, self._get_ht_proof(ifid)) pld = IFStatePayload.from_values([state_info]) for br in self.topology.get_all_border_routers(): meta = UDPMetadata.from_values(host=br.addr, port=br.port) self.send_meta(pld.copy(), meta, (br.addr, br.port))
def _send_ifstate_update(self, state_infos, border_metas, server_metas=None): server_metas = server_metas or [] payload = CtrlPayload(PathMgmt( IFStatePayload.from_values(state_infos))) for meta in border_metas: self.send_meta(payload.copy(), meta, (meta.host, meta.port)) for meta in server_metas: self.send_meta(payload.copy(), meta)
def _send_ifstate_update(self, border_metas, server_metas=None): server_metas = server_metas or [] with self.ifid_state_lock: infos = [] for (ifid, state) in self.ifid_state.items(): # Don't include inactive interfaces in update. if state.is_inactive(): continue rev_info = self._get_ht_proof(ifid) if state.is_revoked() else None info = IFStateInfo.from_values(ifid, state.is_active(), rev_info) infos.append(info) if not infos and not self._quiet_startup(): logging.warning("No IF state info to put in IFState update for %s.", ", ".join([str(m) for m in border_metas + server_metas])) return payload = IFStatePayload.from_values(infos) for meta in border_metas: self.send_meta(payload.copy(), meta, (meta.host, meta.port)) for meta in server_metas: self.send_meta(payload.copy(), meta)
def _issue_revocation(self, if_id): """ Store a RevocationInfo in ZK and send a revocation to all BRs. :param if_id: The interface that needs to be revoked. :type if_id: int """ # Only the master BS issues revocations. if not self.zk.have_lock(): return rev_info = self._get_ht_proof(if_id) logging.error("Issuing revocation for IF %d.", if_id) # Issue revocation to all BRs. info = IFStateInfo.from_values(if_id, False, rev_info) pld = IFStatePayload.from_values([info]) for br in self.topology.get_all_border_routers(): meta = UDPMetadata.from_values(host=br.addr, port=br.port) self.send_meta(pld.copy(), meta, (br.addr, br.port)) self._process_revocation(rev_info) self._send_rev_to_local_ps(rev_info)
def _issue_revocation(self, if_id): """ Store a RevocationInfo in ZK and send a revocation to all BRs. :param if_id: The interface that needs to be revoked. :type if_id: int """ # Only the master BS issues revocations. if not self.zk.have_lock(): return rev_info = self._get_ht_proof(if_id) logging.info("Issuing revocation: %s", rev_info.short_desc()) if self._labels: REVOCATIONS_ISSUED.labels(**self._labels).inc() # Issue revocation to all BRs. info = IFStateInfo.from_values(if_id, False, rev_info) pld = IFStatePayload.from_values([info]) for br in self.topology.border_routers: br_addr, br_port = br.int_addrs[0].public[0] meta = UDPMetadata.from_values(host=br_addr, port=br_port) self.send_meta(pld.copy(), meta, (br_addr, br_port)) self._process_revocation(rev_info) self._send_rev_to_local_ps(rev_info)
def _send_ifstate_update(self, state_infos, server_metas): payload = CtrlPayload(PathMgmt( IFStatePayload.from_values(state_infos))) for meta in server_metas: logging.debug("IFState update to %s:%s", meta.host, meta.port) self.send_meta(payload.copy(), meta)