示例#1
0
    def run(self, prefixes: List[str], labels: List[int], json_opt: bool = False):
        routes = []
        mpls_routes = []

        try:
            routes = self.client.getRouteTableByClient(self.client.client_id)
        except Exception as e:
            print("Failed to get routes from Fib.")
            print("Exception: {}".format(e))
            return 1

        host_id = utils.get_connected_node_name(self.cli_opts)
        client_id = self.client.client_id

        try:
            mpls_routes = self.client.getMplsRouteTableByClient(self.client.client_id)
        except platform_types.PlatformError as e:
            print("Pls check Open/R version. Exception: {}".format(e))

        if json_opt:
            utils.print_json(
                utils.get_routes_json(
                    host_id, client_id, routes, prefixes, mpls_routes, labels
                )
            )
        else:
            caption = f"{host_id}'s FIB routes by client {client_id}"
            utils.print_unicast_routes(caption, routes, prefixes)
            caption = f"{host_id}'s MPLS routes by client {client_id}"
            utils.print_mpls_routes(caption, mpls_routes, labels)

        return 0
示例#2
0
 def run(self, src, dst, max_hop):
     if not src or not dst:
         host_id = utils.get_connected_node_name(self.host,
                                                 self.lm_cmd_port)
         src = src or host_id
         dst = dst or host_id
     paths = self.get_paths(self.client, src, dst, max_hop)
     self.print_paths(paths)
示例#3
0
    def run(self, prefixes):
        try:
            routes = self.client.getKernelRouteTable()
        except Exception as e:
            print('Failed to get routes from Fib.')
            print('Exception: {}'.format(e))
            sys.exit(1)

        host_id = utils.get_connected_node_name(self.client.host, self.lm_cmd_port)
        caption = '{}\'s kernel routes'.format(host_id)
        utils.print_routes(caption, routes, prefixes)
示例#4
0
    def print_counters(self, counters):
        ''' print the Fib counters '''

        host_id = utils.get_connected_node_name(self.client.host, self.lm_cmd_port)
        caption = '{}\'s Fib counters'.format(host_id)

        rows = []
        for key in counters:
            rows.append(['{} : {}'.format(key, counters[key])])
        print(printing.render_horizontal_table(rows, caption=caption, tablefmt='plain'))
        print()
示例#5
0
文件: fib.py 项目: gitpop/openr-xr
    def run(self):
        try:
            routes = self.client.getRouteTableByClient(self.client.client_id)
        except Exception as e:
            print('Failed to get routes from Fib.')
            print('Exception: {}'.format(e))
            sys.exit(1)

        host_id = utils.get_connected_node_name(self.client.host,
                                                self.lm_cmd_port)
        caption = '{}\'s FIB routes by client {}'.format(
            host_id, self.client.client_id)
        print_routes(caption, routes)
示例#6
0
    def config(ctx, config_store_url, verbose):  # noqa: B902
        ''' CLI tool to peek into Config Store module. '''

        config_store_url = config_store_url or "{}_{}".format(
            Consts.CONFIG_STORE_URL_PREFIX,
            utils.get_connected_node_name(
                ctx.obj.hostname,
                ctx.obj.ports_config.get('lm_cmd_port', None)
                or Consts.LINK_MONITOR_CMD_PORT))

        override_url = ctx.obj.ports_config.get('config_store_url', None)
        ctx.obj = ConfigContext(verbose, zmq.Context(), ctx.obj.timeout,
                                override_url or config_store_url)
示例#7
0
    def print_peers(self, peers: kv_store_types.PeersMap) -> None:
        """ print the Kv Store peers """

        host_id = utils.get_connected_node_name(self.cli_opts)
        caption = "{}'s peers".format(host_id)

        rows = []
        for (key, value) in sorted(peers.items(), key=lambda x: x[0]):
            row = [key]
            row.append("cmd via {}".format(value.cmdUrl))
            row.append("pub via {}".format(value.pubUrl))
            rows.append(row)

        print(printing.render_vertical_table(rows, caption=caption))
示例#8
0
    def print_peers(self, peers_reply):
        ''' print the Kv Store peers '''

        host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port)
        caption = '{}\'s peers'.format(host_id)

        rows = []
        for (key, value) in sorted(peers_reply.peers.items(), key=lambda x: x[0]):
            row = [key]
            row.append('cmd via {}'.format(value.cmdUrl))
            row.append('pub via {}'.format(value.pubUrl))
            row.append('Public Key: {}'.format(value.publicKey.encode("hex")))
            rows.append(row)

        print(printing.render_vertical_table(rows, caption=caption))
示例#9
0
文件: decision.py 项目: MOYUMax/openr
    def run(self, src, dst, max_hop):
        if not src or not dst:
            host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port)
            src = src or host_id
            dst = dst or host_id

        # Get prefix_dbs from KvStore
        self.prefix_dbs = {}
        pub = self.kvstore_client.dump_all_with_filter(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(src, dst, max_hop)
        self.print_paths(paths)
示例#10
0
    def print_peers(self, peers_reply):
        """ print the Kv Store peers """

        host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port)
        caption = "{}'s peers".format(host_id)

        rows = []
        for (key, value) in sorted(peers_reply.peers.items(),
                                   key=lambda x: x[0]):
            row = [key]
            row.append("cmd via {}".format(value.cmdUrl))
            row.append("pub via {}".format(value.pubUrl))
            rows.append(row)

        print(printing.render_vertical_table(rows, caption=caption))
示例#11
0
文件: fib.py 项目: shadowkun/openr
    def print_counters(self, counters, json_opt):
        """ print the Fib counters """

        host_id = utils.get_connected_node_name(self.cli_opts)
        caption = "{}'s Fib counters".format(host_id)

        if json_opt:
            utils.print_json(counters)
        else:
            rows = []
            for key in counters:
                rows.append(["{} : {}".format(key, counters[key])])
            print(
                printing.render_horizontal_table(rows,
                                                 caption=caption,
                                                 tablefmt="plain"))
            print()
示例#12
0
    def print_counters(self, resp, prefix):
        ''' print the Kv Store counters '''

        host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port)
        caption = '{}\'s counters'.format(host_id)

        rows = []
        for key, counter in sorted(resp.counters.items()):
            if not key.startswith(prefix):
                continue
            rows.append(['{} : {}'.format(key, counter.value)])

        print(
            printing.render_horizontal_table(rows,
                                             caption=caption,
                                             tablefmt='plain'))
        print()
示例#13
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)
示例#14
0
文件: fib.py 项目: shadowkun/openr
    def run(self, prefixes, json_opt=False):
        try:
            routes = self.client.getRouteTableByClient(self.client.client_id)
        except Exception as e:
            print("Failed to get routes from Fib.")
            print("Exception: {}".format(e))
            return 1

        host_id = utils.get_connected_node_name(self.cli_opts)
        client_id = self.client.client_id

        if json_opt:
            utils.print_json(
                utils.get_routes_json(host_id, client_id, routes, prefixes))
        else:
            caption = "{}'s FIB routes by client {}".format(host_id, client_id)
            utils.print_unicast_routes(caption, routes, prefixes)

        return 0
示例#15
0
    def run(self, prefixes, json_opt=False):
        try:
            routes = self.client.getRouteTableByClient(self.client.client_id)
        except Exception as e:
            print('Failed to get routes from Fib.')
            print('Exception: {}'.format(e))
            return 1

        host_id = utils.get_connected_node_name(self.client.host, self.lm_cmd_port)
        client_id = self.client.client_id

        if json_opt:
            utils.print_json(utils.get_routes_json(
                host_id, client_id, routes, prefixes))
        else:
            caption = '{}\'s FIB routes by client {}'.format(host_id, client_id)
            utils.print_routes(caption, routes, prefixes)

        return 0
示例#16
0
    def run(self, nodes):
        if nodes:
            nodes = set(nodes.strip().split(','))
            if 'all' in nodes:
                nodes = self.get_node_list()
            host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port)
            if host_id in nodes:
                nodes.remove(host_id)

            our_kvs = self.client.dump_all_with_prefix().keyVals
            kv_dict = self.dump_nodes_kvs(nodes)
            for node in kv_dict:
                self.compare(our_kvs, kv_dict[node], host_id, node)

        else:
            nodes = self.get_node_list()
            kv_dict = self.dump_nodes_kvs(nodes)
            for our_node, other_node in combinations(kv_dict.keys(), 2):
                self.compare(kv_dict[our_node], kv_dict[other_node],
                             our_node, other_node)
示例#17
0
文件: kvstore.py 项目: nitinics/openr
    def run(self, nodes):
        all_nodes_to_ips = self.get_node_to_ips()
        if nodes:
            nodes = set(nodes.strip().split(","))
            if "all" in nodes:
                nodes = list(all_nodes_to_ips.keys())
            host_id = utils.get_connected_node_name(self.cli_opts)
            if host_id in nodes:
                nodes.remove(host_id)

            our_kvs = self.client.dump_all_with_filter().keyVals
            kv_dict = self.dump_nodes_kvs(nodes, all_nodes_to_ips)
            for node in kv_dict:
                self.compare(our_kvs, kv_dict[node], host_id, node)

        else:
            nodes = list(all_nodes_to_ips.keys())
            kv_dict = self.dump_nodes_kvs(nodes, all_nodes_to_ips)
            for our_node, other_node in combinations(kv_dict.keys(), 2):
                self.compare(kv_dict[our_node], kv_dict[other_node], our_node,
                             other_node)
示例#18
0
    def print_counters(self, resp, prefix, is_json):
        """ print the Kv Store counters """

        host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port)
        caption = "{}'s counters".format(host_id)

        rows = []
        for key, counter in sorted(resp.counters.items()):
            if not key.startswith(prefix):
                continue
            rows.append([key, ":", counter.value])

        if is_json:
            json_data = {k: v for k, _, v in rows}
            print(utils.json_dumps(json_data))
        else:
            print(
                printing.render_horizontal_table(rows,
                                                 caption=caption,
                                                 tablefmt="plain"))
            print()
示例#19
0
    def print_counters(self, resp: Dict, prefix: str, json: bool) -> None:
        """ print the Kv Store counters """

        host_id = utils.get_connected_node_name(self.cli_opts)
        caption = "{}'s counters".format(host_id)

        rows = []
        for key, counter in sorted(resp.items()):
            if not key.startswith(prefix):
                continue
            rows.append([key, ":", counter])

        if json:
            json_data = {k: v for k, _, v in rows}
            print(utils.json_dumps(json_data))
        else:
            print(
                printing.render_horizontal_table(
                    rows, caption=caption, tablefmt="plain"
                )
            )
            print()
示例#20
0
    def _run(self, client: OpenrCtrl.Client, nodes: set) -> None:
        all_nodes_to_ips = self.get_node_to_ips(client)
        if nodes:
            nodes = set(nodes.strip().split(","))
            if "all" in nodes:
                nodes = list(all_nodes_to_ips.keys())
            host_id = utils.get_connected_node_name(self.cli_opts)
            if host_id in nodes:
                nodes.remove(host_id)

            keyDumpParams = self.buildKvStoreKeyDumpParams(
                Consts.ALL_DB_MARKER)
            pub = client.getKvStoreKeyValsFiltered(keyDumpParams)
            kv_dict = self.dump_nodes_kvs(nodes, all_nodes_to_ips)
            for node in kv_dict:
                self.compare(pub.keyVals, kv_dict[node], host_id, node)

        else:
            nodes = list(all_nodes_to_ips.keys())
            kv_dict = self.dump_nodes_kvs(nodes, all_nodes_to_ips)
            for our_node, other_node in combinations(kv_dict.keys(), 2):
                self.compare(kv_dict[our_node], kv_dict[other_node], our_node,
                             other_node)
示例#21
0
 def run(self):
     resp = self.client.dump_all_with_filter(prefix=Consts.PREFIX_DB_MARKER)
     host_id = utils.get_connected_node_name(self.cli_opts)
     self.print_kvstore_nodes(resp, host_id)
示例#22
0
 def run(self):
     resp = self.client.dump_all_with_prefix(Consts.PREFIX_DB_MARKER)
     host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port)
     self.print_kvstore_nodes(resp, host_id)
示例#23
0
 def _run(self, client: OpenrCtrl.Client) -> None:
     keyDumpParams = self.buildKvStoreKeyDumpParams(Consts.PREFIX_DB_MARKER)
     resp = client.getKvStoreKeyValsFiltered(keyDumpParams)
     host_id = utils.get_connected_node_name(self.cli_opts)
     self.print_kvstore_nodes(resp, host_id)