From 01c02019d0004c19244573a7e77f354bebd57caa Mon Sep 17 00:00:00 2001 From: Hanarion Date: Sun, 20 Apr 2025 22:48:01 +0200 Subject: [PATCH 1/5] Fix BGP summary template for recent versions of VyOS --- napalm_vyos/templates/bgp_sum.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/napalm_vyos/templates/bgp_sum.template b/napalm_vyos/templates/bgp_sum.template index 023967e..c67194a 100644 --- a/napalm_vyos/templates/bgp_sum.template +++ b/napalm_vyos/templates/bgp_sum.template @@ -14,7 +14,7 @@ Value Required PREFIX_SENT (\d+) Value Required DESCRIPTION (.+) Start - ^BGP router identifier ${BGP_ROUTER_ID}, local AS number ${LOCAL_AS} vrf-id ${VRF_ID} -> Neighbors + ^BGP router identifier ${BGP_ROUTER_ID}, local AS number ${LOCAL_AS} .* vrf-id ${VRF_ID} -> Neighbors Neighbors ^Neighbor\s+V\s+AS\s+MsgRcvd\s+MsgSent\s+TblVer\s+InQ\s+OutQ\s+Up/Down\s+State/PfxRcd\s+PfxSnt\s+Desc -> PeerLine From 4b7c9146331e3037ea72e11c668ee95e8ffa4d4d Mon Sep 17 00:00:00 2001 From: Hanarion Date: Sun, 20 Apr 2025 22:51:18 +0200 Subject: [PATCH 2/5] Allows for using the module without peering-manager --- napalm_vyos/vyos.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/napalm_vyos/vyos.py b/napalm_vyos/vyos.py index 268315e..627fd62 100644 --- a/napalm_vyos/vyos.py +++ b/napalm_vyos/vyos.py @@ -24,14 +24,15 @@ import re import tempfile import textfsm import vyattaconfparser +try: + import logging + logger = logging.getLogger("peering.manager.peering") -import logging -logger = logging.getLogger("peering.manager.peering") - -from django.core.cache import cache - -cache.clear() + from django.core.cache import cache + cache.clear() +except Exception: + pass # NAPALM base import napalm.base.constants as C from napalm.base.base import NetworkDriver From 2a32bdf380cc965e13a3b89d942e23dd3184924c Mon Sep 17 00:00:00 2001 From: Hanarion Date: Sun, 20 Apr 2025 23:10:39 +0200 Subject: [PATCH 3/5] Fix IPv6 neigbour informations --- napalm_vyos/vyos.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/napalm_vyos/vyos.py b/napalm_vyos/vyos.py index 268315e..22ddc1e 100644 --- a/napalm_vyos/vyos.py +++ b/napalm_vyos/vyos.py @@ -460,7 +460,7 @@ class VyOSDriver(NetworkDriver): 192.168.1.4 4 64522 0 0 0 0 0 never Active """ - output = self.device.send_command("show ip bgp summary") + output = self.device.send_command("show bgp summary") current_dir = os.path.dirname(os.path.abspath(__file__)) template_path = os.path.join(current_dir, "templates", "bgp_sum.template") @@ -513,7 +513,7 @@ class VyOSDriver(NetworkDriver): for neighbor in neighbors["global"]["peers"]: - output = self.device.send_command(f"show ip bgp neighbor {neighbor}") + output = self.device.send_command(f"show bgp neighbor {neighbor}") current_dir = os.path.dirname(os.path.abspath(__file__)) template_path = os.path.join( @@ -542,7 +542,7 @@ class VyOSDriver(NetworkDriver): "remote_as": int(neighbor_detail["REMOTE_AS"]), "router_id": neighbor_detail["LOCAL_ROUTER_ID"], "local_address": neighbor_detail[ - "LOCAL_ROUTER_ID" + "LOCAL_HOST" ], # Adjusted from LOCAL_ROUTER_ID based on context "routing_table": f"IPv{neighbor_detail['BGP_VERSION']} Unicast", # Constructed value "local_address_configured": bool(neighbor_detail["LOCAL_ROUTER_ID"]), From 56e8ddcb354e22968320ad7e973b13458d708f90 Mon Sep 17 00:00:00 2001 From: Hanarion Date: Mon, 21 Apr 2025 00:09:47 +0200 Subject: [PATCH 4/5] Fix the prefix counts on VyOS, using the prefix count command and a new template --- napalm_vyos/vyos.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/napalm_vyos/vyos.py b/napalm_vyos/vyos.py index 268315e..80ed023 100644 --- a/napalm_vyos/vyos.py +++ b/napalm_vyos/vyos.py @@ -499,6 +499,26 @@ class VyOSDriver(NetworkDriver): return bgp_neighbor_data + def get_bgp_neighbor_prefix_counts(self, neighbor_address): + output = self.device.send_command(f"show bgp {self._get_ip_version(neighbor_address)} neighbor {neighbor_address} prefix-counts") + + current_dir = os.path.dirname(os.path.abspath(__file__)) + template_path = os.path.join( + current_dir, "templates", "bgp_prefix_counts.template" + ) + + with open(template_path) as template_file: + fsm = textfsm.TextFSM(template_file) + result = fsm.ParseText(output) + + if not result: + return {} + + neighbor_dict = dict(zip(fsm.header, result[0])) + + + return neighbor_dict + def get_bgp_neighbors_detail(self, neighbor_address=""): def safe_int(value, default=0): @@ -512,14 +532,16 @@ class VyOSDriver(NetworkDriver): neighbors = self.get_bgp_neighbors() for neighbor in neighbors["global"]["peers"]: - - output = self.device.send_command(f"show ip bgp neighbor {neighbor}") + neighbor_obj = neighbors["global"]["peers"].get(neighbor) + output = self.device.send_command(f"show bgp {self._get_ip_version(neighbor)} neighbor {neighbor}") current_dir = os.path.dirname(os.path.abspath(__file__)) template_path = os.path.join( current_dir, "templates", "bgp_details.template" ) + neighbor_prefix_counts = self.get_bgp_neighbor_prefix_counts(neighbor) + with open(template_path) as template_file: fsm = textfsm.TextFSM(template_file) result = fsm.ParseText(output) @@ -542,7 +564,7 @@ class VyOSDriver(NetworkDriver): "remote_as": int(neighbor_detail["REMOTE_AS"]), "router_id": neighbor_detail["LOCAL_ROUTER_ID"], "local_address": neighbor_detail[ - "LOCAL_ROUTER_ID" + "LOCAL_HOST" ], # Adjusted from LOCAL_ROUTER_ID based on context "routing_table": f"IPv{neighbor_detail['BGP_VERSION']} Unicast", # Constructed value "local_address_configured": bool(neighbor_detail["LOCAL_ROUTER_ID"]), @@ -601,16 +623,16 @@ class VyOSDriver(NetworkDriver): neighbor_detail["CONFIGURED_KEEPALIVE_INTERVAL"] ), "active_prefix_count": int( - neighbor_detail.get("ACTIVE_PREFIX_COUNT", 0) + neighbor_prefix_counts.get("BEST_SELECTED", 0) ), # Assuming ACTIVE_PREFIX_COUNT is available "accepted_prefix_count": int( - neighbor_detail.get("ACCEPTED_PREFIX_COUNT", 0) + neighbor_prefix_counts.get("USEABLE", 0) ), # Assuming ACCEPTED_PREFIX_COUNT is available "suppressed_prefix_count": int( - neighbor_detail.get("SUPPRESSED_PREFIX_COUNT", 0) + neighbor_prefix_counts.get("REMOVED", 0) ), # Assuming SUPPRESSED_PREFIX_COUNT is available "advertised_prefix_count": int( - neighbor_detail.get("ADVERTISED_PREFIX_COUNT", 0) + neighbor_obj.get("advertised_prefix_count", 0) ), "received_prefix_count": safe_int( neighbor_detail.get("RECEIVED_PREFIXES_IPV4", 0) From 3a238987acb7eb4bd33415877b71d5d4f3fa8618 Mon Sep 17 00:00:00 2001 From: Hanarion Date: Mon, 21 Apr 2025 00:10:53 +0200 Subject: [PATCH 5/5] Adding bgp_prefix_counts.template --- .../templates/bgp_prefix_counts.template | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 napalm_vyos/templates/bgp_prefix_counts.template diff --git a/napalm_vyos/templates/bgp_prefix_counts.template b/napalm_vyos/templates/bgp_prefix_counts.template new file mode 100644 index 0000000..e29538c --- /dev/null +++ b/napalm_vyos/templates/bgp_prefix_counts.template @@ -0,0 +1,26 @@ +Value NEIGHBOR_IP (\S+) +Value ADJ_IN (\d+) +Value DAMPED (\d+) +Value REMOVED (\d+) +Value HISTORY (\d+) +Value STALE (\d+) +Value VALID (\d+) +Value ALL_RIB (\d+) +Value PFXCT_COUNTED (\d+) +Value BEST_SELECTED (\d+) +Value USEABLE (\d+) +Value UNSORTED (\d+) + +Start + ^Prefix counts for ${NEIGHBOR_IP}, IPv[4,6] Unicast + ^\s*Adj-in:\s+${ADJ_IN} + ^\s*Damped:\s+${DAMPED} + ^\s*Removed:\s+${REMOVED} + ^\s*History:\s+${HISTORY} + ^\s*Stale:\s+${STALE} + ^\s*Valid:\s+${VALID} + ^\s*All RIB:\s+${ALL_RIB} + ^\s*PfxCt counted:\s+${PFXCT_COUNTED} + ^\s*PfxCt Best Selected:\s+${BEST_SELECTED} + ^\s*Useable:\s+${USEABLE} + ^\s*Unsorted:\s+${UNSORTED}