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

Add a port index mapper service for sFlow #4794

Merged
merged 2 commits into from
Jun 24, 2020

Conversation

padmanarayana
Copy link
Contributor

- Why I did it

sFlow generates both counter samples and flow samples. While the counter samples contain the ifName, the flow samples have only the interface index - and the index is the Linux ifindex (and not the SONiC port index (as is typically seen in the PORT_TABLE). Any external application (sflow collector / end user) then has to map the index to port index (that's obtained from IF-MIB, say) which is not intuitive.

The SAI driver generates the samples using the Linux indexing scheme. While it is possible to address the issue from SAI driver/SDK perspective, we believe providing a mapping service and letting applications handle the mapping may be a more flexible alternative (which could benefit other applications in future).

- How I did it

Introduce a port_index_mapper script in sflow docker which will:

  1. Use IPDB to construct the initial PORT_INDEX_TABLE table in the STATE DB.
  2. Register a callback that will watch for RTM_NEWLINK/RTM_DELLINK and update the table accordingly.

Note that this currently supports only interfaces supported by port_util.

- How to verify it

  1. Checked that the PORT_INDEX_TABLE gets populated by the script at startup (redis-cli -n 6 keys "PORT_INDEX_TABLE*")
  2. Used scripts to add/remove port channels to verify changes to the table entries.

Verify that the index/ifindex mapping matches that of "ip link show".

- Description for the changelog

Add a port index mapper service for sFlow

- A picture of a cute animal (not mandatory but encouraged)

@lgtm-com
Copy link

lgtm-com bot commented Jun 17, 2020

This pull request introduces 1 alert when merging f1123c4 into edf3160 - view on LGTM.com

new alerts:

  • 1 for Unreachable code

from pyroute2 import IPDB
from swsssdk import SonicV2Connector, port_util

RTM_NEWLINK = 16
Copy link
Contributor

Choose a reason for hiding this comment

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

Does pyroute2.netlink has these definitions?. I don't think we should define these values explicitly.

_hash = '{}|{}'.format(PORT_INDEX_TABLE_NAME, ifname)

if msgtype == RTM_NEWLINK:
state_db.set(state_db.STATE_DB, _hash, 'index', str(index))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think its better to put updating STATE DB to a separate function, as it is called from multiple places.

@lgtm-com
Copy link

lgtm-com bot commented Jun 18, 2020

This pull request introduces 1 alert when merging 4033024 into 7c2f5a0 - view on LGTM.com

new alerts:

  • 1 for Unreachable code

@padmanarayana
Copy link
Contributor Author

retest vsimage please

@prsunny prsunny requested a review from lguohan June 19, 2020 22:33
Copy link
Contributor

@prsunny prsunny left a comment

Choose a reason for hiding this comment

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

Code lgtm. Can you add this new stateDb entry PORT_INDEX_TABLE_NAME to swss-schema.md

@prsunny
Copy link
Contributor

prsunny commented Jun 19, 2020

retest vsimage please

2 similar comments
@padmanarayana
Copy link
Contributor Author

retest vsimage please

@prsunny
Copy link
Contributor

prsunny commented Jun 22, 2020

retest vsimage please

@padmanarayana
Copy link
Contributor Author

github/codeql#3746

@prsunny prsunny merged commit 5cacc20 into sonic-net:master Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants