|
5 | 5 | from ax_interface import MIBMeta, ValueType, MIBUpdater, SubtreeMIBEntry
|
6 | 6 | from ax_interface.util import ip2tuple_v4
|
7 | 7 | from bisect import bisect_right
|
| 8 | +from sonic_py_common import multi_asic |
8 | 9 |
|
9 | 10 | class RouteUpdater(MIBUpdater):
|
10 | 11 | def __init__(self):
|
@@ -49,26 +50,41 @@ def update_data(self):
|
49 | 50 | self.route_dest_list.append(sub_id)
|
50 | 51 | self.route_dest_map[sub_id] = self.loips[loip].packed
|
51 | 52 |
|
52 |
| - route_entries = Namespace.dbs_keys(self.db_conn, mibs.APPL_DB, "ROUTE_TABLE:*") |
53 |
| - if not route_entries: |
54 |
| - return |
55 |
| - |
56 |
| - for route_entry in route_entries: |
57 |
| - routestr = route_entry |
58 |
| - ipnstr = routestr[len("ROUTE_TABLE:"):] |
59 |
| - if ipnstr == "0.0.0.0/0": |
60 |
| - ipn = ipaddress.ip_network(ipnstr) |
61 |
| - ent = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, routestr, blocking=True) |
62 |
| - nexthops = ent["nexthop"] |
63 |
| - ifnames = ent["ifname"] |
64 |
| - for nh, ifn in zip(nexthops.split(','), ifnames.split(',')): |
65 |
| - ## Ignore non front panel interfaces |
66 |
| - ## TODO: non front panel interfaces should not be in APPL_DB at very beginning |
67 |
| - ## This is to workaround the bug in current sonic-swss implementation |
68 |
| - if ifn == "eth0" or ifn == "lo" or ifn == "docker0": continue |
69 |
| - sub_id = ip2tuple_v4(ipn.network_address) + ip2tuple_v4(ipn.netmask) + (self.tos,) + ip2tuple_v4(nh) |
70 |
| - self.route_dest_list.append(sub_id) |
71 |
| - self.route_dest_map[sub_id] = ipn.network_address.packed |
| 53 | + # Get list of front end asic namespaces for multi-asic platform. |
| 54 | + # This list will be empty for single asic platform. |
| 55 | + front_ns = multi_asic.get_all_namespaces()['front_ns'] |
| 56 | + ipnstr = "0.0.0.0/0" |
| 57 | + ipn = ipaddress.ip_network(ipnstr) |
| 58 | + route_str = "ROUTE_TABLE:0.0.0.0/0" |
| 59 | + |
| 60 | + for db_conn in Namespace.get_non_host_dbs(self.db_conn): |
| 61 | + # For multi-asic platform, proceed to get routes only for |
| 62 | + # front end namespaces. |
| 63 | + # For single-asic platform, front_ns will be empty list. |
| 64 | + if front_ns and db_conn.namespace not in front_ns: |
| 65 | + continue |
| 66 | + port_table = multi_asic.get_port_table(db_conn.namespace) |
| 67 | + ent = db_conn.get_all(mibs.APPL_DB, route_str, blocking=False) |
| 68 | + if ent is None: |
| 69 | + continue |
| 70 | + nexthops = ent["nexthop"] |
| 71 | + ifnames = ent["ifname"] |
| 72 | + for nh, ifn in zip(nexthops.split(','), ifnames.split(',')): |
| 73 | + ## Ignore non front panel interfaces |
| 74 | + ## TODO: non front panel interfaces should not be in APPL_DB at very beginning |
| 75 | + ## This is to workaround the bug in current sonic-swss implementation |
| 76 | + if ifn == "eth0" or ifn == "lo" or ifn == "docker0": |
| 77 | + continue |
| 78 | + # Ignore internal asic routes |
| 79 | + if multi_asic.is_port_channel_internal(ifn, db_conn.namespace): |
| 80 | + continue |
| 81 | + if (ifn in port_table and |
| 82 | + multi_asic.ROLE in port_table[ifn] and |
| 83 | + port_table[ifn][multi_asic.ROLE] == multi_asic.INTERNAL_PORT): |
| 84 | + continue |
| 85 | + sub_id = ip2tuple_v4(ipn.network_address) + ip2tuple_v4(ipn.netmask) + (self.tos,) + ip2tuple_v4(nh) |
| 86 | + self.route_dest_list.append(sub_id) |
| 87 | + self.route_dest_map[sub_id] = ipn.network_address.packed |
72 | 88 |
|
73 | 89 | self.route_dest_list.sort()
|
74 | 90 |
|
|
0 commit comments