1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

fix handling of Arista iBGP routes, closes #132

This commit is contained in:
checktheroads
2021-04-10 11:00:26 -07:00
parent c6bcd4407f
commit 7581d42df6
2 changed files with 18 additions and 4 deletions

View File

@@ -38,7 +38,7 @@ class AristaAsPathEntry(_AristaBase):
"""Validation model for Arista asPathEntry.""" """Validation model for Arista asPathEntry."""
as_path_type: str = "External" as_path_type: str = "External"
as_path: str = "" as_path: Optional[str] = ""
class AristaPeerEntry(_AristaBase): class AristaPeerEntry(_AristaBase):
@@ -99,6 +99,8 @@ class AristaRoute(_AristaBase):
router_id: str router_id: str
vrf: str vrf: str
bgp_route_entries: Dict[str, AristaRouteEntry] bgp_route_entries: Dict[str, AristaRouteEntry]
# The raw value is really a string, but `int` will convert it.
asn: int
@staticmethod @staticmethod
def _get_route_age(timestamp: int) -> int: def _get_route_age(timestamp: int) -> int:
@@ -108,6 +110,8 @@ class AristaRoute(_AristaBase):
@staticmethod @staticmethod
def _get_as_path(as_path: str) -> List[str]: def _get_as_path(as_path: str) -> List[str]:
if as_path == "":
return []
return [int(p) for p in as_path.split() if p.isdecimal()] return [int(p) for p in as_path.split() if p.isdecimal()]
def serialize(self): def serialize(self):
@@ -129,6 +133,12 @@ class AristaRoute(_AristaBase):
if route.route_detail is not None: if route.route_detail is not None:
communities = route.route_detail.community_list communities = route.route_detail.community_list
# iBGP paths contain an empty AS_PATH array. If the AS_PATH is empty, we
# set the source_as to the router's local-as.
source_as = self.asn
if len(as_path) != 0:
source_as = as_path[0]
routes.append( routes.append(
{ {
"prefix": prefix, "prefix": prefix,
@@ -140,7 +150,7 @@ class AristaRoute(_AristaBase):
"as_path": as_path, "as_path": as_path,
"communities": communities, "communities": communities,
"next_hop": route.next_hop, "next_hop": route.next_hop,
"source_as": as_path[0], "source_as": source_as,
"source_rid": route.peer_entry.peer_router_id, "source_rid": route.peer_entry.peer_router_id,
"peer_rid": route.peer_entry.peer_router_id, "peer_rid": route.peer_entry.peer_router_id,
"rpki_state": rpki_state, "rpki_state": rpki_state,

View File

@@ -41,8 +41,12 @@ def parse_arista(output: Sequence[str]) -> Dict: # noqa: C901
log.critical("Error decoding JSON: {}", str(err)) log.critical("Error decoding JSON: {}", str(err))
raise ParsingError("Error parsing response data") raise ParsingError("Error parsing response data")
except (KeyError, IndexError) as err: except KeyError as err:
log.critical("{} was not found in the response", str(err)) log.critical("'{}' was not found in the response", str(err))
raise ParsingError("Error parsing response data")
except IndexError as err:
log.critical(str(err))
raise ParsingError("Error parsing response data") raise ParsingError("Error parsing response data")
except ValidationError as err: except ValidationError as err: