Skip to content

Commit

Permalink
Merge pull request netenglabs#949 from netenglabs/fix-route-action-pr…
Browse files Browse the repository at this point in the history
…otocol

Fix route action protocol
  • Loading branch information
ddutt authored May 23, 2024
2 parents 00153e5 + 9db881d commit 9ffb095
Show file tree
Hide file tree
Showing 21 changed files with 10,110 additions and 9,366 deletions.
6 changes: 5 additions & 1 deletion suzieq/engines/pandas/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def _cons_addnl_fields(self, columns: List[str], addnl_fields: List[str],

return addnl_fields

# pylint: disable=too-many-statements
def get(self, **kwargs):
'''Return the routes table for the given filters'''

Expand Down Expand Up @@ -95,9 +96,12 @@ def get(self, **kwargs):
query_str = f'prefixlen != {prefixlen[1:]}'
else:
query_str = f'prefixlen == {prefixlen}'

# drop in reset_index to not add an additional index col
df = df.query(query_str).reset_index(drop=True)
if 'protocol' in df:
df['protocol'] = df.protocol.replace('direct', 'connected')
if 'action' in df:
df['action'] = df.action.replace('local', 'forward')

if 'numNexthops' in columns or (columns == ['*']):
srs_oif = df['oifs'].str.len()
Expand Down
13 changes: 13 additions & 0 deletions suzieq/poller/worker/services/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def _clean_junos_data(self, processed_data, raw_data):
drop_entries_idx.append(i)
continue

if entry.get('protocol', '') == 'direct':
entry['protocol'] = 'connected'
vrf = entry.pop("vrf")[0]['data']
if vrf == "inet.0":
vrf = "default"
Expand Down Expand Up @@ -253,6 +255,17 @@ def _clean_nxos_data(self, processed_data, raw_data):
else:
entry['statusChangeTimestamp'] = 0

if (protocol := entry.get('protocol', '')) == 'bgp':
rt_tag = entry.get('routeTag', [])
if isinstance(rt_tag, str):
# This is for older versions of NXOS
entry['asPathList'] = re.findall(r'\d+', rt_tag)
else:
entry['asPathList'] = rt_tag or []

if protocol == 'direct':
entry['protocol'] = 'connected'

self._fix_ipvers(entry)

processed_data = np.delete(processed_data, drop_indices).tolist()
Expand Down
2,485 changes: 1,247 additions & 1,238 deletions tests/integration/sqcmds/common-samples/all.yml

Large diffs are not rendered by default.

5,665 changes: 2,848 additions & 2,817 deletions tests/integration/sqcmds/common-samples/not.yml

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions tests/integration/sqcmds/eos-samples/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6063,8 +6063,8 @@ tests:
1, "routeTag": "", "asPathList": [], "validState": "", "hardwareProgrammed": "unknown",
"metric": 20, "statusChangeTimestamp": 0, "active": true}, {"namespace": "eos",
"hostname": "dcedge01", "vrf": "default", "prefix": "10.0.0.41/32", "nexthopIps":
[], "oifs": ["lo0.0"], "protocol": "direct", "source": "", "preference": 0, "ipvers":
4, "action": "forward", "timestamp": 1623025176627, "weights": [], "prefixlen":
[], "oifs": ["lo0.0"], "protocol": "connected", "source": "", "preference": 0,
"ipvers": 4, "action": "forward", "timestamp": 1623025176627, "weights": [], "prefixlen":
32, "numNexthops": 1, "routeTag": "", "asPathList": [], "validState": "", "hardwareProgrammed":
"unknown", "metric": 0, "statusChangeTimestamp": 1620676278627, "active": true},
{"namespace": "eos", "hostname": "dcedge01", "vrf": "default", "prefix": "10.0.0.200/32",
Expand All @@ -6074,28 +6074,28 @@ tests:
["65522", "65533", "?"], "validState": "unverified", "hardwareProgrammed": "unknown",
"metric": 0, "statusChangeTimestamp": 1620677002627, "active": true}, {"namespace":
"eos", "hostname": "dcedge01", "vrf": "default", "prefix": "10.255.2.0/24", "nexthopIps":
[], "oifs": ["em0.0"], "protocol": "direct", "source": "", "preference": 0, "ipvers":
4, "action": "forward", "timestamp": 1623025176627, "weights": [], "prefixlen":
[], "oifs": ["em0.0"], "protocol": "connected", "source": "", "preference": 0,
"ipvers": 4, "action": "forward", "timestamp": 1623025176627, "weights": [], "prefixlen":
24, "numNexthops": 1, "routeTag": "", "asPathList": [], "validState": "", "hardwareProgrammed":
"unknown", "metric": 0, "statusChangeTimestamp": 1620675831627, "active": true},
{"namespace": "eos", "hostname": "dcedge01", "vrf": "default", "prefix": "10.255.2.250/32",
"nexthopIps": [], "oifs": ["em0.0"], "protocol": "local", "source": "", "preference":
0, "ipvers": 4, "action": "local", "timestamp": 1623025176627, "weights": [],
0, "ipvers": 4, "action": "forward", "timestamp": 1623025176627, "weights": [],
"prefixlen": 32, "numNexthops": 1, "routeTag": "", "asPathList": [], "validState":
"", "hardwareProgrammed": "unknown", "metric": 0, "statusChangeTimestamp": 1620675831627,
"active": true}, {"namespace": "eos", "hostname": "dcedge01", "vrf": "default",
"prefix": "169.254.0.0/24", "nexthopIps": [], "oifs": ["em1.0"], "protocol": "direct",
"prefix": "169.254.0.0/24", "nexthopIps": [], "oifs": ["em1.0"], "protocol": "connected",
"source": "", "preference": 0, "ipvers": 4, "action": "forward", "timestamp":
1623025176627, "weights": [], "prefixlen": 24, "numNexthops": 1, "routeTag": "",
"asPathList": [], "validState": "", "hardwareProgrammed": "unknown", "metric":
0, "statusChangeTimestamp": 1620675821627, "active": true}, {"namespace": "eos",
"hostname": "dcedge01", "vrf": "default", "prefix": "169.254.0.2/32", "nexthopIps":
[], "oifs": ["em1.0"], "protocol": "local", "source": "", "preference": 0, "ipvers":
4, "action": "local", "timestamp": 1623025176627, "weights": [], "prefixlen":
4, "action": "forward", "timestamp": 1623025176627, "weights": [], "prefixlen":
32, "numNexthops": 1, "routeTag": "", "asPathList": [], "validState": "", "hardwareProgrammed":
"unknown", "metric": 0, "statusChangeTimestamp": 1620675821627, "active": true},
{"namespace": "eos", "hostname": "dcedge01", "vrf": "default", "prefix": "169.254.127.0/31",
"nexthopIps": [], "oifs": ["xe-0/0/0.0"], "protocol": "direct", "source": "",
"nexthopIps": [], "oifs": ["xe-0/0/0.0"], "protocol": "connected", "source": "",
"preference": 0, "ipvers": 4, "action": "forward", "timestamp": 1623025176627,
"weights": [], "prefixlen": 31, "numNexthops": 1, "routeTag": "", "asPathList":
[], "validState": "", "hardwareProgrammed": "unknown", "metric": 0, "statusChangeTimestamp":
Expand All @@ -6107,13 +6107,13 @@ tests:
"I"], "validState": "unverified", "hardwareProgrammed": "unknown", "metric": 0,
"statusChangeTimestamp": 1620699310627, "active": true}, {"namespace": "eos",
"hostname": "dcedge01", "vrf": "default", "prefix": "169.254.127.2/31", "nexthopIps":
[], "oifs": ["xe-0/0/1.0"], "protocol": "direct", "source": "", "preference":
[], "oifs": ["xe-0/0/1.0"], "protocol": "connected", "source": "", "preference":
0, "ipvers": 4, "action": "forward", "timestamp": 1623025176627, "weights": [],
"prefixlen": 31, "numNexthops": 1, "routeTag": "", "asPathList": [], "validState":
"", "hardwareProgrammed": "unknown", "metric": 0, "statusChangeTimestamp": 1620676707627,
"active": true}, {"namespace": "eos", "hostname": "dcedge01", "vrf": "default",
"prefix": "169.254.127.2/32", "nexthopIps": [], "oifs": ["xe-0/0/1.0"], "protocol":
"local", "source": "", "preference": 0, "ipvers": 4, "action": "local", "timestamp":
"local", "source": "", "preference": 0, "ipvers": 4, "action": "forward", "timestamp":
1623025176627, "weights": [], "prefixlen": 32, "numNexthops": 1, "routeTag": "",
"asPathList": [], "validState": "", "hardwareProgrammed": "unknown", "metric":
0, "statusChangeTimestamp": 1620676707627, "active": true}, {"namespace": "eos",
Expand All @@ -6130,7 +6130,7 @@ tests:
"65533", "65521", "I"], "validState": "unverified", "hardwareProgrammed": "unknown",
"metric": 0, "statusChangeTimestamp": 1620700001627, "active": true}, {"namespace":
"eos", "hostname": "dcedge01", "vrf": "default", "prefix": "fe80::205:860f:fc71:f000/128",
"nexthopIps": [], "oifs": ["lo0.0"], "protocol": "direct", "source": "", "preference":
"nexthopIps": [], "oifs": ["lo0.0"], "protocol": "connected", "source": "", "preference":
0, "ipvers": 6, "action": "forward", "timestamp": 1623025176627, "weights": [],
"prefixlen": 128, "numNexthops": 1, "routeTag": "", "asPathList": [], "validState":
"", "hardwareProgrammed": "unknown", "metric": 0, "statusChangeTimestamp": 1620675822627,
Expand All @@ -6141,7 +6141,7 @@ tests:
[], "validState": "", "hardwareProgrammed": "unknown", "metric": 0, "statusChangeTimestamp":
1620675816627, "active": true}, {"namespace": "eos", "hostname": "dcedge01", "vrf":
"default", "prefix": "169.254.127.0/32", "nexthopIps": [], "oifs": ["xe-0/0/0.0"],
"protocol": "local", "source": "", "preference": 0, "ipvers": 4, "action": "local",
"protocol": "local", "source": "", "preference": 0, "ipvers": 4, "action": "forward",
"timestamp": 1623025176627, "weights": [], "prefixlen": 32, "numNexthops": 1,
"routeTag": "", "asPathList": [], "validState": "", "hardwareProgrammed": "unknown",
"metric": 0, "statusChangeTimestamp": 1620676700627, "active": true}, {"namespace":
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/sqcmds/eos-samples/path.yml
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,9 @@ tests:
- command: path summarize --dest=172.16.3.202 --src=172.16.1.101 --format=json --namespace=eos
data-directory: tests/data/parquet/
marks: path summarize eos
output: '[{"eos": 8}, {"eos": [2, 2, 2, 1]}, {"eos": 4}, {"eos": 4.0}, {"eos": 8},
{"eos": 1500}, {"eos": true}, {"eos": true}]'
output: '{"eos": {"totalPaths": 8, "perHopEcmp": [2, 2, 2, 1], "maxPathLength":
4, "avgPathLength": 4.0, "uniqueDevices": 8, "pathMtu": 1500, "usesOverlay": true,
"mtuMismatch": true}}'
- command: path summarize --dest=10.0.0.11 --src=10.0.0.14 --format=json --namespace=eos
data-directory: tests/data/parquet/
marks: path summarize eos
Expand Down
Loading

0 comments on commit 9ffb095

Please sign in to comment.