-
Notifications
You must be signed in to change notification settings - Fork 104
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
[sonic_ax_impl]: Add support of port channels. #21
Conversation
- Add port channels support to RFC1213 (1.3.6.1.2.1.2) and RFC2863 (1.3.6.1.2.1.31.1) MIBs. - Read oper state, admin state and MTU value from DB.
if sub_id in self.oid_lag_name_map: | ||
counter_value = 0 | ||
for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[sub_id]]: | ||
counter_value += self.get_counter(mibs.get_index(lag_member), table_name) |
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.
What if the sum of the interface counters will be greater then 2^32?
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.
It will be truncated to 32 bit in upper layer. Changed code to truncate it explicitly.
src/sonic_ax_impl/mibs/__init__.py
Outdated
""" | ||
match = re.match(SONIC_ETHERNET_RE_PATTERN, if_name) | ||
if match: | ||
n = match.group(1) | ||
return int(n) + 1 | ||
|
||
match = re.match(SONIC_PORTCHANNEL_RE_PATTERN, if_name) |
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.
Probably it's better to make a loop over regexps with if_name.
regexps = {
SONIC_ETHERNET_RE_PATTERN: 1
SONIC_PORTCHANNEL_RE_PATTERN: 1000
}
If we want to add vlan or other interfaces later, we could just add more entry to table.
@qiluo-msft, canyou review? |
return int(n) + 1 | ||
patterns = { | ||
SONIC_ETHERNET_RE_PATTERN: 1, | ||
SONIC_PORTCHANNEL_RE_PATTERN: 1000 |
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.
1000 [](start = 38, length = 4)
Magic number. Give a name and some comment? May be '1' above is in the same context. #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.
There is comment in function description
src/sonic_ax_impl/mibs/__init__.py
Outdated
|
||
for lag_entry in lag_entries: | ||
lag_name = lag_entry[len(b"LAG_TABLE:"):] | ||
lag_members = db_conn.keys(APPL_DB, b"LAG_MEMBER_TABLE:%s:*" % lag_name) |
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.
b"LAG_MEMBER_TABLE:%s:*" % lag_name [](start = 44, length = 35)
regex replace LAG_TABLE->LAG_MEMBER_TABLE
Is it more readable?
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.
It will look the same. Isn't it?
src/sonic_ax_impl/mibs/__init__.py
Outdated
if_name_lag_name_map = {} | ||
|
||
for lag_entry in lag_entries: | ||
lag_name = lag_entry[len(b"LAG_TABLE:"):] |
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.
lag_entry[len(b"LAG_TABLE:"):] [](start = 19, length = 30)
Split by ':' and get the second part?
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.
what is the difference?
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.
src/sonic_ax_impl/mibs/__init__.py
Outdated
|
||
# { OID -> lag_name (SONiC) } | ||
oid_lag_name_map = {get_index(if_name): if_name for if_name in lag_name_if_name_map.keys() | ||
if get_index(if_name)} |
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.
get_index [](start = 27, length = 9)
get_index() twice?
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.
Yes, to verify that get_index return value is not None
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.
def member_name_str(val, lag_name): | ||
return val[len(b"LAG_MEMBER_TABLE:%s:" % lag_name):] | ||
|
||
lag_name_if_name_map[lag_name] = [member_name_str(m, lag_name) for m in lag_members] |
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.
m [](start = 75, length = 1)
Check m is valid. And it will make sure recursive get_counter() is safe.
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.
"m" is always valid we get it from DB
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.
Recursion here is safe. Maximum depth is always 1.
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.
There is a trust boundary between DB and this component. If anything bad happens in DB, this component should not be trapped in a non-stopping recursion and crash.
In reply to: 113863174 [](ancestors = 113863174)
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.
SNMP in SONiC works in read only mode. It takes information from DB converts it in special format and returns to user. Without working DB it is meaningless. If something bad happens with DB it will crash anyway because all code is implemented taking into consideration that DB can't fail. This is actual for any existing component.
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.
As comments
Refactor is not in scope of this commit. Suggest to create an enhancement |
src/sonic_ax_impl/mibs/__init__.py
Outdated
""" | ||
db_conn.connect(APPL_DB) | ||
|
||
lag_entries = db_conn.keys(APPL_DB, b"LAG_TABLE:*") |
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 function seems to be only executed at the init time. this may not be complete at certain point of time. For example, the system has 4 port channels, and at the time when you tries to get the LAG_TABLE, you only see 3.
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.
Will update this PR soon
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.
done
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.
init_sync_d_lag_tables is only executed at the init time, lag_table may not be complete at that point of time. need periodically scan the lag_table.
@qiluo-msft Created an issue to refactor rfc1213.py and rfc2863.py files #23. Will clarify with Liat if someone from MLNX team can contribute to this. |
There are still comments not fully resolved. However, they are not blocking.
* [sonic_ax_impl]: Add support of port channels. - Add port channels support to RFC1213 (1.3.6.1.2.1.2) and RFC2863 (1.3.6.1.2.1.31.1) MIBs. - Read oper state, admin state and MTU value from DB.
This merging breaks unit test. @oleksandrivantsiv Could you help check?
|
RFC2863 (1.3.6.1.2.1.31.1) MIBs.