-
Notifications
You must be signed in to change notification settings - Fork 133
[rfc1213] Interface MIB add l3 vlan interfaces & aggregate rif counters #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
f1b5ec1
029a992
5d3421f
f0e4048
2a35053
0999b4b
cbf06e3
7c969b7
b5c4632
20afa18
167ece7
9124833
ed9409f
b141e51
80935af
89616da
0116f85
5d2110d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| from bisect import bisect_right | ||
|
|
||
| from sonic_ax_impl import mibs | ||
| from sonic_ax_impl import logger | ||
| from ax_interface.mib import MIBMeta, ValueType, MIBUpdater, MIBEntry, SubtreeMIBEntry, OverlayAdpaterMIBEntry, OidMIBEntry | ||
| from ax_interface.encodings import ObjectIdentifier | ||
| from ax_interface.util import mac_decimals, ip2tuple_v4 | ||
|
|
@@ -48,7 +49,8 @@ class DbTables(int, Enum): | |
| class IfTypes(int, Enum): | ||
| """ IANA ifTypes """ | ||
| ethernetCsmacd = 6 | ||
| ieee8023adLag = 161 | ||
| l3ipvlan = 136 | ||
| ieee8023adLag = 161 | ||
|
|
||
| class ArpUpdater(MIBUpdater): | ||
| def __init__(self): | ||
|
|
@@ -157,8 +159,13 @@ def __init__(self): | |
| self.lag_name_if_name_map = {} | ||
| self.if_name_lag_name_map = {} | ||
| self.oid_lag_name_map = {} | ||
| self.lag_sai_map = {} | ||
| self.mgmt_oid_name_map = {} | ||
| self.mgmt_alias_map = {} | ||
| self.vlan_oid_name_map = {} | ||
| self.vlan_name_map = {} | ||
| self.rif_port_map = {} | ||
| self.port_rif_map = {} | ||
|
|
||
| # cache of interface counters | ||
| self.if_counters = {} | ||
|
|
@@ -168,6 +175,7 @@ def __init__(self): | |
| self.if_id_map = {} | ||
| self.oid_sai_map = {} | ||
| self.oid_name_map = {} | ||
| self.rif_counters = {} | ||
|
|
||
| def reinit_data(self): | ||
| """ | ||
|
|
@@ -182,6 +190,13 @@ def reinit_data(self): | |
| self.mgmt_oid_name_map, \ | ||
| self.mgmt_alias_map = mibs.init_mgmt_interface_tables(self.db_conn) | ||
|
|
||
| self.vlan_name_map, \ | ||
| self.vlan_oid_sai_map, \ | ||
| self.vlan_oid_name_map = mibs.init_sync_d_vlan_tables(self.db_conn) | ||
|
|
||
| self.rif_port_map, \ | ||
| self.port_rif_map = mibs.init_sync_d_rif_tables(self.db_conn) | ||
|
|
||
| def update_data(self): | ||
| """ | ||
| Update redis (caches config) | ||
|
|
@@ -191,13 +206,24 @@ def update_data(self): | |
| {sai_id: self.db_conn.get_all(mibs.COUNTERS_DB, mibs.counter_table(sai_id), blocking=True) | ||
| for sai_id in self.if_id_map} | ||
|
|
||
| rif_sai_ids = list(self.rif_port_map) + list(self.vlan_name_map) | ||
|
|
||
| self.rif_counters = \ | ||
| {sai_id: self.db_conn.get_all(mibs.COUNTERS_DB, mibs.counter_table(sai_id), blocking=True) | ||
| for sai_id in rif_sai_ids} | ||
|
|
||
| if self.rif_counters: | ||
| self.aggregate_counters() | ||
|
|
||
| self.lag_name_if_name_map, \ | ||
| self.if_name_lag_name_map, \ | ||
| self.oid_lag_name_map = mibs.init_sync_d_lag_tables(self.db_conn) | ||
| self.oid_lag_name_map, \ | ||
| self.lag_sai_map = mibs.init_sync_d_lag_tables(self.db_conn) | ||
|
|
||
| self.if_range = sorted(list(self.oid_sai_map.keys()) + | ||
| list(self.oid_lag_name_map.keys()) + | ||
| list(self.mgmt_oid_name_map.keys())) | ||
| list(self.mgmt_oid_name_map.keys()) + | ||
| list(self.vlan_oid_name_map.keys())) | ||
| self.if_range = [(i,) for i in self.if_range] | ||
|
|
||
| def get_next(self, sub_id): | ||
|
|
@@ -241,6 +267,8 @@ def interface_description(self, sub_id): | |
| return self.oid_lag_name_map[oid] | ||
| elif oid in self.mgmt_oid_name_map: | ||
| return self.mgmt_alias_map[self.mgmt_oid_name_map[oid]] | ||
| elif oid in self.vlan_oid_name_map: | ||
| return self.vlan_oid_name_map[oid] | ||
|
|
||
| return self.if_alias_map[self.oid_name_map[oid]] | ||
|
|
||
|
|
@@ -250,7 +278,13 @@ def _get_counter(self, oid, table_name): | |
| :param table_name: the redis table (either IntEnum or string literal) to query. | ||
| :return: the counter for the respective sub_id/table. | ||
| """ | ||
| sai_id = self.oid_sai_map[oid] | ||
| sai_id = '' | ||
| if oid in self.oid_sai_map: | ||
| sai_id = self.oid_sai_map[oid] | ||
| elif oid in self.vlan_oid_sai_map: | ||
| sai_id = self.vlan_oid_sai_map[oid] | ||
| else: | ||
| logger.warning("Unexpected oid {}".format(oid)) | ||
| # Enum.name or table_name = 'name_of_the_table' | ||
| _table_name = bytes(getattr(table_name, 'name', table_name), 'utf-8') | ||
|
|
||
|
|
@@ -264,6 +298,29 @@ def _get_counter(self, oid, table_name): | |
| mibs.logger.warning("SyncD 'COUNTERS_DB' missing attribute '{}'.".format(e)) | ||
| return None | ||
|
|
||
| def aggregate_counters(self): | ||
| """ | ||
| For ports with l3 router interfaces l3 drops may be counted separately (RIF counters) | ||
| Get l2 and l3 (if any) counters from redis, add l3 counters to l2 counters cache according to mapping | ||
|
|
||
| For l3vlan map l3 counters to l2 counters | ||
| """ | ||
| for rif_sai_id, port_sai_id in self.rif_port_map.items(): | ||
| if port_sai_id in self.if_id_map: | ||
| for port_counter_name, rif_counter_name in mibs.RIF_COUNTERS_AGGR_MAP.items(): | ||
| self.if_counters[port_sai_id][port_counter_name] = \ | ||
| int(self.if_counters[port_sai_id][port_counter_name]) + \ | ||
| int(self.rif_counters[rif_sai_id][rif_counter_name]) | ||
|
|
||
| for vlan_sai_id in self.vlan_name_map: | ||
| for port_counter_name, rif_counter_name in mibs.RIF_COUNTERS_AGGR_MAP.items(): | ||
| try: | ||
| self.if_counters.setdefault(vlan_sai_id, {}) | ||
| self.if_counters[vlan_sai_id][port_counter_name] = \ | ||
| int(self.rif_counters[vlan_sai_id][rif_counter_name]) | ||
| except KeyError as e: | ||
| logger.warning("Not able to aggregate counters for {}: {}\n {}".format(vlan_sai_id, rif_counter_name, e)) | ||
|
|
||
| def get_counter(self, sub_id, table_name): | ||
| """ | ||
| :param sub_id: The 1-based sub-identifier query. | ||
|
|
@@ -283,7 +340,14 @@ def get_counter(self, sub_id, table_name): | |
| counter_value = 0 | ||
| for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]: | ||
| counter_value += self._get_counter(mibs.get_index(lag_member), table_name) | ||
|
|
||
| # import pdb; pdb.set_trace() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove dead code #Closed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
| sai_lag_id = self.lag_sai_map[self.oid_lag_name_map[oid]] | ||
| sai_lag_rif_id = self.port_rif_map[sai_lag_id] | ||
| if sai_lag_rif_id in self.rif_port_map: | ||
| _table_name = bytes(getattr(table_name, 'name', table_name), 'utf-8') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
leading underscore is for private class member. Could you use other name convention? #Closed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
| if _table_name in mibs.RIF_COUNTERS_AGGR_MAP: | ||
| rif_table_name = mibs.RIF_COUNTERS_AGGR_MAP[_table_name] | ||
| counter_value += int(self.rif_counters[sai_lag_rif_id][rif_table_name]) | ||
| # truncate to 32-bit counter | ||
| return counter_value & 0x00000000ffffffff | ||
| else: | ||
|
|
@@ -417,6 +481,7 @@ def get_if_type(self, sub_id): | |
|
|
||
| ethernetCsmacd(6), -- for all ethernet-like interfaces, | ||
| -- regardless of speed, as per RFC3635 | ||
| l3ipvlan(136) -- Layer 3 Virtual LAN using IP | ||
| ieee8023adLag(161) -- IEEE 802.3ad Link Aggregate | ||
| """ | ||
| oid = self.get_oid(sub_id) | ||
|
|
@@ -425,6 +490,8 @@ def get_if_type(self, sub_id): | |
|
|
||
| if oid in self.oid_lag_name_map: | ||
| return IfTypes.ieee8023adLag | ||
| elif oid in self.vlan_oid_name_map: | ||
| return IfTypes.l3ipvlan | ||
| else: | ||
| return IfTypes.ethernetCsmacd | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it only for Mellanox SKUs? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only be executed if COUNTERS DB contains the rif counters. If RIF counters is not supported/disabled we will have unchanged behavior.