-
Notifications
You must be signed in to change notification settings - Fork 114
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
[rfc1213] Interface MIB add l3 vlan interfaces & aggregate rif counters #169
Merged
qiluo-msft
merged 26 commits into
sonic-net:master
from
stepanblyschak:rif_vlan_counters
Dec 8, 2020
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f1b5ec1
[rfc1213] Interface MIB add l3 vlan interfaces
029a992
[rfc1213] aggregate rifcounters on top of l2 counters
5d3421f
fix issues
f0e4048
add unittests
2a35053
add mock data
0999b4b
cleanup
cbf06e3
lag rif fixes
7c969b7
add more unittests
b5c4632
update test_mibs.py
20afa18
Merge branch 'master' into drops
mykolaf 167ece7
fix comments
9124833
update namespace/test_mibs.py unittest
ed9409f
[rfc1213] add vlan interface admin_status
b141e51
only aggregate errors
80935af
add vlan subinterface unitttests
89616da
fix init_sync_d_lag
0116f85
update namespace mib test
5d2110d
add namespace mock table data
2721b32
Merge commit 'refs/pull/133/head' of github.com:azure/sonic-snmpagent
76fb565
Fix exception when RIF counters are not available.
stepanblyschak b22236b
make rif key unique in multi-asic env
stepanblyschak 8a741fb
Merge remote-tracking branch 'origin/master' into rif_vlan_counters
stepanblyschak 068f530
support multi-asic devices & unit test for multi-asic
stepanblyschak 144658f
merge import lines
stepanblyschak 196033f
remove unused report
stepanblyschak a00e69e
Merge branch 'master' of github.com:azure/sonic-snmpagent into rif_vl…
stepanblyschak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,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): | ||
|
@@ -191,8 +192,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 = {} | ||
|
@@ -201,6 +207,8 @@ def __init__(self): | |
self.if_alias_map = {} | ||
self.if_id_map = {} | ||
self.oid_name_map = {} | ||
self.rif_counters = {} | ||
|
||
self.namespace_db_map = Namespace.get_namespace_db_map(self.db_conn) | ||
|
||
def reinit_data(self): | ||
|
@@ -219,26 +227,50 @@ def reinit_data(self): | |
self.mgmt_oid_name_map, \ | ||
self.mgmt_alias_map = mibs.init_mgmt_interface_tables(self.db_conn[0]) | ||
|
||
self.vlan_name_map, \ | ||
self.vlan_oid_sai_map, \ | ||
self.vlan_oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_vlan_tables, self.db_conn) | ||
|
||
self.rif_port_map, \ | ||
self.port_rif_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_rif_tables, self.db_conn) | ||
|
||
def update_data(self): | ||
""" | ||
Update redis (caches config) | ||
Pulls the table references for each interface. | ||
""" | ||
for sai_id_key in self.if_id_map: | ||
namespace, sai_id = mibs.split_sai_id_key(sai_id_key) | ||
if_idx = mibs.get_index_from_str(self.if_id_map[sai_id_key]) | ||
self.if_counters[if_idx] = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \ | ||
mibs.counter_table(sai_id), blocking=True) | ||
|
||
self.update_if_counters() | ||
self.update_rif_counters() | ||
|
||
self.aggregate_counters() | ||
|
||
self.lag_name_if_name_map, \ | ||
self.if_name_lag_name_map, \ | ||
self.oid_lag_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn) | ||
self.oid_lag_name_map, \ | ||
self.lag_sai_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn) | ||
|
||
self.if_range = sorted(list(self.oid_name_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 update_if_counters(self): | ||
for sai_id_key in self.if_id_map: | ||
namespace, sai_id = mibs.split_sai_id_key(sai_id_key) | ||
if_idx = mibs.get_index_from_str(self.if_id_map[sai_id_key]) | ||
self.if_counters[if_idx] = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \ | ||
mibs.counter_table(sai_id), blocking=True) | ||
|
||
def update_rif_counters(self): | ||
rif_sai_ids = list(self.rif_port_map) + list(self.vlan_name_map) | ||
self.rif_counters = \ | ||
{sai_id: Namespace.dbs_get_all(self.db_conn, mibs.COUNTERS_DB, | ||
mibs.counter_table(mibs.split_sai_id_key(sai_id)[1]), | ||
blocking=False) | ||
for sai_id in rif_sai_ids} | ||
|
||
def get_next(self, sub_id): | ||
""" | ||
:param sub_id: The 1-based sub-identifier query. | ||
|
@@ -280,6 +312,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]] | ||
|
||
|
@@ -302,6 +336,31 @@ 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) | ||
add l3 drops to l2 drop 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: | ||
port_idx = mibs.get_index_from_str(self.if_id_map[port_sai_id]) | ||
for port_counter_name, rif_counter_name in mibs.RIF_DROPS_AGGR_MAP.items(): | ||
self.if_counters[port_idx][port_counter_name] = \ | ||
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.
I see you change |
||
int(self.if_counters[port_idx][port_counter_name]) + \ | ||
int(self.rif_counters[rif_sai_id][rif_counter_name]) | ||
|
||
for vlan_sai_id, vlan_name in self.vlan_name_map.items(): | ||
for port_counter_name, rif_counter_name in mibs.RIF_COUNTERS_AGGR_MAP.items(): | ||
vlan_idx = mibs.get_index_from_str(vlan_name) | ||
vlan_rif_counters = self.rif_counters[vlan_sai_id] | ||
if rif_counter_name in vlan_rif_counters: | ||
self.if_counters.setdefault(vlan_idx, {}) | ||
self.if_counters[vlan_idx][port_counter_name] = \ | ||
int(vlan_rif_counters[rif_counter_name]) | ||
|
||
|
||
def get_counter(self, sub_id, table_name): | ||
""" | ||
:param sub_id: The 1-based sub-identifier query. | ||
|
@@ -321,7 +380,13 @@ 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_from_str(lag_member), table_name) | ||
|
||
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 = getattr(table_name, 'name', table_name) | ||
if table_name in mibs.RIF_DROPS_AGGR_MAP: | ||
rif_table_name = mibs.RIF_DROPS_AGGR_MAP[table_name] | ||
counter_value += int(self.rif_counters[sai_lag_rif_id].get(rif_table_name, 0)) | ||
# truncate to 32-bit counter | ||
return counter_value & 0x00000000ffffffff | ||
else: | ||
|
@@ -351,6 +416,8 @@ def _get_if_entry(self, sub_id): | |
elif oid in self.mgmt_oid_name_map: | ||
if_table = mibs.mgmt_if_entry_table(self.mgmt_oid_name_map[oid]) | ||
db = mibs.CONFIG_DB | ||
elif oid in self.vlan_oid_name_map: | ||
if_table = mibs.vlan_entry_table(self.vlan_oid_name_map[oid]) | ||
elif oid in self.oid_name_map: | ||
if_table = mibs.if_entry_table(self.oid_name_map[oid]) | ||
else: | ||
|
@@ -455,6 +522,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) | ||
|
@@ -463,6 +531,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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If you merge latest master, you don't need to encoding to byte array.