Skip to content

Commit 9e9f088

Browse files
frr: return AS0 if AS_PATH length is zero
Local prefixes usually do not have an AS_PATH: ``` vtysh -c "show bgp ipv4 unicast 10.10.10.10 json" | jq '.paths[].aspath' { "string": "Local", "segments": [], "length": 0 } ``` Set AS0 as a temporary solution when AS_PATH length is zero. This avoids parser failures for local prefixes, though ideally we should use the device's actual ASN (see TODO in code). Signed-off-by: Tan Siewert <[email protected]>
1 parent 590a923 commit 9e9f088

File tree

1 file changed

+9
-1
lines changed
  • hyperglass/models/parsing

1 file changed

+9
-1
lines changed

hyperglass/models/parsing/frr.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,15 @@ class FRRPath(_FRRBase):
6565
def validate_path(cls, values):
6666
"""Extract meaningful data from FRR response."""
6767
new = values.copy()
68-
new["aspath"] = values["aspath"]["segments"][0]["list"]
68+
# Local prefixes (i.e. those in the same ASN) usually have
69+
# no AS_PATH.
70+
# Set AS_PATH to AS0 for now as we cannot ensure that the
71+
# ASN for the prefix is the primary ASN.
72+
if values["aspath"]["length"] != 0:
73+
new["aspath"] = values["aspath"]["segments"][0]["list"]
74+
else:
75+
# TODO: Get an ASN that is reasonable (e.g. primary ASN)
76+
new["aspath"] = [0]
6977
community = values.get("community", {"list": []})
7078
new["community"] = community["list"]
7179
new["lastUpdate"] = values["lastUpdate"]["epoch"]

0 commit comments

Comments
 (0)