From 47fc55fb08ad9d698ae5f7a889b7483b7d697bfa Mon Sep 17 00:00:00 2001 From: checktheroads Date: Thu, 22 Apr 2021 22:22:39 -0700 Subject: [PATCH] fix handling of juniper indirect next-hops, add tests. closes #135 --- hyperglass/models/parsing/juniper.py | 3 + .../models/parsing/juniper_route_direct.xml | 774 ++++++++++++++++++ .../models/parsing/juniper_route_indirect.xml | 201 +++++ hyperglass/parsing/test_juniper.py | 31 + 4 files changed, 1009 insertions(+) create mode 100644 hyperglass/models/parsing/juniper_route_direct.xml create mode 100644 hyperglass/models/parsing/juniper_route_indirect.xml create mode 100644 hyperglass/parsing/test_juniper.py diff --git a/hyperglass/models/parsing/juniper.py b/hyperglass/models/parsing/juniper.py index e519fd6c..514ffc0f 100644 --- a/hyperglass/models/parsing/juniper.py +++ b/hyperglass/models/parsing/juniper.py @@ -75,6 +75,9 @@ def validate_optional_flags(cls, values): if "selected-next-hop" in hop: selected_next_hop = hop.get("to", "") break + elif hop.get("to") is not None: + selected_next_hop = hop["to"] + break values["next-hop"] = selected_next_hop diff --git a/hyperglass/models/parsing/juniper_route_direct.xml b/hyperglass/models/parsing/juniper_route_direct.xml new file mode 100644 index 00000000..a96084a0 --- /dev/null +++ b/hyperglass/models/parsing/juniper_route_direct.xml @@ -0,0 +1,774 @@ + + + + + + inet.0 + + + 851482 + + + 3145808 + + + 851445 + + + 1 + + + 94 + + + + 1.1.1.0 + + + 24 + + + 4 + + + 1 + + + + * + + + + + BGP + + + 170 + + + -176 + + + Router + + + 1007 + + + 0x36d576ac + + + 1337511 + + + 0 + + + 62.115.189.136 + + + + Next hop + + + 62.115.189.136 + + + xe-0/1/1.0 + + + + 4e3 + + + + Active Ext + + + 14525 + + + 1299 + + + 4w2d 11:47:11 + + + valid + + + 0 + + + BGP_1299.62.115.189.136 + + + 5 + + + 0-KRT 6-BGP_RT_Background 8-Resolve tree 3 10-Aggregate 12-RT + + + AS path: 1299 13335 I + Aggregator: 13335 141.101.72.1 + AS path: Recorded + + + + + AS path: + + + 1299 13335 I + + + + + + + 11 + + + + 13335 + + + 141.101.72.1 + + + + + + + 1299:35000 + + + 14525:0 + + + 14525:41 + + + 14525:600 + + + 14525:1021 + + + 14525:2840 + + + 14525:3001 + + + 14525:4001 + + + 14525:9003 + + + + Accepted + + + 175 + + + 2.255.254.43 + + + + + + + BGP + + + 200 + + + -251 + + + Indirect + + + 0 + + + 0x159d47bc + + + 546747 + + + 0 + + + 199.34.94.1 + + + Router + + + 897 + + + + Next hop + + + 100.64.0.21 + + + et-0/0/2.3601 + + + + 0x4261200 + + + 0x0 + + + 4 + + + 2 + + + 0 + + + 53c + + + + + 199.34.94.1 + + + 0xa010e00 1048620 INH Session ID: 0x53e + + + + Int Ext + + + Route Preference + + + 14525 + + + 14525 + + + 2w6d 10:46:31 + + + 0 + + + 1000 + + + unverified + + + 1000 + + + BGP_14525.199.34.94.1 + + + AS path: 13335 I + Aggregator: 13335 172.68.129.1 + AS path: Recorded + + + + + AS path: + + + 13335 I + + + + + + + 11 + + + + 13335 + + + 172.68.129.1 + + + + + + + 13335:10232 + + + 13335:19000 + + + 13335:20050 + + + 13335:20500 + + + 13335:20530 + + + 14525:0 + + + 14525:20 + + + 14525:600 + + + 14525:1021 + + + 14525:2840 + + + 14525:3003 + + + 14525:4003 + + + 14525:9009 + + + + Accepted + + + 250 + + + 199.34.94.1 + + + + + + + BGP + + + 200 + + + -251 + + + Indirect + + + 0 + + + 0x20040a2c + + + 600203 + + + 0 + + + 199.34.94.2 + + + Router + + + 1243 + + + + Next hop + + + 100.64.0.22 + + + et-0/0/2.3601 + + + + 0x8b6e880 + + + 0x0 + + + 4 + + + 2 + + + 0 + + + 532 + + + + + 199.34.94.2 + + + 0xa010800 1048619 INH Session ID: 0x5c1 + + + + NotBest Int Ext + + + Not Best in its group - Router ID + + + 14525 + + + 14525 + + + 4:02 + + + 0 + + + 1000 + + + unverified + + + 1000 + + + BGP_14525.199.34.94.2 + + + AS path: 13335 I + Aggregator: 13335 172.68.129.1 + AS path: Recorded + + + + + AS path: + + + 13335 I + + + + + + + 11 + + + + 13335 + + + 172.68.129.1 + + + + + + + 13335:10232 + + + 13335:19000 + + + 13335:20050 + + + 13335:20500 + + + 13335:20530 + + + 14525:0 + + + 14525:20 + + + 14525:600 + + + 14525:1021 + + + 14525:2840 + + + 14525:3003 + + + 14525:4003 + + + 14525:9009 + + + + Accepted + + + 250 + + + 199.34.94.2 + + + + + + + BGP + + + 200 + + + -251 + + + Indirect + + + 0 + + + 0x1e049e7c + + + 135307 + + + 0 + + + 216.250.230.2 + + + Router + + + 0 + + + + Next hop + + + 100.64.0.52 + + + et-0/0/1.3605 + + + 0x1 + + + + 0x8b6f980 + + + 0x0 + + + 13 + + + 5 + + + 0 + + + 0 + + + + + Next hop + + + 100.64.0.140 + + + et-0/0/2.3607 + + + 0x1 + + + 0x8b6f980 + + + 0x0 + + + 13 + + + 5 + + + 0 + + + 0 + + + + + 216.250.230.2 + + + 0xa00f600 1048607 INH Session ID: 0x54c + + + + NotBest Int Ext + + + Not Best in its group - Router ID + + + 14525 + + + 14525 + + + 2w1d 19:52:36 + + + 0 + + + 1000 + + + unverified + + + 1000 + + + BGP_14525.216.250.230.2 + + + AS path: 13335 I + Aggregator: 13335 141.101.73.1 + + + + + AS path: + + + 13335 I + + + + + 11 + + + + 13335 + + + 141.101.73.1 + + + + + + + 13335:10014 + + + 13335:19000 + + + 13335:20050 + + + 13335:20500 + + + 13335:20530 + + + 14525:0 + + + 14525:20 + + + 14525:600 + + + 14525:1021 + + + 14525:2840 + + + 14525:3003 + + + 14525:4002 + + + 14525:9009 + + + + Accepted + + + 250 + + + 216.250.230.2 + + + + + + + + + + diff --git a/hyperglass/models/parsing/juniper_route_indirect.xml b/hyperglass/models/parsing/juniper_route_indirect.xml new file mode 100644 index 00000000..ba2f6519 --- /dev/null +++ b/hyperglass/models/parsing/juniper_route_indirect.xml @@ -0,0 +1,201 @@ + + + + + + inet.0 + + + 851462 + + + 3145810 + + + 851425 + + + 1 + + + 94 + + + + 199.34.94.96 + + + 30 + + + 1 + + + 1 + + + + + + * + + + + + BGP + + + 200 + + + -451 + + + Indirect + + + 0 + + + 0x159d47bc + + + 546728 + + + 0 + + + 199.34.94.1 + + + Router + + + 897 + + + + Next hop + + + 100.64.0.21 + + + et-0/0/2.3601 + + + + 0x4261200 + + + 0x0 + + + 4 + + + 2 + + + 0 + + + 53c + + + + + 199.34.94.1 + + + 0xa010e00 1048620 INH Session ID: 0x53e + + + + Active Int Ext + + + 14525 + + + 14525 + + + 2w6d 10:54:23 + + + 0 + + + 1000 + + + unverified + + + 1000 + + + BGP_14525.199.34.94.1 + + + 4 + + + 0-KRT 8-Resolve tree 3 10-Aggregate 12-RT + + + AS path: I + AS path: Recorded + + + + + AS path: + + + I + + + + + + + + 14525:0 + + + 14525:1 + + + 14525:1021 + + + 14525:2840 + + + 14525:3003 + + + 14525:4003 + + + + Accepted + + + 450 + + + 199.34.94.1 + + + + + + + + + + diff --git a/hyperglass/parsing/test_juniper.py b/hyperglass/parsing/test_juniper.py new file mode 100644 index 00000000..3b112659 --- /dev/null +++ b/hyperglass/parsing/test_juniper.py @@ -0,0 +1,31 @@ +"""Test Juniper XML Parsing.""" + +# Standard Library +import sys +import json +from pathlib import Path + +# Project +from hyperglass.log import log + +# Local +from .juniper import parse_juniper + +SAMPLE_FILES = ( + Path(__file__).parent.parent / "models" / "parsing" / "juniper_route_direct.xml", + Path(__file__).parent.parent / "models" / "parsing" / "juniper_route_indirect.xml", +) + +if __name__ == "__main__": + samples = () + if len(sys.argv) == 2: + samples += (sys.argv[1],) + else: + for sample_file in SAMPLE_FILES: + with sample_file.open("r") as file: + samples += (file.read(),) + + for sample in samples: + parsed = parse_juniper([sample]) + log.info(json.dumps(parsed, indent=2)) + sys.exit(0)