コード例 #1
0
ファイル: kvstore.py プロジェクト: schijioke-uche/openr
    def _run(self, client: OpenrCtrl.Client) -> None:
        if not self.area_feature:
            super()._run(client)
            return

        all_kv = kv_store_types.Publication()
        all_kv.keyVals = {}
        node_area = {}
        nodes = set()
        for area in self.areas:
            prefix_keys = client.getKvStoreKeyValsFilteredArea(
                self.buildKvStoreKeyDumpParams(Consts.PREFIX_DB_MARKER), area
            )
            all_kv.keyVals.update(prefix_keys.keyVals)
            adj_keys = client.getKvStoreKeyValsFilteredArea(
                self.buildKvStoreKeyDumpParams(Consts.ADJ_DB_MARKER), area
            )
            host_id = client.getMyNodeName()
            node_set = self.get_connected_nodes(adj_keys, host_id)
            # save area associated with each node
            for node in node_set:
                node_area[node] = area
            nodes.update(node_set)

        self.print_kvstore_nodes(nodes, all_kv, host_id, node_area)
コード例 #2
0
ファイル: decision.py プロジェクト: edi2212/openr
    def _run(
        self,
        client: OpenrCtrl.Client,
        src: str,
        dst: str,
        max_hop: int,
        area: str,
        *args,
        **kwargs,
    ) -> None:
        if not src or not dst:
            host_id = client.getMyNodeName()
            src = src or host_id
            dst = dst or host_id

        # pyre-fixme[16]: `PathCmd` has no attribute `prefix_dbs`.
        self.prefix_dbs: Dict[str, openr_types.PrefixDatabase] = {}
        area = utils.get_area_id(client, area)
        # Get prefix_dbs from KvStore

        params = openr_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)
コード例 #3
0
ファイル: kvstore.py プロジェクト: wlm328cs/openr
    def _run(self, client: OpenrCtrl.Client, nodes: set) -> None:
        area = self.get_area_id()

        all_nodes_to_ips = self.get_node_to_ips(client, area)
        if nodes:
            nodes = set(nodes.strip().split(","))
            if "all" in nodes:
                nodes = list(all_nodes_to_ips.keys())
            host_id = client.getMyNodeName()
            if host_id in nodes:
                nodes.remove(host_id)

            keyDumpParams = self.buildKvStoreKeyDumpParams(
                Consts.ALL_DB_MARKER)
            pub = None
            if not self.area_feature:
                pub = client.getKvStoreKeyValsFiltered(keyDumpParams)
            else:
                pub = client.getKvStoreKeyValsFilteredArea(keyDumpParams, area)
            kv_dict = self.dump_nodes_kvs(nodes, all_nodes_to_ips, area)
            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, area)
            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)
コード例 #4
0
ファイル: kvstore.py プロジェクト: wlm328cs/openr
    def _run(self, client: OpenrCtrl.Client, nodes: set, bidir: bool,
             json: bool) -> None:
        if not self.area_feature:
            super()._run(client, nodes, bidir, json)
            return

        publications = {}
        for area in self.areas:
            keyDumpParams = self.buildKvStoreKeyDumpParams(
                Consts.ADJ_DB_MARKER)
            publications[area] = client.getKvStoreKeyValsFilteredArea(
                keyDumpParams, area)
        self.print_adj(publications, nodes, bidir, json)
コード例 #5
0
ファイル: kvstore.py プロジェクト: wlm328cs/openr
    def _run(self, client: OpenrCtrl.Client, nodes: set, node: Any,
             interface: Any) -> None:
        if not self.area_feature:
            super()._run(client, nodes, interface)
            return

        keyDumpParams = self.buildKvStoreKeyDumpParams(Consts.ADJ_DB_MARKER)
        resp = openr_types.Publication()
        resp.keyVals = {}
        for area in self.areas:
            publication = client.getKvStoreKeyValsFilteredArea(
                keyDumpParams, area)
            resp.keyVals.update(publication.keyVals)
        self.printAdjNode(resp, nodes, node, interface)
コード例 #6
0
ファイル: decision.py プロジェクト: qmiinh/openr
    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 = openr_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)
コード例 #7
0
ファイル: kvstore.py プロジェクト: wlm328cs/openr
 def _run(
     self,
     client: OpenrCtrl.Client,
     nodes: set,
     json: bool,
     prefix: str = "",
     client_type: str = "",
 ) -> None:
     if not self.area_feature:
         super()._run(client, nodes, json, prefix, client_type)
         return
     keyDumpParams = self.buildKvStoreKeyDumpParams(Consts.PREFIX_DB_MARKER)
     area_kv = {}
     for area in self.areas:
         resp = client.getKvStoreKeyValsFilteredArea(keyDumpParams, area)
         area_kv[area] = resp
     self.print_prefix(area_kv, nodes, json, prefix, client_type)
コード例 #8
0
ファイル: kvstore.py プロジェクト: schijioke-uche/openr
    def get_node_to_ips(self, client: OpenrCtrl.Client, area: str = None) -> Dict:
        """ get the dict of all nodes to their IP in the network """

        node_dict = {}
        keyDumpParams = self.buildKvStoreKeyDumpParams(Consts.PREFIX_DB_MARKER)
        resp = kv_store_types.Publication()
        if not self.area_feature:
            resp = client.getKvStoreKeyValsFiltered(keyDumpParams)
        else:
            if area is None:
                print(f"Error: Must specify one of the areas: {self.areas}")
                sys.exit(1)
            resp = client.getKvStoreKeyValsFilteredArea(keyDumpParams, area)

        prefix_maps = utils.collate_prefix_keys(resp.keyVals)
        for node, prefix_db in prefix_maps.items():
            node_dict[node] = self.get_node_ip(prefix_db)

        return node_dict
コード例 #9
0
ファイル: kvstore.py プロジェクト: wlm328cs/openr
    def _run(
        self,
        client: OpenrCtrl.Client,
        json: bool,
        prefix: Any,
        originator: Any = None,
        ttl: bool = False,
    ) -> None:
        if not self.area_feature:
            super()._run(client, json, prefix, originator, ttl)
            return

        keyDumpParams = self.buildKvStoreKeyDumpParams(
            prefix, [originator] if originator else None)

        area_kv = {}
        for area in self.areas:
            resp = client.getKvStoreKeyValsFilteredArea(keyDumpParams, area)
            area_kv[area] = resp

        self.print_kvstore_keys(area_kv, ttl, json)
コード例 #10
0
ファイル: decision.py プロジェクト: mrinaldhillon/openr
    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(self.cli_opts, area)
        # Get prefix_dbs from KvStore
        if area is None:
            pub = client.getKvStoreKeyValsFiltered(
                kv_store_types.KeyDumpParams(Consts.PREFIX_DB_MARKER))
        else:
            pub = client.getKvStoreKeyValsFilteredArea(
                kv_store_types.KeyDumpParams(Consts.PREFIX_DB_MARKER), 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)
コード例 #11
0
ファイル: kvstore.py プロジェクト: schijioke-uche/openr
    def _run(
        self,
        client: OpenrCtrl.Client,
        node: str,
        bidir: bool,
        output_file: str,
        edge_label: Any,
        json: bool,
    ) -> None:
        area = self.get_area_id()

        try:
            import matplotlib.pyplot as plt
            import networkx as nx
        except ImportError:
            print(
                "Drawing topology requires `matplotlib` and `networkx` "
                "libraries. You can install them with following command and "
                "retry. \n"
                "  pip install matplotlib\n"
                "  pip install networkx"
            )
            sys.exit(1)

        rem_str = {".facebook.com": "", ".tfbnw.net": ""}
        rem_str = dict((re.escape(k), v) for k, v in rem_str.items())
        rem_pattern = re.compile("|".join(rem_str.keys()))

        keyDumpParams = self.buildKvStoreKeyDumpParams(Consts.ADJ_DB_MARKER)
        publication = None
        if area is None:
            publication = client.getKvStoreKeyValsFiltered(keyDumpParams)
        else:
            publication = client.getKvStoreKeyValsFilteredArea(keyDumpParams, area)
        nodes = list(self.get_node_to_ips(client, area).keys()) if not node else [node]
        adjs_map = utils.adj_dbs_to_dict(
            publication, nodes, bidir, self.iter_publication
        )

        if json:
            return self.topology_json_dump(adjs_map.items())

        G = nx.Graph()
        adj_metric_map = {}
        node_overloaded = {}

        for this_node_name, db in adjs_map.items():
            node_overloaded[
                rem_pattern.sub(
                    lambda m: rem_str[re.escape(m.group(0))], this_node_name
                )
            ] = db["overloaded"]
            for adj in db["adjacencies"]:
                adj_metric_map[(this_node_name, adj["ifName"])] = adj["metric"]

        for this_node_name, db in adjs_map.items():
            for adj in db["adjacencies"]:
                adj["color"] = "r" if adj["isOverloaded"] else "b"
                adj["adjOtherIfMetric"] = adj_metric_map[
                    (adj["otherNodeName"], adj["otherIfName"])
                ]
                G.add_edge(
                    rem_pattern.sub(
                        lambda m: rem_str[re.escape(m.group(0))], this_node_name
                    ),
                    rem_pattern.sub(
                        lambda m: rem_str[re.escape(m.group(0))], adj["otherNodeName"]
                    ),
                    **adj,
                )

        # hack to get nice fabric
        # XXX: FB Specific
        pos = {}
        eswx = 0
        sswx = 0
        fswx = 0
        rswx = 0
        blue_nodes = []
        red_nodes = []
        for node in G.nodes():
            if node_overloaded[node]:
                red_nodes.append(node)
            else:
                blue_nodes.append(node)

            if "esw" in node:
                pos[node] = [eswx, 3]
                eswx += 10
            elif "ssw" in node:
                pos[node] = [sswx, 2]
                sswx += 10
            elif "fsw" in node:
                pos[node] = [fswx, 1]
                fswx += 10
            elif "rsw" in node:
                pos[node] = [rswx, 0]
                rswx += 10

        maxswx = max(eswx, sswx, fswx, rswx)
        if maxswx > 0:
            # aesthetically pleasing multiplier (empirically determined)
            plt.figure(figsize=(maxswx * 0.5, 8))
        else:
            plt.figure(
                figsize=(min(len(G.nodes()) * 2, 150), min(len(G.nodes()) * 2, 150))
            )
            pos = nx.spring_layout(G)
        plt.axis("off")

        edge_colors = []
        for _, _, d in G.edges(data=True):
            edge_colors.append(d["color"])

        nx.draw_networkx_nodes(
            G, pos, ax=None, alpha=0.5, node_color="b", nodelist=blue_nodes
        )
        nx.draw_networkx_nodes(
            G, pos, ax=None, alpha=0.5, node_color="r", nodelist=red_nodes
        )
        nx.draw_networkx_labels(G, pos, ax=None, alpha=0.5, font_size=8)
        nx.draw_networkx_edges(
            G, pos, ax=None, alpha=0.5, font_size=8, edge_color=edge_colors
        )
        edge_labels = {}
        if node:
            if edge_label:
                edge_labels = {
                    (u, v): "<"
                    + str(d["otherIfName"])
                    + ",  "
                    + str(d["metric"])
                    + " >     <"
                    + str(d["ifName"])
                    + ", "
                    + str(d["adjOtherIfMetric"])
                    + ">"
                    for u, v, d in G.edges(data=True)
                }
            nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=6)

        print("Saving topology to file => {}".format(output_file))
        plt.savefig(output_file)