Skip to content
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

Merged
merged 4 commits into from
May 8, 2017

Conversation

oleksandrivantsiv
Copy link
Collaborator

  • 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.

- 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)
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

"""
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)
Copy link
Contributor

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.

@lguohan
Copy link
Contributor

lguohan commented Apr 27, 2017

@qiluo-msft, canyou review?

return int(n) + 1
patterns = {
SONIC_ETHERNET_RE_PATTERN: 1,
SONIC_PORTCHANNEL_RE_PATTERN: 1000
Copy link
Contributor

@qiluo-msft qiluo-msft Apr 27, 2017

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

Copy link
Collaborator Author

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


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)
Copy link
Contributor

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?

Copy link
Collaborator Author

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?

if_name_lag_name_map = {}

for lag_entry in lag_entries:
lag_name = lag_entry[len(b"LAG_TABLE:"):]
Copy link
Contributor

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More readable.


In reply to: 113862724 [](ancestors = 113862724)


# { 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)}
Copy link
Contributor

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?

Copy link
Collaborator Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you optimize it to once?


In reply to: 113880393 [](ancestors = 113880393)

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]
Copy link
Contributor

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.

Copy link
Collaborator Author

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

Copy link
Collaborator Author

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.

Copy link
Contributor

@qiluo-msft qiluo-msft Apr 28, 2017

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)

Copy link
Collaborator Author

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.

@qiluo-msft
Copy link
Contributor

qiluo-msft commented Apr 27, 2017

        return counter_value

We can cache this return value, so if recursion happens, it can be fetch back immediately.


Refers to: src/sonic_ax_impl/mibs/ietf/rfc1213.py:152 in 61c87fb. [](commit_id = 61c87fb, deletion_comment = False)

@qiluo-msft
Copy link
Contributor

def interface_name(self, sub_id):

I notice lots functions are the same as rfc1213. Suggest to refactor.


Refers to: src/sonic_ax_impl/mibs/ietf/rfc2863.py:73 in 61c87fb. [](commit_id = 61c87fb, deletion_comment = False)

Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As comments

@oleksandrivantsiv
Copy link
Collaborator Author

Refactor is not in scope of this commit. Suggest to create an enhancement

"""
db_conn.connect(APPL_DB)

lag_entries = db_conn.keys(APPL_DB, b"LAG_TABLE:*")
Copy link
Contributor

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.

Copy link
Collaborator Author

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@lguohan lguohan left a 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.

@oleksandrivantsiv
Copy link
Collaborator Author

@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.

@qiluo-msft qiluo-msft dismissed their stale review May 5, 2017 23:33

There are still comments not fully resolved. However, they are not blocking.

lguohan pushed a commit that referenced this pull request May 8, 2017
* [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.
@lguohan lguohan merged commit 74e57b8 into sonic-net:master May 8, 2017
@qiluo-msft
Copy link
Contributor

This merging breaks unit test. @oleksandrivantsiv Could you help check?

pytest -s -k tests/test_interfaces.py

@qiluo-msft qiluo-msft mentioned this pull request May 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants