Beispiel #1
0
    def get_dbs(self, client: OpenrCtrl.Client,
                area: str) -> Tuple[Dict, Dict, Dict]:
        # get LSDB from Decision
        decision_adj_dbs = client.getDecisionAdjacencyDbs()
        decision_prefix_dbs = client.getDecisionPrefixDbs()

        area = utils.get_area_id(client, area)
        # get LSDB from KvStore
        params = kv_store_types.KeyDumpParams(Consts.ALL_DB_MARKER)
        params.keys = [Consts.ALL_DB_MARKER]
        if area is None:
            kvstore_keyvals = client.getKvStoreKeyValsFiltered(params).keyVals
        else:
            kvstore_keyvals = client.getKvStoreKeyValsFilteredArea(
                params, area).keyVals

        return (decision_adj_dbs, decision_prefix_dbs, kvstore_keyvals)
Beispiel #2
0
    def _run(self, client: OpenrCtrl.Client, src: str, dst: str,
             max_hop: int) -> None:
        if not src or not dst:
            host_id = utils.get_connected_node_name(self.cli_opts)
            src = src or host_id
            dst = dst or host_id

        # Get prefix_dbs from KvStore
        self.prefix_dbs = {}
        pub = client.getKvStoreKeyValsFiltered(
            kv_store_types.KeyDumpParams(Consts.PREFIX_DB_MARKER))
        for v in pub.keyVals.values():
            prefix_db = deserialize_thrift_object(v.value,
                                                  lsdb_types.PrefixDatabase)
            self.prefix_dbs[prefix_db.thisNodeName] = prefix_db

        paths = self.get_paths(client, src, dst, max_hop)
        self.print_paths(paths)
    def dump_key_with_prefix(self, prefix=""):
        '''  dump the hashes of kvstore whose key matches the given prefix
             if prefix is an empty string, the full KV hash is dumped
        '''

        req_msg = kv_store_types.Request(kv_store_types.Command.HASH_DUMP)
        req_msg.keyDumpParams = kv_store_types.KeyDumpParams(prefix)
        self._kv_store_cmd_socket.send_thrift_obj(req_msg)

        resp = self._kv_store_cmd_socket.recv()
        if len(resp) == 3 and resp == str('ERR'):
            # KvStore doesn't support HASH_DUMP API yet. Use full dump
            # API instead
            return self.dump_all_with_prefix(prefix)
        else:
            return serializer.deserialize_thrift_object(
                resp, kv_store_types.Publication,
                self._kv_store_cmd_socket.proto_factory)
Beispiel #4
0
    def buildKvStoreKeyDumpParams(
        self,
        prefix: str = Consts.ALL_DB_MARKER,
        originator_ids: Optional[List[str]] = None,
        keyval_hash: Optional[Dict[str, kv_store_types.Value]] = None,
    ) -> kv_store_types.KeyDumpParams:
        """
        Build KeyDumpParams based on input parameter list
        """
        params = kv_store_types.KeyDumpParams(prefix)
        params.originatorIds = []
        params.keyValHashes = None

        if originator_ids:
            params.originatorIds = originator_ids
        if keyval_hash:
            params.keyValHashes = keyval_hash

        return params
Beispiel #5
0
    def dump_all_with_filter(
        self,
        prefix: str = "",
        originator_ids: Optional[List[str]] = None,
        keyval_hash: Optional[Dict[str, kv_store_types.Value]] = None,
    ):
        """  dump the entries of kvstore whose key matches the given prefix
             if prefix is an empty string, the full KV store is dumped
        """

        req_msg = kv_store_types.Request(kv_store_types.Command.KEY_DUMP)
        req_msg.keyDumpParams = kv_store_types.KeyDumpParams(prefix)
        req_msg.keyDumpParams.originatorIds = []
        req_msg.keyDumpParams.keyValHashes = None
        if originator_ids:
            req_msg.keyDumpParams.originatorIds = originator_ids
        if keyval_hash:
            req_msg.keyDumpParams.keyValHashes = keyval_hash

        return self.send_and_recv_thrift_obj(req_msg, kv_store_types.Publication)
Beispiel #6
0
    def _run(self, client: OpenrCtrl.Client, src: str, dst: str, max_hop: int,
             area: str) -> None:
        if not src or not dst:
            host_id = client.getMyNodeName()
            src = src or host_id
            dst = dst or host_id

        self.prefix_dbs: Dict[str, lsdb_types.PrefixDatabase] = {}
        area = utils.get_area_id(client, area)
        # Get prefix_dbs from KvStore

        params = kv_store_types.KeyDumpParams(Consts.PREFIX_DB_MARKER)
        params.keys = [Consts.PREFIX_DB_MARKER]
        if area is None:
            pub = client.getKvStoreKeyValsFiltered(params)
        else:
            pub = client.getKvStoreKeyValsFilteredArea(params, area)
        for value in pub.keyVals.values():
            utils.parse_prefix_database("", "", self.prefix_dbs, value)

        paths = self.get_paths(client, src, dst, max_hop)
        self.print_paths(paths)