def print_route_db( self, route_db: openr_types.RouteDatabase, prefixes: Optional[List[str]] = None, labels: Optional[List[int]] = None, ) -> None: """ print the routes from Fib module """ if (prefixes or not labels) and len(route_db.unicastRoutes) != 0: utils.print_unicast_routes( caption="", unicast_routes=route_db.unicastRoutes, prefixes=prefixes, element_prefix="+", filter_exact_match=True, timestamp=True, ) if (labels or not prefixes) and len(route_db.mplsRoutes) != 0: utils.print_mpls_routes( caption="", mpls_routes=route_db.mplsRoutes, labels=labels, element_prefix="+", element_suffix="(MPLS)", timestamp=True, )
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
def run( self, prefixes: List[str], labels: List[int] = (), json_opt: bool = False, client_id: Optional[int] = None, ): routes = [] mpls_routes = [] client_id = client_id if client_id is not None else self.client.client_id try: routes = self.client.getRouteTableByClient(client_id) except Exception as e: print("Failed to get routes from Fib.") print("Exception: {}".format(e)) return 1 try: mpls_routes = self.client.getMplsRouteTableByClient(client_id) except Exception: pass if json_opt: utils.print_json( utils.get_routes_json("", client_id, routes, prefixes, mpls_routes, labels)) else: caption = f"FIB routes by client {client_id}" utils.print_unicast_routes(caption, routes, prefixes) caption = f"MPLS routes by client {client_id}" utils.print_mpls_routes(caption, mpls_routes, labels) return 0
def _run(self, client: OpenrCtrl.Client, prefix_or_ip: List[str], json: bool) -> None: unicast_route_list = client.getUnicastRoutesFiltered(prefix_or_ip) host_name = client.getMyNodeName() if json: routes = { "unicastRoutes": [utils.unicast_route_to_dict(r) for r in unicast_route_list] } route_dict = {host_name: routes} utils.print_routes_json(route_dict) else: utils.print_unicast_routes( "Unicast Routes for {}".format(host_name), unicast_route_list)
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
def print_route_db_delta( self, delta_db: openr_types.RouteDatabaseDelta, prefixes: Optional[List[str]] = None, ) -> None: """ print the RouteDatabaseDelta from Fib module """ if len(delta_db.unicastRoutesToUpdate) != 0: utils.print_unicast_routes( caption="", unicast_routes=delta_db.unicastRoutesToUpdate, prefixes=prefixes, element_prefix="+", filter_exact_match=True, timestamp=True, ) if len(delta_db.unicastRoutesToDelete) != 0: self.print_ip_prefixes_filtered( ip_prefixes=delta_db.unicastRoutesToDelete, prefixes_filter=prefixes, element_prefix="-", ) if prefixes: return if len(delta_db.mplsRoutesToUpdate) != 0: utils.print_mpls_routes( caption="", mpls_routes=delta_db.mplsRoutesToUpdate, element_prefix="+", element_suffix="(MPLS)", timestamp=True, ) if len(delta_db.mplsRoutesToDelete) != 0: self.print_mpls_labels( labels=delta_db.mplsRoutesToDelete, element_prefix="-", element_suffix="(MPLS)", )
def run( self, prefixes: List[str], labels: List[int], json_opt: bool = False, client_id: Optional[int] = None, ): routes = [] mpls_routes = [] client_id = client_id if client_id is not None else self.client.client_id try: routes = self.client.getRouteTableByClient(client_id) except Exception as e: print("Failed to get routes from Fib.") print("Exception: {}".format(e)) return 1 with utils.get_openr_ctrl_client(self.cli_opts.host, self.cli_opts) as client: host_id = client.getMyNodeName() try: mpls_routes = self.client.getMplsRouteTableByClient(client_id) except Exception 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