Merging all pull requests into one

This commit is contained in:
Landry JUGE 2025-04-21 00:17:02 +02:00
3 changed files with 64 additions and 16 deletions

View File

@ -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}

View File

@ -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

View File

@ -24,14 +24,15 @@ import re
import tempfile
import textfsm
import vyattaconfparser
try:
import logging
logger = logging.getLogger("peering.manager.peering")
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
@ -460,7 +461,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")
@ -499,6 +500,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 +533,15 @@ 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)