mirror of
https://github.com/thatmattlove/hyperglass.git
synced 2026-01-22 18:28:07 +00:00
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 <tan@siewert.io>
This commit is contained in:
parent
32873934cf
commit
79d235c2ff
1 changed files with 9 additions and 1 deletions
|
|
@ -65,7 +65,15 @@ class FRRPath(_FRRBase):
|
|||
def validate_path(cls, values):
|
||||
"""Extract meaningful data from FRR response."""
|
||||
new = values.copy()
|
||||
new["aspath"] = values["aspath"]["segments"][0]["list"]
|
||||
# Local prefixes (i.e. those in the same ASN) usually have
|
||||
# no AS_PATH.
|
||||
# Set AS_PATH to AS0 for now as we cannot ensure that the
|
||||
# ASN for the prefix is the primary ASN.
|
||||
if values["aspath"]["length"] != 0:
|
||||
new["aspath"] = values["aspath"]["segments"][0]["list"]
|
||||
else:
|
||||
# TODO: Get an ASN that is reasonable (e.g. primary ASN)
|
||||
new["aspath"] = [0]
|
||||
community = values.get("community", {"list": []})
|
||||
new["community"] = community["list"]
|
||||
new["lastUpdate"] = values["lastUpdate"]["epoch"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue