Skip to content

Commit

Permalink
accomodate bgp-rib model changes introduced in SRL 24.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wdesmedt committed Nov 12, 2024
1 parent d359b01 commit b429046
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 25 deletions.
79 changes: 63 additions & 16 deletions nornir_srl/connections/srlinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ def get_bgp_rib(
raise Exception("Cannot get gNMI capabilities")

BGP_EVPN_VERSION_MAP = {
1: ("20"),
1: ("2021-", "2022-", "2023-", "2024-03", "2024-07"),
2: ("20"),
}
BGP_EVPN_ROUTE_TYPE_MAP = {
1: ("2021-", "2022-", "2023-", "2024-03", "2024-07"),
2: ("20"),
}
BGP_IP_VERSION_MAP = {
1: ("2021-", "2022-"),
Expand All @@ -180,12 +185,21 @@ def get_bgp_rib(
"ipv4": "ipv4-unicast",
"ipv6": "ipv6-unicast",
}
ROUTE_TYPE = {
"1": "ethernet-ad-routes",
"2": "mac-ip-routes",
"3": "imet-routes",
"4": "ethernet-segment-routes",
"5": "ip-prefix-routes",
ROUTE_TYPE_VERSIONS = {
1: {
"1": "ethernet-ad-routes",
"2": "mac-ip-routes",
"3": "imet-routes",
"4": "ethernet-segment-routes",
"5": "ip-prefix-routes",
},
2: {
"1": "ethernet-ad-route",
"2": "mac-ip-route",
"3": "imet-route",
"4": "ethernet-segment-route",
"5": "ip-prefix-route",
},
}

def augment_routes(d, attribs): # augment routes with attributes
Expand Down Expand Up @@ -236,6 +250,13 @@ def augment_routes(d, attribs): # augment routes with attributes
for k, v in sorted(BGP_EVPN_VERSION_MAP.items(), key=lambda item: item[0])
if len([ver for ver in v if mod_version.startswith(ver)]) > 0
][0]
evpn_route_type_version = [
k
for k, v in sorted(
BGP_EVPN_ROUTE_TYPE_MAP.items(), key=lambda item: item[0]
)
if len([ver for ver in v if mod_version.startswith(ver)]) > 0
][0]
ip_path_version = [
k
for k, v in sorted(BGP_IP_VERSION_MAP.items(), key=lambda item: item[0])
Expand All @@ -244,7 +265,10 @@ def augment_routes(d, attribs): # augment routes with attributes

if route_fam not in ROUTE_FAMILY:
raise ValueError(f"Invalid route family {route_fam}")
if route_type and route_type not in ROUTE_TYPE:
if (
route_type
and route_type not in ROUTE_TYPE_VERSIONS[evpn_route_type_version]
):
raise ValueError(f"Invalid route type {route_type}")

PATH_BGP_PATH_ATTRIBS = (
Expand All @@ -257,12 +281,31 @@ def augment_routes(d, attribs): # augment routes with attributes
"RIB_EVPN_PATH": (
"/network-instance[name=" + network_instance + "]/bgp-rib/" # type: ignore
f"{ROUTE_FAMILY[route_fam]}/rib-in-out/rib-in-post/"
f"{ROUTE_TYPE[route_type]}" # type: ignore
f"{ROUTE_TYPE_VERSIONS[evpn_route_type_version][route_type]}" # type: ignore
),
"RIB_EVPN_JMESPATH_COMMON": '"network-instance"[].{NI:name, Rib:"bgp-rib"."'
+ ROUTE_FAMILY[route_fam]
+ '"."rib-in-out"."rib-in-post"."'
+ ROUTE_TYPE[route_type] # type: ignore
+ ROUTE_TYPE_VERSIONS[evpn_route_type_version][route_type] # type: ignore
+ '"[]',
"RIB_EVPN_JMESPATH_ATTRS": {
"1": '.{RD:"route-distinguisher", peer:neighbor, ESI:esi, Tag:"ethernet-tag-id",vni:vni, "NextHop":"next-hop", RT:"_rt", "esi-lbl":"_esi_lbl", "0_st":"_r_state"}}',
"2": '.{RD:"route-distinguisher", RT:"_rt", peer:neighbor, ESI:esi, "MAC":"mac-address", "IP":"ip-address",vni:vni,"next-hop":"next-hop", "0_st":"_r_state"}}',
"3": '.{RD:"route-distinguisher", RT:"_rt", peer:neighbor, Tag:"ethernet-tag-id", "next-hop":"next-hop", origin:origin, "0_st":"_r_state"}}',
"4": '.{RD:"route-distinguisher", RT:"_rt", peer:neighbor, ESI:esi, "next-hop":"next-hop", origin:origin, "0_st":"_r_state"}}',
"5": '.{RD:"route-distinguisher", RT:"_rt", peer:neighbor, lpref:"local-pref", "IP-Pfx":"ip-prefix",vni:vni, med:med, "next-hop":"next-hop", GW:"gateway-ip",origin:origin, "0_st":"_r_state"}}',
},
},
2: {
"RIB_EVPN_PATH": (
"/network-instance[name=" + network_instance + f"]/bgp-rib/afi-safi[afi-safi-name={ROUTE_FAMILY[route_fam]}]/" # type: ignore
f"{ROUTE_FAMILY[route_fam]}/rib-in-out/rib-in-post/"
f"{ROUTE_TYPE_VERSIONS[evpn_route_type_version][route_type]}" # type: ignore
),
"RIB_EVPN_JMESPATH_COMMON": '"network-instance"[].{NI:name, Rib:"bgp-rib"."afi-safi"[]."'
+ ROUTE_FAMILY[route_fam]
+ '"."rib-in-out"."rib-in-post"."'
+ ROUTE_TYPE_VERSIONS[evpn_route_type_version][route_type] # type: ignore
+ '"[]',
"RIB_EVPN_JMESPATH_ATTRS": {
"1": '.{RD:"route-distinguisher", peer:neighbor, ESI:esi, Tag:"ethernet-tag-id",vni:vni, "NextHop":"next-hop", RT:"_rt", "esi-lbl":"_esi_lbl", "0_st":"_r_state"}}',
Expand Down Expand Up @@ -630,9 +673,11 @@ def get_rib(
]

route["_nh_itf"] = [
nh.get("subinterface") + f"@vrf:{nh_ni}"
if leaked
else nh.get("subinterface")
(
nh.get("subinterface") + f"@vrf:{nh_ni}"
if leaked
else nh.get("subinterface")
)
for nh in nhgroup_mapping[nh_ni].get(
route["next-hop-group"], {}
)
Expand Down Expand Up @@ -739,9 +784,11 @@ def set_es_peers(resp):
.get("designated-forwarder-candidate", [])
)
vrf["_peers"] = " ".join(
f"{peer['address']}(DF)"
if peer["designated-forwarder"]
else peer["address"]
(
f"{peer['address']}(DF)"
if peer["designated-forwarder"]
else peer["address"]
)
for peer in es_peers
)
vrf["_ni_peers"] = f"{vrf['name']}:[{vrf['_peers']}]"
Expand Down
7 changes: 4 additions & 3 deletions nornir_srl/fsc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from importlib.metadata import PackageNotFoundError
from typing import Any, Dict, List, Optional, Callable
import importlib
import fnmatch
import sys
import tempfile
import pkg_resources


from ruamel.yaml import YAML

Expand Down Expand Up @@ -58,8 +59,8 @@

def get_project_version():
try:
version = pkg_resources.get_distribution(PYTHON_PKG_NAME).version
except pkg_resources.DistributionNotFound:
version = importlib.metadata.version(PYTHON_PKG_NAME)
except PackageNotFoundError:
version = "Version not found"

return version
Expand Down
27 changes: 23 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[virtualenvs]
in-project = true
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tool.poetry]
name = "nornir-srl"
version = "0.2.19"
version = "0.2.20"
description = "Nornir connection plugin for SRLinux"
authors = ["Walter De Smedt <[email protected]>"]
readme = "README.md"
repository = "https://github.com/srl-labs/nornir-srl"

[tool.poetry.dependencies]
python = "^3.8"
python = "^3.9"
nornir = "^3.3.0"
nornir-utils = "^0.2.0"
pygnmi = "^0.8.9"
Expand All @@ -18,6 +18,7 @@ natsort = "^8.2.0"
jsondiff = "^2.0.0"
click = "^8.1.3"
jmespath = "^1.0.1"
setuptools = "^75.4.0"

[tool.poetry.plugins."nornir.plugins.connections"]
"srlinux" = "nornir_srl.connections.srlinux:SrLinux"
Expand Down

0 comments on commit b429046

Please sign in to comment.