Skip to content

Commit a57d62c

Browse files
authored
Merge pull request #947 from netenglabs/fix-sonic-routes
Fix sonic routes version 4.2
2 parents 3a96659 + 460eb1e commit a57d62c

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

suzieq/config/routes.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ apply:
2525
copy: cumulus
2626

2727
sonic:
28-
copy: cumulus
28+
- version: '>= 4.2.0'
29+
merge: False
30+
command:
31+
- command: ip vrf show
32+
textfsm: textfsm_templates/sonic_vrf_show.tfsm
33+
- command: ip route show table all
34+
textfsm: textfsm_templates/sonic_routes_v42.tfsm
35+
- version: all
36+
command: ip route show table all
37+
textfsm: textfsm_templates/linux_routes.tfsm
2938

3039
eos:
3140
version: all
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Value protocol (\w+)
2+
Value Required prefix ([0-9./]*|[0-9a-f:/]*|default)
3+
Value vrf_id (\d+)
4+
Value source ([0-9./]*)
5+
Value List nexthopIps ([0-9./]*|[0-9a-f:/]*)
6+
Value List oifs (\S+)
7+
Value List weights (\d+)
8+
Value metric (\d+)
9+
Value action (blackhole)
10+
11+
Start
12+
^\S+ -> Continue.Record
13+
^${action}\s+(?:nhid \d+\s+)?${prefix}\s+proto ${protocol}\s+metric ${metric}.*$$
14+
^\s+nexthop via\s+${nexthopIps}\s+dev ${oifs}\s+weight ${weights}.*$$
15+
^${prefix}\s+(?:nhid \d+\s+)?via\s+${nexthopIps}\s+dev ${oifs}\s+table ${vrf_id}\s+proto ${protocol}\s+metric ${metric}.*$$
16+
^${prefix}\s+(?:nhid \d+\s+)?dev ${oifs}\s+table ${vrf_id}\s+proto ${protocol}.*src ${source}.*$$
17+
^unreachable\s+(?:nhid \d+\s+)?${prefix}\s+table ${vrf_id}\s+metric ${metric}.*$$
18+
^${prefix}\s+(?:nhid \d+\s+)?via\s+${nexthopIps}\s+dev ${oifs}\s+table ${vrf_id}
19+
^${prefix}\s+(?:nhid \d+\s+)?proto ${protocol}\s+metric ${metric}.*$$
20+
^${prefix}\s+(?:nhid \d+\s+)?proto ${protocol}\s+src ${source}\s+metric ${metric}.*$$
21+
^${prefix}\s+(?:nhid \d+\s+)?via ${nexthopIps}\s+dev ${oifs}\s+proto ${protocol}\s+metric ${metric}.*$$
22+
^${prefix}\s+(?:nhid \d+\s+)?dev ${oifs}\s+proto ${protocol}.*src ${source}.*$$
23+
^${prefix}\s+(?:nhid \d+\s+)?via ${nexthopIps}\s+dev ${oifs}.*$$
24+
^${prefix}\s+(?:nhid \d+\s+)?table ${vrf_id}\s+proto ${protocol}\s+metric ${metric}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Value vrf (\S+)
2+
Value table_id (\d+)
3+
4+
Start
5+
^${vrf}\s+${table_id} -> Record

suzieq/poller/worker/services/routes.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from typing import Dict, List
23
import numpy as np
34

45
from suzieq.poller.worker.services.service import Service
@@ -58,9 +59,18 @@ def _clean_eos_data(self, processed_data, _):
5859

5960
def _clean_linux_data(self, processed_data, _):
6061
"""Clean Linux ip route data"""
62+
drop_indices: List[int] = []
63+
id_vrf_match: Dict[str, str] = {}
6164

62-
for entry in processed_data:
63-
entry["vrf"] = entry["vrf"] or "default"
65+
for i, entry in enumerate(processed_data):
66+
if table_id := entry.get('table_id'):
67+
id_vrf_match[table_id] = entry.get('vrf') or 'default'
68+
drop_indices.append(i)
69+
continue
70+
if vrf_id := entry.get('vrf_id'):
71+
entry["vrf"] = id_vrf_match.get(vrf_id) or 'default'
72+
else:
73+
entry["vrf"] = entry.get("vrf") or "default"
6474
entry["metric"] = entry["metric"] or 20
6575
entry['preference'] = entry['metric']
6676
for ele in ["nexthopIps", "oifs"]:
@@ -87,6 +97,10 @@ def _clean_linux_data(self, processed_data, _):
8797

8898
entry['inHardware'] = True # Till the offload flag is here
8999

100+
if drop_indices:
101+
processed_data = np.delete(
102+
processed_data, drop_indices).tolist() # type: ignore
103+
90104
return processed_data
91105

92106
def _clean_cumulus_data(self, processed_data, raw_data):

suzieq/poller/worker/services/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ def _get_def_for_version(self, defn: List, version: str) -> Dict:
321321
# There are various outputs that due to an old parsing bug
322322
# return a node version of 0. Use 'all' for those
323323
continue
324-
opdict = {'>': operator.gt, '<': operator.lt,
325-
'>=': operator.ge, '<=': operator.le,
324+
opdict = {'>=': operator.ge, '<=': operator.le,
325+
'>': operator.gt, '<': operator.lt,
326326
'=': operator.eq, '!=': operator.ne}
327327
op = operator.eq
328328

0 commit comments

Comments
 (0)