Skip to content

Commit bcd9772

Browse files
Skip default route present in ASIC-DB but not in APP-DB. (sonic-net#1107)
This is not deemed as error, hence don't report as error.
1 parent 144bccb commit bcd9772

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

scripts/route_check.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ class Level(Enum):
2828
def __str__(self):
2929
return self.value
3030

31+
3132
report_level = syslog.LOG_ERR
3233

34+
3335
def set_level(lvl):
3436
global report_level
3537

@@ -48,27 +50,37 @@ def print_message(lvl, *args):
4850
print(msg)
4951
syslog.syslog(lvl, msg)
5052

53+
5154
def add_prefix(ip):
5255
if ip.find(IPV6_SEPARATOR) == -1:
5356
ip = ip + PREFIX_SEPARATOR + "32"
5457
else:
5558
ip = ip + PREFIX_SEPARATOR + "128"
5659
return ip
5760

61+
5862
def add_prefix_ifnot(ip):
5963
return ip if ip.find(PREFIX_SEPARATOR) != -1 else add_prefix(ip)
6064

65+
6166
def is_local(ip):
6267
t = ipaddress.ip_address(ip.split("/")[0].decode('utf-8'))
6368
return t.is_link_local
6469

70+
71+
def is_default_route(ip):
72+
t = ipaddress.ip_address(ip.split("/")[0].decode('utf-8'))
73+
return t.is_unspecified and ip.split("/")[1] == "0"
74+
75+
6576
def cmps(s1, s2):
6677
if (s1 == s2):
6778
return 0
6879
if (s1 < s2):
6980
return -1
7081
return 1
7182

83+
7284
def do_diff(t1, t2):
7385
t1_x = t2_x = 0
7486
t1_miss = []
@@ -111,6 +123,7 @@ def get_routes():
111123
print_message(syslog.LOG_DEBUG, json.dumps({"ROUTE_TABLE": sorted(valid_rt)}, indent=4))
112124
return sorted(valid_rt)
113125

126+
114127
def get_route_entries():
115128
db = ConfigDBConnector()
116129
db.db_connect('ASIC_DB')
@@ -147,6 +160,7 @@ def get_interfaces():
147160
print_message(syslog.LOG_DEBUG, json.dumps({"APPL_DB_INTF": sorted(intf)}, indent=4))
148161
return sorted(intf)
149162

163+
150164
def filter_out_local_interfaces(keys):
151165
rt = []
152166
local_if = set(['eth0', 'lo', 'docker0'])
@@ -164,6 +178,17 @@ def filter_out_local_interfaces(keys):
164178

165179
return rt
166180

181+
182+
def filter_out_default_routes(lst):
183+
upd = []
184+
185+
for rt in lst:
186+
if not is_default_route(rt):
187+
upd.append(rt)
188+
189+
return upd
190+
191+
167192
def check_routes():
168193
intf_appl_miss = []
169194
rt_appl_miss = []
@@ -181,6 +206,7 @@ def check_routes():
181206

182207
# Check missed ASIC routes against APPL-DB INTF_TABLE
183208
_, rt_asic_miss = do_diff(intf_appl, rt_asic_miss)
209+
rt_asic_miss = filter_out_default_routes(rt_asic_miss)
184210

185211
# Check APPL-DB INTF_TABLE with ASIC table route entries
186212
intf_appl_miss, _ = do_diff(intf_appl, rt_asic)
@@ -208,6 +234,7 @@ def check_routes():
208234
print_message(syslog.LOG_INFO, "All good!")
209235
return 0
210236

237+
211238
def main(argv):
212239
interval = 0
213240
parser=argparse.ArgumentParser(description="Verify routes between APPL-DB & ASIC-DB are in sync")

0 commit comments

Comments
 (0)