CLI support for Layer 2 MAC/FDB show #106
Conversation
scripts/fdbshow
Outdated
|
|
||
| def __init__(self): | ||
| super(FdbShow,self).__init__() | ||
| self.db = swsssdk.SonicV2Connector(host="127.0.0.1") |
There was a problem hiding this comment.
host [](start = 43, length = 4)
We prefer using unix socket. #Closed
There was a problem hiding this comment.
As discussed, this format is used by other standalone scripts which also handles the permission issue.
| self.if_br_oid_map[br_port_id] = port_id | ||
|
|
||
|
|
||
| def fetch_fdb_data(self): |
There was a problem hiding this comment.
fetch_fdb_data [](start = 8, length = 14)
I notice code duplication with sonic-snmpagent. Could you reuse code?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Modified to use common library API
scripts/fdbshow
Outdated
| print "Total number of entries {0} ".format(self.FDB_COUNT) | ||
|
|
||
|
|
||
| def display_summary(self): |
There was a problem hiding this comment.
display_summary [](start = 8, length = 15)
I guess you don't need one more function for no filters. Just reuse display_specific(). #Closed
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] |
There was a problem hiding this comment.
Simplify the conditions into one? #Closed
There was a problem hiding this comment.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Agree its slightly complex since I accounted for adding future options. Revisited the logic and made it simple. Thanks for pointing out.
| else: | ||
| fdb.display_specific(args.port, args.vlan) | ||
|
|
||
| except Exception as e: |
There was a problem hiding this comment.
Exception [](start = 11, length = 9)
No need to catch all exceptions.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
If you are arguing about this case, the solution should be catch specific exception, instead of catch all.
|
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. |
|
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 |
There was a problem hiding this comment.
This line is redundant with the import swsssdk line above. Remove whichever is less appropriate.
|
|
||
| from swsssdk import port_util | ||
| from tabulate import tabulate | ||
| from natsort import natsorted |
There was a problem hiding this comment.
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.
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: |
There was a problem hiding this comment.
use if instead of try/except?
|
somehow, I did not see my previous comments. can we add hook to show command show macs |
lguohan
left a comment
There was a problem hiding this comment.
add hook to show commands
lguohan
left a comment
There was a problem hiding this comment.
add hook to show commands.
|
Added hooks to Show CLI command. |
| run_command(cmd) | ||
|
|
||
| # | ||
| # 'mac' command ("show mac ...") |
There was a problem hiding this comment.
mac [](start = 23, length = 3)
I am not sure about other vendors' CLI. Is it more accurate to call it 'show fdb'? #Closed
* 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)
…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.
…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
[202412] Code sync sonic-net/sonic-utilities:202411 => 202412
Support to show Layer 2 MAC entries learnt in Hardware. The entries can also be shown per Port/Vlan