@@ -56,17 +56,24 @@ try: # pragma: no cover
56
56
except KeyError : # pragma: no cover
57
57
pass
58
58
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
61
61
from tabulate import tabulate
62
62
63
63
class FdbShow (object ):
64
64
65
65
HEADER = ['No.' , 'Vlan' , 'MacAddress' , 'Port' , 'Type' ]
66
66
67
- def __init__ (self ):
67
+ def __init__ (self , namespace = None ):
68
68
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
+
70
77
self .if_name_map , \
71
78
self .if_oid_map = port_util .get_interface_oid_map (self .db )
72
79
self .if_br_oid_map = port_util .get_bridge_port_map (self .db )
@@ -169,7 +176,7 @@ class FdbShow(object):
169
176
170
177
print ("Total number of entries {0}" .format (len (self .bridge_mac_list )))
171
178
172
- def validate_params (self , vlan , port , address , entry_type ):
179
+ def validate_params (self , vlan , port , address , entry_type , namespace ):
173
180
if vlan is not None :
174
181
if not vlan .isnumeric ():
175
182
print ("Error: Invalid vlan id {0}" .format (vlan ))
@@ -194,6 +201,15 @@ class FdbShow(object):
194
201
print ("Error: Invalid type {0}" . format (entry_type ))
195
202
return False
196
203
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
+
197
213
return True
198
214
199
215
def main ():
@@ -205,11 +221,12 @@ def main():
205
221
parser .add_argument ('-a' , '--address' , type = str , help = 'FDB display based on specific mac address' , default = None )
206
222
parser .add_argument ('-t' , '--type' , type = str , help = 'FDB display of specific type of mac address' , default = None )
207
223
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 )
208
225
args = parser .parse_args ()
209
226
210
227
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 ):
213
230
sys .exit (1 )
214
231
215
232
fdb .display (args .vlan , args .port , args .address , args .type , args .count )
0 commit comments