From ae40fb3fe5f39f777aedb395e369a4aaff00dbe0 Mon Sep 17 00:00:00 2001 From: Christian Elsen Date: Mon, 8 Jun 2020 18:16:14 -0700 Subject: [PATCH 1/2] Added support for BGP Large communities with Frr FRR uses separate commands to lookup regular BGP communities (show bgp ipvX unicast community {target}) and BGP large communities (show bgp ipvXunicast large-community {target}). This patch checks whether the provide community is a regular community or a large community and calls the corresponding FRR command. --- hyperglass_frr/execute.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hyperglass_frr/execute.py b/hyperglass_frr/execute.py index ccf4354..7f2cd44 100644 --- a/hyperglass_frr/execute.py +++ b/hyperglass_frr/execute.py @@ -2,6 +2,7 @@ Execute the constructed command """ # Standard Imports +import re import logging import subprocess @@ -24,6 +25,13 @@ def execute(query): logger.debug(f"Received query: {query}") query_type = query.get("query_type") try: + if query_type in ["bgp_community"]: + target = query.get("target") + logger.debug(f'{query_type}: Check for large community {target}') + if re.match("^([0-9]{1,10})\:([0-9]{1,10})\:[0-9]{1,10}$", target): + logger.debug(f'Large community detected.') + query["query_type"] = "bgp_large_community" + command = configuration.Command(query) if query_type in ["bgp_route", "bgp_community", "bgp_aspath"]: logger.debug(f'Running vtysh command "{command}"') @@ -36,5 +44,5 @@ def execute(query): except subprocess.CalledProcessError as error_exception: output = f'Unable to reach {query["target"]}.' status = 504 - logger.debug(f"{output} Error:\n{ping_error}") + logger.debug(f"{output} Ping error:\n") return (output, status) From 4dec7ab70159330508bbb9c6d8fe370cfc67d2ed Mon Sep 17 00:00:00 2001 From: Christian Elsen Date: Mon, 8 Jun 2020 18:20:08 -0700 Subject: [PATCH 2/2] Update configuration.toml.example --- hyperglass_frr/configuration.toml.example | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hyperglass_frr/configuration.toml.example b/hyperglass_frr/configuration.toml.example index 54e355e..907989a 100644 --- a/hyperglass_frr/configuration.toml.example +++ b/hyperglass_frr/configuration.toml.example @@ -6,6 +6,7 @@ key = "1234" [commands.ipv4] bgp_route = "show bgp ipv4 unicast {target}" bgp_community = "show bgp ipv4 unicast community {target}" +bgp_large_community = "show bgp ipv4 unicast large-community {target}" bgp_aspath = "show bgp ipv4 unicast regexp {target}" ping = "ping -4 -c 5 -I {source} {target}" traceroute = "traceroute -4 -w 1 -q 1 -s {source} {target}" @@ -13,6 +14,7 @@ traceroute = "traceroute -4 -w 1 -q 1 -s {source} {target}" [commands.ipv6] bgp_route = "show bgp ipv6 unicast {target}" bgp_community = "show bgp ipv6 unicast community {target}" +bgp_large_community = "show bgp ipv6 unicast large-community {target}" bgp_aspath = "show bgp ipv6 unicast regexp {target}" ping = "ping -6 -c 5 -I {source} {target}" traceroute = "traceroute -6 -w 1 -q 1 -s {source} {target}"