Skip to content

Commit

Permalink
Skip default route present in ASIC-DB but not in APP-DB. (sonic-net#1107
Browse files Browse the repository at this point in the history
)

This is not deemed as error, hence don't report as error.
  • Loading branch information
renukamanavalan authored Sep 12, 2020
1 parent 144bccb commit bcd9772
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions scripts/route_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ class Level(Enum):
def __str__(self):
return self.value


report_level = syslog.LOG_ERR


def set_level(lvl):
global report_level

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


def add_prefix(ip):
if ip.find(IPV6_SEPARATOR) == -1:
ip = ip + PREFIX_SEPARATOR + "32"
else:
ip = ip + PREFIX_SEPARATOR + "128"
return ip


def add_prefix_ifnot(ip):
return ip if ip.find(PREFIX_SEPARATOR) != -1 else add_prefix(ip)


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


def is_default_route(ip):
t = ipaddress.ip_address(ip.split("/")[0].decode('utf-8'))
return t.is_unspecified and ip.split("/")[1] == "0"


def cmps(s1, s2):
if (s1 == s2):
return 0
if (s1 < s2):
return -1
return 1


def do_diff(t1, t2):
t1_x = t2_x = 0
t1_miss = []
Expand Down Expand Up @@ -111,6 +123,7 @@ def get_routes():
print_message(syslog.LOG_DEBUG, json.dumps({"ROUTE_TABLE": sorted(valid_rt)}, indent=4))
return sorted(valid_rt)


def get_route_entries():
db = ConfigDBConnector()
db.db_connect('ASIC_DB')
Expand Down Expand Up @@ -147,6 +160,7 @@ def get_interfaces():
print_message(syslog.LOG_DEBUG, json.dumps({"APPL_DB_INTF": sorted(intf)}, indent=4))
return sorted(intf)


def filter_out_local_interfaces(keys):
rt = []
local_if = set(['eth0', 'lo', 'docker0'])
Expand All @@ -164,6 +178,17 @@ def filter_out_local_interfaces(keys):

return rt


def filter_out_default_routes(lst):
upd = []

for rt in lst:
if not is_default_route(rt):
upd.append(rt)

return upd


def check_routes():
intf_appl_miss = []
rt_appl_miss = []
Expand All @@ -181,6 +206,7 @@ def check_routes():

# Check missed ASIC routes against APPL-DB INTF_TABLE
_, rt_asic_miss = do_diff(intf_appl, rt_asic_miss)
rt_asic_miss = filter_out_default_routes(rt_asic_miss)

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


def main(argv):
interval = 0
parser=argparse.ArgumentParser(description="Verify routes between APPL-DB & ASIC-DB are in sync")
Expand Down

0 comments on commit bcd9772

Please sign in to comment.