Skip to content

Commit eb8911e

Browse files
committed
feat: support namespace arg for show mac
1 parent aa52db8 commit eb8911e

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

doc/Command-Reference.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11827,12 +11827,13 @@ This command displays the MAC (FDB) entries either in full or partial as given b
1182711827
4) show mac -a <mac-address> - display the MACs that match a specific mac-address
1182811828
5) show mac -t <type> - display the MACs that match a specific type (static/dynamic)
1182911829
6) show mac -c - display the count of MAC addresses
11830+
7) show mac -n <namespace> - display the MACs that belong to a specific namespace
1183011831

1183111832
To show the default MAC address aging time on the switch.
1183211833

1183311834
- Usage:
1183411835
```
11835-
show mac [-v <vlan_id>] [-p <port_name>] [-a <mac_address>] [-t <type>] [-c]
11836+
show mac [-v <vlan_id>] [-p <port_name>] [-a <mac_address>] [-t <type>] [-c] [-n <namespace>]
1183611837
```
1183711838

1183811839
- Example:
@@ -11931,6 +11932,14 @@ Optionally, you can specify a VLAN ID or interface name or type or mac-address i
1193111932
admin@sonic:~$ show mac -c
1193211933
Total number of entries 18
1193311934
```
11935+
```
11936+
admin@sonic:~$ show mac -n asic0
11937+
No. Vlan MacAddress Port Type
11938+
----- ------ ----------------- ----------- -------
11939+
2 1000 50:96:23:AD:F1:65 Ethernet192 Static
11940+
2 1000 C6:C9:5E:AE:24:42 Ethernet192 Static
11941+
Total number of entries 2
11942+
```
1193411943

1193511944
**show mac aging-time**
1193611945

scripts/fdbshow

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,24 @@ try: # pragma: no cover
5656
except KeyError: # pragma: no cover
5757
pass
5858

59-
from sonic_py_common import port_util
60-
from swsscommon.swsscommon import SonicV2Connector
59+
from sonic_py_common import port_util, multi_asic
60+
from swsscommon.swsscommon import SonicV2Connector, SonicDBConfig
6161
from tabulate import tabulate
6262

6363
class FdbShow(object):
6464

6565
HEADER = ['No.', 'Vlan', 'MacAddress', 'Port', 'Type']
6666

67-
def __init__(self):
67+
def __init__(self, namespace=None):
6868
super(FdbShow,self).__init__()
69-
self.db = SonicV2Connector(host="127.0.0.1")
69+
if namespace is not None:
70+
if not SonicDBConfig.isGlobalInit():
71+
SonicDBConfig.load_sonic_global_db_config()
72+
73+
self.db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
74+
else:
75+
self.db = SonicV2Connector(host="127.0.0.1")
76+
7077
self.if_name_map, \
7178
self.if_oid_map = port_util.get_interface_oid_map(self.db)
7279
self.if_br_oid_map = port_util.get_bridge_port_map(self.db)
@@ -169,7 +176,7 @@ class FdbShow(object):
169176

170177
print("Total number of entries {0}".format(len(self.bridge_mac_list)))
171178

172-
def validate_params(self, vlan, port, address, entry_type):
179+
def validate_params(self, vlan, port, address, entry_type, namespace):
173180
if vlan is not None:
174181
if not vlan.isnumeric():
175182
print("Error: Invalid vlan id {0}".format(vlan))
@@ -194,6 +201,15 @@ class FdbShow(object):
194201
print("Error: Invalid type {0}". format(entry_type))
195202
return False
196203

204+
if namespace is not None:
205+
if not multi_asic.is_multi_asic():
206+
print("Error: Namespace is not supported in single asic")
207+
return False
208+
209+
if namespace not in multi_asic.get_namespace_list():
210+
print("Error: Invalid namespace {0}".format(namespace))
211+
return False
212+
197213
return True
198214

199215
def main():
@@ -205,11 +221,12 @@ def main():
205221
parser.add_argument('-a', '--address', type=str, help='FDB display based on specific mac address', default=None)
206222
parser.add_argument('-t', '--type', type=str, help='FDB display of specific type of mac address', default=None)
207223
parser.add_argument('-c', '--count', action='store_true', help='FDB display count of mac address')
224+
parser.add_argument('-n', '--namespace', type=str, help='Namespace name or all', default=None)
208225
args = parser.parse_args()
209226

210227
try:
211-
fdb = FdbShow()
212-
if not fdb.validate_params(args.vlan, args.port, args.address, args.type):
228+
fdb = FdbShow(namespace=args.namespace)
229+
if not fdb.validate_params(args.vlan, args.port, args.address, args.type, args.namespace):
213230
sys.exit(1)
214231

215232
fdb.display(args.vlan, args.port, args.address, args.type, args.count)

show/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,8 @@ def pwm_headroom_pool(namespace):
11211121
@click.option('-t', '--type')
11221122
@click.option('-c', '--count', is_flag=True)
11231123
@click.option('--verbose', is_flag=True, help="Enable verbose output")
1124-
def mac(ctx, vlan, port, address, type, count, verbose):
1124+
@multi_asic_util.multi_asic_click_option_namespace
1125+
def mac(ctx, vlan, port, address, type, count, verbose, namespace):
11251126
"""Show MAC (FDB) entries"""
11261127

11271128
if ctx.invoked_subcommand is not None:
@@ -1144,6 +1145,9 @@ def mac(ctx, vlan, port, address, type, count, verbose):
11441145
if count:
11451146
cmd += ["-c"]
11461147

1148+
if namespace is not None:
1149+
cmd += ['-n', str(namespace)]
1150+
11471151
run_command(cmd, display_cmd=verbose)
11481152

11491153
@mac.command('aging-time')

0 commit comments

Comments
 (0)