From 176cc4ab2aa058597f1c3cb54d825d429dab45b9 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan <47282725+renukamanavalan@users.noreply.github.com> Date: Fri, 16 Apr 2021 07:40:27 -0700 Subject: [PATCH] 1) Loopback interfaces with valid nexthop IP are not ignored/treated as loopback. (#1565) 2) The vrf routes are *not* handled. --- scripts/route_check.py | 22 ++++++++++++++++++---- tests/route_check_test.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/scripts/route_check.py b/scripts/route_check.py index fe870ab0769d..1e03a9c6bde0 100755 --- a/scripts/route_check.py +++ b/scripts/route_check.py @@ -264,6 +264,10 @@ def get_subscribe_updates(selector, subs): return (sorted(adds), sorted(deletes)) +def is_vrf(k): + return k.startswith("Vrf") + + def get_routes(): """ helper to read route table from APPL-DB. @@ -276,7 +280,7 @@ def get_routes(): valid_rt = [] for k in keys: - if not is_local(k): + if not is_vrf(k) and not is_local(k): valid_rt.append(add_prefix_ifnot(k.lower())) print_message(syslog.LOG_DEBUG, json.dumps({"ROUTE_TABLE": sorted(valid_rt)}, indent=4)) @@ -341,15 +345,25 @@ def filter_out_local_interfaces(keys): :return keys filtered out of local """ rt = [] - local_if_re = [r'eth0', r'lo', r'docker0', r'tun0', r'Loopback\d+'] + local_if_lst = {'eth0', 'docker0'} + local_if_lo = [r'tun0', r'lo', r'Loopback\d+'] db = swsscommon.DBConnector(APPL_DB_NAME, 0) tbl = swsscommon.Table(db, 'ROUTE_TABLE') for k in keys: e = dict(tbl.get(k)[1]) - if not e or all([not re.match(x, e['ifname']) for x in local_if_re]): - rt.append(k) + + ifname = e.get('ifname', '') + if ifname in local_if_lst: + continue + + if any([re.match(x, ifname) for x in local_if_lo]): + nh = e.get('nexthop') + if not nh or ipaddress.ip_address(nh).is_unspecified: + continue + + rt.append(k) return rt diff --git a/tests/route_check_test.py b/tests/route_check_test.py index f981275314a4..a39015c07f35 100644 --- a/tests/route_check_test.py +++ b/tests/route_check_test.py @@ -218,6 +218,40 @@ } } } + }, + "5": { + DESCR: "local route with nexthop - fail", + ARGS: "route_check -m INFO -i 1000", + RET: -1, + PRE: { + APPL_DB: { + ROUTE_TABLE: { + "0.0.0.0/0" : { "ifname": "portchannel0" }, + "10.10.196.12/31" : { "ifname": "portchannel0" }, + "10.10.196.20/31" : { "ifname": "portchannel0" }, + "10.10.196.30/31" : { "ifname": "lo", "nexthop": "100.0.0.2" } + }, + INTF_TABLE: { + "PortChannel1013:10.10.196.24/31": {}, + "PortChannel1023:2603:10b0:503:df4::5d/126": {}, + "PortChannel1024": {} + } + }, + ASIC_DB: { + RT_ENTRY_TABLE: { + RT_ENTRY_KEY_PREFIX + "10.10.196.12/31" + RT_ENTRY_KEY_SUFFIX: {}, + RT_ENTRY_KEY_PREFIX + "10.10.196.20/31" + RT_ENTRY_KEY_SUFFIX: {}, + RT_ENTRY_KEY_PREFIX + "10.10.196.24/32" + RT_ENTRY_KEY_SUFFIX: {}, + RT_ENTRY_KEY_PREFIX + "2603:10b0:503:df4::5d/128" + RT_ENTRY_KEY_SUFFIX: {}, + RT_ENTRY_KEY_PREFIX + "0.0.0.0/0" + RT_ENTRY_KEY_SUFFIX: {} + } + } + }, + RESULT: { + "missed_ROUTE_TABLE_routes": [ + "10.10.196.30/31" + ] + } } }