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

CLI support for Layer 2 MAC/FDB show #106

Merged
merged 12 commits into from
Sep 27, 2017
Merged

Conversation

prsunny
Copy link
Contributor

@prsunny prsunny commented Sep 25, 2017

Support to show Layer 2 MAC entries learnt in Hardware. The entries can also be shown per Port/Vlan

usage: fdbshow [-p PORT] [-v VLAN]
optional arguments:
  -p,  --port              FDB learned on specific port: Ethernet0
  -v,  --vlan              FDB learned on specific Vlan: 1000

Example of the output:
admin@str~$ fdbshow
  No.    Vlan  MacAddress         Port
-----  ------  -----------------  ----------
    1    1000  7C:FE:90:80:9F:05  Ethernet20
    2    1000  7C:FE:90:80:9F:10  Ethernet40
    3    1000  7C:FE:90:80:9F:01  Ethernet4
    4    1000  7C:FE:90:80:9F:02  Ethernet8
Total number of entries 4

scripts/fdbshow Outdated

def __init__(self):
super(FdbShow,self).__init__()
self.db = swsssdk.SonicV2Connector(host="127.0.0.1")
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 25, 2017

Choose a reason for hiding this comment

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

host [](start = 43, length = 4)

We prefer using unix socket. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, this format is used by other standalone scripts which also handles the permission issue.

scripts/fdbshow Outdated
self.if_br_oid_map[br_port_id] = port_id


def fetch_fdb_data(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

fetch_fdb_data [](start = 8, length = 14)

I notice code duplication with sonic-snmpagent. Could you reuse code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked this in detail to see if we can reuse some functionality but there is tight coupling with MIB and SNMP functionality. Since this is a standalone functionality, thought of keeping it separate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified to use common library API

scripts/fdbshow Outdated
print "Total number of entries {0} ".format(self.FDB_COUNT)


def display_summary(self):
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 25, 2017

Choose a reason for hiding this comment

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

display_summary [](start = 8, length = 15)

I guess you don't need one more function for no filters. Just reuse display_specific(). #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

scripts/fdbshow Outdated
vlan = int(vlan)
s_index = self.get_iter_index(vlan)
fdb_list = [fdb for fdb in self.bridge_mac_list[s_index:]
if fdb[0] == vlan and fdb[2] == port]
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 25, 2017

Choose a reason for hiding this comment

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

Simplify the conditions into one? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is not simplified, and become more complex...


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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it now handles the three conditions -
1 - All arguments None
2 - Some arguments None
3 - None of the arguments are None.
Could you suggest a different way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree its slightly complex since I accounted for adding future options. Revisited the logic and made it simple. Thanks for pointing out.

scripts/fdbshow Outdated
else:
fdb.display_specific(args.port, args.vlan)

except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Exception [](start = 11, length = 9)

No need to catch all exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we discussed, I removed this and checked. But observed that in case of invalid inputs, in addition to displaying the error message, it also gives the trace back which is not expected. For e.g:

admin@str-s6000-acs-7:~$ ./fdbshow -v 1001
Traceback (most recent call last):
File "./fdbshow", line 182, in
main()
File "./fdbshow", line 179, in main
fdb.display(args.vlan, args.port)
File "./fdbshow", line 158, in display
s_index = self.get_iter_index(arg_list[m_index], m_index)
File "./fdbshow", line 127, in get_iter_index
return keys.index(key_value)
ValueError: 1001 is not in list

Whereas, with the exception is would be:

admin@str-s6000-acs-7:~$ ./fdbshow -v 1001
1001 is not in list

Copy link
Contributor

Choose a reason for hiding this comment

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

If you are arguing about this case, the solution should be catch specific exception, instead of catch all.

@qiluo-msft
Copy link
Contributor

qiluo-msft commented Sep 26, 2017

install_requires=[

Should we add swsssdk as a dependency here? #Closed


Refers to: setup.py:45 in 25f704d. [](commit_id = 25f704d, deletion_comment = False)

@prsunny
Copy link
Contributor Author

prsunny commented Sep 26, 2017

I don't think swsssdk is required in setup.py. It says it's mainly used to install dependencies when the project is installed using 'pip'. Also swsssdk is used by other scripts files in the same repo.

@jleveque
Copy link
Contributor

I don't think it would hurt to add swsssdk in the list of dependencies. I think it was overlooked in the past.

scripts/fdbshow Outdated
import json
import sys

from swsssdk import port_util
Copy link
Contributor

@jleveque jleveque Sep 26, 2017

Choose a reason for hiding this comment

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

This line is redundant with the import swsssdk line above. Remove whichever is less appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

scripts/fdbshow Outdated

from swsssdk import port_util
from tabulate import tabulate
from natsort import natsorted
Copy link
Contributor

Choose a reason for hiding this comment

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

Please reorder so that import ... statements are ordered alphabetically followed by from ... import ... statements ordered alphabetically. This makes it easier to locate used packages/modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@sonic-net sonic-net deleted a comment from msftclas Sep 27, 2017
scripts/fdbshow Outdated

ent = self.db.get_all('ASIC_DB', s, blocking=True)
br_port_id = ent[b"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"][oid_pfx:]
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

use if instead of try/except?

@lguohan
Copy link
Contributor

lguohan commented Sep 27, 2017

somehow, I did not see my previous comments.

can we add hook to show command

show macs
show macs [-v vlan]
show macs [-p port]

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.

add hook to show commands

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.

add hook to show commands.

@prsunny
Copy link
Contributor Author

prsunny commented Sep 27, 2017

Added hooks to Show CLI command.

@@ -226,6 +226,25 @@ def sfp(interfacename):

run_command(cmd)

#
# 'mac' command ("show mac ...")
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 27, 2017

Choose a reason for hiding this comment

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

mac [](start = 23, length = 3)

I am not sure about other vendors' CLI. Is it more accurate to call it 'show fdb'? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lguohan , can you suggest?

@prsunny prsunny merged commit 206aabe into sonic-net:master Sep 27, 2017
zhenggen-xu pushed a commit to zhenggen-xu/sonic-utilities that referenced this pull request Jun 6, 2018
* msft_github/master:
  Enhancement of 'show' commands and addition of 'debug', and 'undebug'… (sonic-net#113)
  CLI support for Layer 2 MAC/FDB show  (sonic-net#106)
  [show]: Add 'show interfaces alias' command to display port name/alias mapping (sonic-net#107)
  Add 'ipv6' group along with 'bgp' and 'route' subcommands; Remove duplicate commands ('bgp,' 'route') from under root group (sonic-net#102)
  [generate_dump]: Skip the sparse file /var/log/lastlog (sonic-net#104)
  Added syncd SAI dump to sysdump script (sonic-net#89)
  Adapt to new minigraph_parser schema (sonic-net#103)
  [core dump] remove number of parameter assumption from script coredump-compress
  [FastReboot]: Update FR to make it working with 1.0.3 (sonic-net#95)
vdahiya12 pushed a commit to vdahiya12/sonic-utilities that referenced this pull request Jul 23, 2021
…ies in setup.py (sonic-net#106)

Remove dependence on the 'enum' package, as we are currently transitioning from Python 2 to Python 3 and there are installation conflict issues between the `enum` package and the `enum34` package.

Add 'sonic-py-common' as dependencies in setup.py for xcvrd, also add spaces around "equals" signs.
mihirpat1 pushed a commit to mihirpat1/sonic-utilities that referenced this pull request Sep 15, 2023
…onic-net#106)

To support the component firmware automatic update, add auto_update_firmware() to platform component api
This is to support fwutil auto_update command to update the platform component firmware automatically.
Fwutil HLD to support auto_update interfaces/commands.
sonic-net/SONiC#648
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.

7 participants