forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmuxcable.py
2486 lines (1909 loc) · 103 KB
/
muxcable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json
import sys
import time
import click
import re
import utilities_common.cli as clicommon
from natsort import natsorted
from collections import OrderedDict
from operator import itemgetter
from sonic_py_common import multi_asic
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
from swsscommon import swsscommon
from tabulate import tabulate
from utilities_common import platform_sfputil_helper
from utilities_common.general import get_optional_value_for_key_in_config_tbl
platform_sfputil = None
REDIS_TIMEOUT_MSECS = 0
SELECT_TIMEOUT = 1000
HWMODE_MUXDIRECTION_TIMEOUT = 0.5
# The empty namespace refers to linux host namespace.
EMPTY_NAMESPACE = ''
CONFIG_SUCCESSFUL = 0
CONFIG_FAIL = 1
EXIT_FAIL = 1
EXIT_SUCCESS = 0
STATUS_FAIL = 1
STATUS_SUCCESSFUL = 0
VENDOR_NAME = "Credo"
VENDOR_MODEL_REGEX = re.compile(r"CAC\w{3}321P2P\w{2}MS")
#define table names that interact with Cli
XCVRD_GET_BER_CMD_TABLE = "XCVRD_GET_BER_CMD"
XCVRD_GET_BER_RSP_TABLE = "XCVRD_GET_BER_RSP"
XCVRD_GET_BER_RES_TABLE = "XCVRD_GET_BER_RES"
XCVRD_GET_BER_CMD_ARG_TABLE = "XCVRD_GET_BER_CMD_ARG"
def get_asic_index_for_port(port):
asic_index = None
if platform_sfputil is not None:
asic_index = platform_sfputil_helper.get_asic_id_for_logical_port(port)
if asic_index is None:
# TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
# is fully mocked
import sonic_platform_base.sonic_sfp.sfputilhelper
asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port)
if asic_index is None:
port_name = platform_sfputil_helper.get_interface_alias(port, db)
click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port_name))
return 0
return asic_index
def db_connect(db_name, namespace=EMPTY_NAMESPACE):
return swsscommon.DBConnector(db_name, REDIS_TIMEOUT_MSECS, True, namespace)
def delete_all_keys_in_db_table(db_type, table_name):
redis_db = {}
table = {}
table_keys = {}
namespaces = multi_asic.get_front_end_namespaces()
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
redis_db[asic_id] = db_connect(db_type, namespace)
table[asic_id] = swsscommon.Table(redis_db[asic_id], table_name)
table_keys[asic_id] = table[asic_id].getKeys()
for key in table_keys[asic_id]:
table[asic_id]._del(key)
target_dict = { "NIC":"0",
"TORA":"1",
"TORB":"2",
"LOCAL":"3"}
def parse_target(target):
return target_dict.get(target, None)
def check_port_in_mux_cable_table(port):
per_npu_configdb = {}
mux_tbl_cfg_db = {}
port_mux_tbl_keys = {}
# Getting all front asic namespace and correspding config and state DB connector
namespaces = multi_asic.get_front_end_namespaces()
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
# TO-DO replace the macros with correct swsscommon names
per_npu_configdb[asic_id] = ConfigDBConnector(use_unix_socket_path=False, namespace=namespace)
per_npu_configdb[asic_id].connect()
mux_tbl_cfg_db[asic_id] = per_npu_configdb[asic_id].get_table("MUX_CABLE")
port_mux_tbl_keys[asic_id] = mux_tbl_cfg_db[asic_id].keys()
asic_index = None
if platform_sfputil is not None:
asic_index = platform_sfputil_helper.get_asic_id_for_logical_port(port)
if asic_index is None:
# TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
# is fully mocked
import sonic_platform_base.sonic_sfp.sfputilhelper
asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port)
if asic_index is None:
click.echo("Got invalid asic index for port {}, cant retrieve mux cable table entries".format(port))
return False
if port in port_mux_tbl_keys[asic_index]:
return True
return False
def get_per_port_firmware(port):
state_db = {}
mux_info_dict = {}
mux_info_full_dict = {}
# Getting all front asic namespace and correspding config and state DB connector
namespaces = multi_asic.get_front_end_namespaces()
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
state_db[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
state_db[asic_id].connect(state_db[asic_id].STATE_DB)
if platform_sfputil is not None:
asic_index = platform_sfputil_helper.get_asic_id_for_logical_port(port)
if asic_index is None:
# TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
# is fully mocked
import sonic_platform_base.sonic_sfp.sfputilhelper
asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port)
if asic_index is None:
click.echo("Got invalid asic index for port {}, cant retrieve mux cable table entries".format(port))
return False
mux_info_full_dict[asic_index] = state_db[asic_index].get_all(
state_db[asic_index].STATE_DB, 'MUX_CABLE_INFO|{}'.format(port))
res_dir = {}
res_dir = mux_info_full_dict[asic_index]
mux_info_dict["version_nic_active"] = res_dir.get("version_nic_active", None)
mux_info_dict["version_nic_inactive"] = res_dir.get("version_nic_inactive", None)
mux_info_dict["version_nic_next"] = res_dir.get("version_nic_next", None)
mux_info_dict["version_peer_active"] = res_dir.get("version_peer_active", None)
mux_info_dict["version_peer_inactive"] = res_dir.get("version_peer_inactive", None)
mux_info_dict["version_peer_next"] = res_dir.get("version_peer_next", None)
mux_info_dict["version_self_active"] = res_dir.get("version_self_active", None)
mux_info_dict["version_self_inactive"] = res_dir.get("version_self_inactive", None)
mux_info_dict["version_self_next"] = res_dir.get("version_self_next", None)
return mux_info_dict
def get_response_for_version(port, mux_info_dict):
state_db = {}
xcvrd_show_fw_res_tbl = {}
namespaces = multi_asic.get_front_end_namespaces()
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
state_db[asic_id] = db_connect("STATE_DB", namespace)
xcvrd_show_fw_res_tbl[asic_id] = swsscommon.Table(state_db[asic_id], "XCVRD_SHOW_FW_RES")
logical_port_list = platform_sfputil_helper.get_logical_list()
if port not in logical_port_list:
click.echo("ERR: This is not a valid port, valid ports ({})".format(", ".join(logical_port_list)))
rc = EXIT_FAIL
res_dict[1] = rc
return mux_info_dict
asic_index = None
if platform_sfputil is not None:
asic_index = platform_sfputil_helper.get_asic_id_for_logical_port(port)
if asic_index is None:
# TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
# is fully mocked
import sonic_platform_base.sonic_sfp.sfputilhelper
asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port)
if asic_index is None:
click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port))
rc = CONFIG_FAIL
res_dict[1] = rc
return mux_info_dict
(status, fvp) = xcvrd_show_fw_res_tbl[asic_index].get(port)
res_dir = dict(fvp)
mux_info_dict["version_nic_active"] = res_dir.get("version_nic_active", None)
mux_info_dict["version_nic_inactive"] = res_dir.get("version_nic_inactive", None)
mux_info_dict["version_nic_next"] = res_dir.get("version_nic_next", None)
mux_info_dict["version_peer_active"] = res_dir.get("version_peer_active", None)
mux_info_dict["version_peer_inactive"] = res_dir.get("version_peer_inactive", None)
mux_info_dict["version_peer_next"] = res_dir.get("version_peer_next", None)
mux_info_dict["version_self_active"] = res_dir.get("version_self_active", None)
mux_info_dict["version_self_inactive"] = res_dir.get("version_self_inactive", None)
mux_info_dict["version_self_next"] = res_dir.get("version_self_next", None)
return mux_info_dict
def get_event_logs(port, res_dict, mux_info_dict):
state_db = {}
xcvrd_show_fw_res_tbl = {}
namespaces = multi_asic.get_front_end_namespaces()
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
state_db[asic_id] = db_connect("STATE_DB", namespace)
xcvrd_show_fw_res_tbl[asic_id] = swsscommon.Table(state_db[asic_id], "XCVRD_EVENT_LOG_RES")
logical_port_list = platform_sfputil_helper.get_logical_list()
if port not in logical_port_list:
click.echo("ERR: This is not a valid port, valid ports ({})".format(", ".join(logical_port_list)))
rc = EXIT_FAIL
res_dict[1] = rc
return mux_info_dict
asic_index = None
if platform_sfputil is not None:
asic_index = platform_sfputil_helper.get_asic_id_for_logical_port(port)
if asic_index is None:
# TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
# is fully mocked
import sonic_platform_base.sonic_sfp.sfputilhelper
asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port)
if asic_index is None:
click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port))
rc = CONFIG_FAIL
res_dict[1] = rc
return mux_info_dict
(status, fvp) = xcvrd_show_fw_res_tbl[asic_index].get(port)
res_dir = dict(fvp)
for key, value in res_dir.items():
mux_info_dict[key] = value;
return mux_info_dict
def get_result(port, res_dict, cmd ,result, table_name):
state_db = {}
xcvrd_show_fw_res_tbl = {}
namespaces = multi_asic.get_front_end_namespaces()
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
state_db[asic_id] = db_connect("STATE_DB", namespace)
xcvrd_show_fw_res_tbl[asic_id] = swsscommon.Table(state_db[asic_id], table_name)
logical_port_list = platform_sfputil_helper.get_logical_list()
if port not in logical_port_list:
click.echo("ERR: This is not a valid port, valid ports ({})".format(", ".join(logical_port_list)))
rc = EXIT_FAIL
res_dict[1] = rc
return result
asic_index = None
if platform_sfputil is not None:
asic_index = platform_sfputil_helper.get_asic_id_for_logical_port(port)
if asic_index is None:
# TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
# is fully mocked
import sonic_platform_base.sonic_sfp.sfputilhelper
asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port)
if asic_index is None:
click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port))
rc = CONFIG_FAIL
res_dict[1] = rc
return result
(status, fvp) = xcvrd_show_fw_res_tbl[asic_index].get(port)
res_dir = dict(fvp)
delete_all_keys_in_db_table("STATE_DB", table_name)
return res_dir
def update_and_get_response_for_xcvr_cmd(cmd_name, rsp_name, exp_rsp, cmd_table_name, cmd_arg_table_name, rsp_table_name , res_table_name, port, cmd_timeout_secs, param_dict= None, arg=None):
res_dict = {}
state_db, appl_db = {}, {}
firmware_rsp_tbl, firmware_rsp_tbl_keys = {}, {}
firmware_rsp_sub_tbl = {}
firmware_cmd_tbl = {}
firmware_cmd_arg_tbl = {}
CMD_TIMEOUT_SECS = cmd_timeout_secs
time_start = time.time()
delete_all_keys_in_db_tables_helper(cmd_table_name, rsp_table_name, cmd_arg_table_name, res_table_name)
sel = swsscommon.Select()
namespaces = multi_asic.get_front_end_namespaces()
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
state_db[asic_id] = db_connect("STATE_DB", namespace)
appl_db[asic_id] = db_connect("APPL_DB", namespace)
firmware_cmd_tbl[asic_id] = swsscommon.Table(appl_db[asic_id], cmd_table_name)
firmware_rsp_sub_tbl[asic_id] = swsscommon.SubscriberStateTable(state_db[asic_id], rsp_table_name)
firmware_rsp_tbl[asic_id] = swsscommon.Table(state_db[asic_id], rsp_table_name)
if cmd_arg_table_name is not None:
firmware_cmd_arg_tbl[asic_id] = swsscommon.Table(appl_db[asic_id], cmd_arg_table_name)
firmware_rsp_tbl_keys[asic_id] = firmware_rsp_tbl[asic_id].getKeys()
for key in firmware_rsp_tbl_keys[asic_id]:
firmware_rsp_tbl[asic_id]._del(key)
sel.addSelectable(firmware_rsp_sub_tbl[asic_id])
rc = CONFIG_FAIL
res_dict[0] = CONFIG_FAIL
res_dict[1] = 'unknown'
logical_port_list = platform_sfputil_helper.get_logical_list()
if port not in logical_port_list:
click.echo("ERR: This is not a valid port, valid ports ({})".format(", ".join(logical_port_list)))
res_dict[0] = rc
return res_dict
asic_index = None
if platform_sfputil is not None:
asic_index = platform_sfputil_helper.get_asic_id_for_logical_port(port)
if asic_index is None:
# TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
# is fully mocked
import sonic_platform_base.sonic_sfp.sfputilhelper
asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port)
if asic_index is None:
click.echo("Got invalid asic index for port {}, cant perform firmware cmd".format(port))
res_dict[0] = rc
return res_dict
if arg is None:
cmd_arg = "null"
else:
cmd_arg = str(arg)
if param_dict is not None:
for key, value in param_dict.items():
fvs = swsscommon.FieldValuePairs([(str(key), str(value))])
firmware_cmd_arg_tbl[asic_index].set(port, fvs)
fvs = swsscommon.FieldValuePairs([(cmd_name, cmd_arg)])
firmware_cmd_tbl[asic_index].set(port, fvs)
# Listen indefinitely for changes to the HW_MUX_CABLE_TABLE in the Application DB's
while True:
# Use timeout to prevent ignoring the signals we want to handle
# in signal_handler() (e.g. SIGTERM for graceful shutdown)
(state, selectableObj) = sel.select(SELECT_TIMEOUT)
time_now = time.time()
time_diff = time_now - time_start
if time_diff >= CMD_TIMEOUT_SECS:
return res_dict
if state == swsscommon.Select.TIMEOUT:
# Do not flood log when select times out
continue
if state != swsscommon.Select.OBJECT:
click.echo("sel.select() did not return swsscommon.Select.OBJECT for sonic_y_cable updates")
continue
# Get the redisselect object from selectable object
redisSelectObj = swsscommon.CastSelectableToRedisSelectObj(
selectableObj)
# Get the corresponding namespace from redisselect db connector object
namespace = redisSelectObj.getDbConnector().getNamespace()
asic_index = multi_asic.get_asic_index_from_namespace(namespace)
(port_m, op_m, fvp_m) = firmware_rsp_sub_tbl[asic_index].pop()
if not port_m:
click.echo("Did not receive a port response {}".format(port))
res_dict[1] = 'unknown'
res_dict[0] = CONFIG_FAIL
firmware_rsp_tbl[asic_index]._del(port)
break
if port_m != port:
res_dict[1] = 'unknown'
res_dict[0] = CONFIG_FAIL
firmware_rsp_tbl[asic_index]._del(port)
continue
if fvp_m:
fvp_dict = dict(fvp_m)
if rsp_name in fvp_dict:
# check if xcvrd got a probe command
result = fvp_dict[rsp_name]
res_dict[1] = result
res_dict[0] = 0
else:
res_dict[1] = 'unknown'
res_dict[0] = CONFIG_FAIL
firmware_rsp_tbl[asic_index]._del(port)
break
else:
res_dict[1] = 'unknown'
res_dict[0] = CONFIG_FAIL
firmware_rsp_tbl[asic_index]._del(port)
break
delete_all_keys_in_db_tables_helper(cmd_table_name, rsp_table_name, cmd_arg_table_name, None)
return res_dict
def delete_all_keys_in_db_tables_helper(cmd_table_name, rsp_table_name, cmd_arg_table_name = None, res_table_name = None):
delete_all_keys_in_db_table("APPL_DB", cmd_table_name)
delete_all_keys_in_db_table("STATE_DB", rsp_table_name)
if cmd_arg_table_name is not None:
delete_all_keys_in_db_table("APPL_DB", cmd_arg_table_name)
if res_table_name is not None:
delete_all_keys_in_db_table("STATE_DB", res_table_name)
return 0
# 'muxcable' command ("show muxcable")
#
@click.group(name='muxcable', cls=clicommon.AliasedGroup)
def muxcable():
"""SONiC command line - 'show muxcable' command"""
global platform_sfputil
# Load platform-specific sfputil class
platform_sfputil_helper.load_platform_sfputil()
# Load port info
platform_sfputil_helper.platform_sfputil_read_porttab_mappings()
platform_sfputil = platform_sfputil_helper.platform_sfputil
def get_value_for_key_in_dict(mdict, port, key, table_name):
value = mdict.get(key, None)
if value is None:
click.echo("could not retrieve key {} value for port {} inside table {}".format(key, port, table_name))
sys.exit(STATUS_FAIL)
return value
def get_value_for_key_in_config_tbl(config_db, port, key, table):
info_dict = {}
info_dict = config_db.get_entry(table, port)
if info_dict is None:
click.echo("could not retrieve key {} value for port {} inside table {}".format(key, port, table))
sys.exit(STATUS_FAIL)
value = get_value_for_key_in_dict(info_dict, port, key, table)
return value
def get_switch_name(config_db):
info_dict = {}
info_dict = config_db.get_entry("DEVICE_METADATA", "localhost")
#click.echo("{} ".format(info_dict))
switch_name = get_value_for_key_in_dict(info_dict, "localhost", "peer_switch", "DEVICE_METADATA")
if switch_name is not None:
return switch_name
else:
click.echo("could not retreive switch name")
sys.exit(STATUS_FAIL)
def create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict, muxcable_grpc_dict, muxcable_health_dict, muxcable_metrics_dict, asic_index, port):
res_dict = {}
status_value = get_value_for_key_in_dict(muxcable_info_dict[asic_index], port, "state", "MUX_CABLE_TABLE")
port_name = platform_sfputil_helper.get_interface_alias(port, db)
port_status_dict["MUX_CABLE"][port_name] = {}
port_status_dict["MUX_CABLE"][port_name]["STATUS"] = status_value
gRPC_value = get_value_for_key_in_dict(muxcable_grpc_dict[asic_index], port, "state", "MUX_CABLE_TABLE")
port_status_dict["MUX_CABLE"][port_name]["SERVER_STATUS"] = gRPC_value
health_value = get_value_for_key_in_dict(muxcable_health_dict[asic_index], port, "state", "MUX_LINKMGR_TABLE")
port_status_dict["MUX_CABLE"][port_name]["HEALTH"] = health_value
res_dict = get_hwmode_mux_direction_port(db, port)
if res_dict[2] == "False":
hwstatus = "absent"
elif res_dict[1] == "not Y-Cable port":
hwstatus = "not Y-Cable port"
elif res_dict[1] == status_value:
hwstatus = "consistent"
else:
hwstatus = "inconsistent"
port_status_dict["MUX_CABLE"][port_name]["HWSTATUS"] = hwstatus
last_switch_end_time = ""
if "linkmgrd_switch_standby_end" in muxcable_metrics_dict[asic_index]:
last_switch_end_time = muxcable_metrics_dict[asic_index].get("linkmgrd_switch_standby_end")
elif "linkmgrd_switch_active_end" in muxcable_metrics_dict[asic_index]:
last_switch_end_time = muxcable_metrics_dict[asic_index].get("linkmgrd_switch_active_end")
port_status_dict["MUX_CABLE"][port_name]["LAST_SWITCHOVER_TIME"] = last_switch_end_time
def create_table_dump_per_port_status(db, print_data, muxcable_info_dict, muxcable_grpc_dict, muxcable_health_dict, muxcable_metrics_dict, asic_index, port):
print_port_data = []
res_dict = {}
res_dict = get_hwmode_mux_direction_port(db, port)
status_value = get_value_for_key_in_dict(muxcable_info_dict[asic_index], port, "state", "MUX_CABLE_TABLE")
#status_value = get_value_for_key_in_tbl(y_cable_asic_table, port, "status")
gRPC_value = get_value_for_key_in_dict(muxcable_grpc_dict[asic_index], port, "state", "MUX_CABLE_TABLE")
health_value = get_value_for_key_in_dict(muxcable_health_dict[asic_index], port, "state", "MUX_LINKMGR_TABLE")
last_switch_end_time = ""
if "linkmgrd_switch_standby_end" in muxcable_metrics_dict[asic_index]:
last_switch_end_time = muxcable_metrics_dict[asic_index].get("linkmgrd_switch_standby_end")
elif "linkmgrd_switch_active_end" in muxcable_metrics_dict[asic_index]:
last_switch_end_time = muxcable_metrics_dict[asic_index].get("linkmgrd_switch_active_end")
port_name = platform_sfputil_helper.get_interface_alias(port, db)
print_port_data.append(port_name)
print_port_data.append(status_value)
print_port_data.append(gRPC_value)
print_port_data.append(health_value)
if res_dict[2] == "False":
hwstatus = "absent"
elif res_dict[1] == "not Y-Cable port":
hwstatus = "not Y-Cable port"
elif res_dict[1] == status_value:
hwstatus = "consistent"
else:
hwstatus = "inconsistent"
print_port_data.append(hwstatus)
print_port_data.append(last_switch_end_time)
print_data.append(print_port_data)
def create_table_dump_per_port_config(db ,print_data, per_npu_configdb, asic_id, port, is_dualtor_active_active):
port_list = []
port_name = platform_sfputil_helper.get_interface_alias(port, db)
port_list.append(port_name)
state_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "state", "MUX_CABLE")
port_list.append(state_value)
ipv4_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "server_ipv4", "MUX_CABLE")
port_list.append(ipv4_value)
ipv6_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "server_ipv6", "MUX_CABLE")
port_list.append(ipv6_value)
cable_type = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "cable_type", "MUX_CABLE")
if cable_type is not None:
port_list.append(cable_type)
soc_ipv4_value = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "soc_ipv4", "MUX_CABLE")
if soc_ipv4_value is not None:
port_list.append(soc_ipv4_value)
is_dualtor_active_active[0] = True
soc_ipv6_value = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "soc_ipv6", "MUX_CABLE")
if soc_ipv6_value is not None:
if cable_type is None:
port_list.append("")
if soc_ipv4_value is None:
port_list.append("")
port_list.append(soc_ipv6_value)
print_data.append(port_list)
def create_json_dump_per_port_config(db, port_status_dict, per_npu_configdb, asic_id, port):
state_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "state", "MUX_CABLE")
port_name = platform_sfputil_helper.get_interface_alias(port, db)
port_status_dict["MUX_CABLE"]["PORTS"][port_name] = {"STATE": state_value}
port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"] = {}
ipv4_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "server_ipv4", "MUX_CABLE")
port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["IPv4"] = ipv4_value
ipv6_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "server_ipv6", "MUX_CABLE")
port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["IPv6"] = ipv6_value
cable_type = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "cable_type", "MUX_CABLE")
if cable_type is not None:
port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["cable_type"] = cable_type
soc_ipv4_value = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "soc_ipv4", "MUX_CABLE")
if soc_ipv4_value is not None:
port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["soc_ipv4"] = soc_ipv4_value
soc_ipv6_value = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "soc_ipv6", "MUX_CABLE")
if soc_ipv6_value is not None:
port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["soc_ipv6"] = soc_ipv6_value
def get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_id, port):
mux_cfg_dict = per_npu_configdb[asic_id].get_all(
per_npu_configdb[asic_id].CONFIG_DB, 'MUX_CABLE|{}'.format(port))
dest_names = ["server_ipv4", "server_ipv6", "soc_ipv4", "soc_ipv6"]
for name in dest_names:
dest_address = mux_cfg_dict.get(name, None)
if dest_address is not None:
kernel_route_keys = per_npu_appl_db[asic_id].keys(
per_npu_appl_db[asic_id].APPL_DB, 'TUNNEL_ROUTE_TABLE:*{}'.format(dest_address))
if_kernel_tunnel_route_programed = kernel_route_keys is not None and len(kernel_route_keys)
asic_route_keys = per_npu_asic_db[asic_id].keys(
per_npu_asic_db[asic_id].ASIC_DB, 'ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY:*{}*'.format(dest_address))
if_asic_tunnel_route_programed = asic_route_keys is not None and len(asic_route_keys)
if if_kernel_tunnel_route_programed or if_asic_tunnel_route_programed:
port_tunnel_route["TUNNEL_ROUTE"][port] = port_tunnel_route["TUNNEL_ROUTE"].get(port, {})
port_tunnel_route["TUNNEL_ROUTE"][port][name] = {}
port_tunnel_route["TUNNEL_ROUTE"][port][name]['DEST'] = dest_address
port_tunnel_route["TUNNEL_ROUTE"][port][name]['kernel'] = if_kernel_tunnel_route_programed
port_tunnel_route["TUNNEL_ROUTE"][port][name]['asic'] = if_asic_tunnel_route_programed
def create_json_dump_per_port_tunnel_route(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_id, port):
get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_id, port)
def create_table_dump_per_port_tunnel_route(db, print_data, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_id, port):
port_tunnel_route = {}
port_tunnel_route["TUNNEL_ROUTE"] = {}
get_tunnel_route_per_port(db, port_tunnel_route, per_npu_configdb, per_npu_appl_db, per_npu_asic_db, asic_id, port)
for port, route in port_tunnel_route["TUNNEL_ROUTE"].items():
for dest_name, values in route.items():
print_line = []
print_line.append(port)
print_line.append(dest_name)
print_line.append(values['DEST'])
print_line.append('added' if values['kernel'] else '-')
print_line.append('added' if values['asic'] else '-')
print_data.append(print_line)
@muxcable.command()
@click.argument('port', required=False, default=None)
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
@clicommon.pass_db
def status(db, port, json_output):
"""Show muxcable status information"""
port = platform_sfputil_helper.get_interface_name(port, db)
port_table_keys = {}
appl_db_muxcable_tbl_keys = {}
port_health_table_keys = {}
port_metrics_table_keys = {}
per_npu_statedb = {}
per_npu_appl_db = {}
muxcable_info_dict = {}
muxcable_grpc_dict = {}
muxcable_health_dict = {}
muxcable_metrics_dict = {}
# Getting all front asic namespace and correspding config and state DB connector
namespaces = multi_asic.get_front_end_namespaces()
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
per_npu_statedb[asic_id] = SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB)
per_npu_appl_db[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
per_npu_appl_db[asic_id].connect(per_npu_appl_db[asic_id].APPL_DB)
appl_db_muxcable_tbl_keys[asic_id] = per_npu_appl_db[asic_id].keys(
per_npu_appl_db[asic_id].APPL_DB, 'MUX_CABLE_TABLE:*')
port_table_keys[asic_id] = per_npu_statedb[asic_id].keys(
per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|*')
port_health_table_keys[asic_id] = per_npu_statedb[asic_id].keys(
per_npu_statedb[asic_id].STATE_DB, 'MUX_LINKMGR_TABLE|*')
port_metrics_table_keys[asic_id] = per_npu_statedb[asic_id].keys(
per_npu_statedb[asic_id].STATE_DB, 'MUX_METRICS_TABLE|*')
if port is not None:
asic_index = None
if platform_sfputil is not None:
asic_index = platform_sfputil.get_asic_id_for_logical_port(port)
if asic_index is None:
# TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
# is fully mocked
import sonic_platform_base.sonic_sfp.sfputilhelper
asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port)
if asic_index is None:
port_name = platform_sfputil_helper.get_interface_alias(port, db)
click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port_name))
sys.exit(STATUS_FAIL)
muxcable_info_dict[asic_index] = per_npu_appl_db[asic_index].get_all(
per_npu_appl_db[asic_index].APPL_DB, 'MUX_CABLE_TABLE:{}'.format(port))
muxcable_grpc_dict[asic_index] = per_npu_statedb[asic_index].get_all(
per_npu_statedb[asic_index].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))
muxcable_health_dict[asic_index] = per_npu_statedb[asic_index].get_all(
per_npu_statedb[asic_index].STATE_DB, 'MUX_LINKMGR_TABLE|{}'.format(port))
muxcable_metrics_dict[asic_index] = per_npu_statedb[asic_index].get_all(
per_npu_statedb[asic_index].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))
if muxcable_info_dict[asic_index] is not None:
logical_key = "MUX_CABLE_TABLE:{}".format(port)
logical_health_key = "MUX_LINKMGR_TABLE|{}".format(port)
logical_metrics_key = "MUX_METRICS_TABLE|{}".format(port)
if logical_key in appl_db_muxcable_tbl_keys[asic_index] and logical_health_key in port_health_table_keys[asic_index]:
if logical_metrics_key not in port_metrics_table_keys[asic_index]:
muxcable_metrics_dict[asic_index] = {}
if json_output:
port_status_dict = {}
port_status_dict["MUX_CABLE"] = {}
create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict, muxcable_grpc_dict,
muxcable_health_dict, muxcable_metrics_dict, asic_index, port)
click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
sys.exit(STATUS_SUCCESSFUL)
else:
print_data = []
create_table_dump_per_port_status(db, print_data, muxcable_info_dict, muxcable_grpc_dict,
muxcable_health_dict, muxcable_metrics_dict, asic_index, port)
headers = ['PORT', 'STATUS', 'SERVER_STATUS', 'HEALTH', 'HWSTATUS', 'LAST_SWITCHOVER_TIME']
click.echo(tabulate(print_data, headers=headers))
sys.exit(STATUS_SUCCESSFUL)
else:
port_name = platform_sfputil_helper.get_interface_alias(port, db)
click.echo("this is not a valid port present on mux_cable".format(port_name))
sys.exit(STATUS_FAIL)
else:
click.echo("there is not a valid asic table for this asic_index".format(asic_index))
sys.exit(STATUS_FAIL)
else:
if json_output:
port_status_dict = {}
port_status_dict["MUX_CABLE"] = {}
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
for key in natsorted(appl_db_muxcable_tbl_keys[asic_id]):
port = key.split(":")[1]
muxcable_info_dict[asic_id] = per_npu_appl_db[asic_id].get_all(
per_npu_appl_db[asic_id].APPL_DB, 'MUX_CABLE_TABLE:{}'.format(port))
muxcable_grpc_dict[asic_id] = per_npu_statedb[asic_id].get_all(
per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))
muxcable_health_dict[asic_id] = per_npu_statedb[asic_id].get_all(
per_npu_statedb[asic_id].STATE_DB, 'MUX_LINKMGR_TABLE|{}'.format(port))
muxcable_metrics_dict[asic_id] = per_npu_statedb[asic_id].get_all(
per_npu_statedb[asic_id].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))
if not muxcable_metrics_dict[asic_id]:
muxcable_metrics_dict[asic_id] = {}
create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict, muxcable_grpc_dict,
muxcable_health_dict, muxcable_metrics_dict, asic_id, port)
click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
else:
print_data = []
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
for key in natsorted(appl_db_muxcable_tbl_keys[asic_id]):
port = key.split(":")[1]
muxcable_info_dict[asic_id] = per_npu_appl_db[asic_id].get_all(
per_npu_appl_db[asic_id].APPL_DB, 'MUX_CABLE_TABLE:{}'.format(port))
muxcable_health_dict[asic_id] = per_npu_statedb[asic_id].get_all(
per_npu_statedb[asic_id].STATE_DB, 'MUX_LINKMGR_TABLE|{}'.format(port))
muxcable_grpc_dict[asic_id] = per_npu_statedb[asic_id].get_all(
per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))
muxcable_metrics_dict[asic_id] = per_npu_statedb[asic_id].get_all(
per_npu_statedb[asic_id].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))
if not muxcable_metrics_dict[asic_id]:
muxcable_metrics_dict[asic_id] = {}
create_table_dump_per_port_status(db, print_data, muxcable_info_dict, muxcable_grpc_dict,
muxcable_health_dict, muxcable_metrics_dict, asic_id, port)
headers = ['PORT', 'STATUS', 'SERVER_STATUS', 'HEALTH', 'HWSTATUS', 'LAST_SWITCHOVER_TIME']
click.echo(tabulate(print_data, headers=headers))
sys.exit(STATUS_SUCCESSFUL)
@muxcable.command()
@click.argument('port', required=False, default=None)
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
@clicommon.pass_db
def config(db, port, json_output):
"""Show muxcable config information"""
port = platform_sfputil_helper.get_interface_name(port, db)
port_mux_tbl_keys = {}
asic_start_idx = None
per_npu_configdb = {}
mux_tbl_cfg_db = {}
peer_switch_tbl_cfg_db = {}
# Getting all front asic namespace and correspding config and state DB connector
namespaces = multi_asic.get_front_end_namespaces()
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
if asic_start_idx is None:
asic_start_idx = asic_id
# TO-DO replace the macros with correct swsscommon names
#config_db[asic_id] = swsscommon.DBConnector("CONFIG_DB", REDIS_TIMEOUT_MSECS, True, namespace)
#mux_tbl_cfg_db[asic_id] = swsscommon.Table(config_db[asic_id], swsscommon.CFG_MUX_CABLE_TABLE_NAME)
per_npu_configdb[asic_id] = ConfigDBConnector(use_unix_socket_path=False, namespace=namespace)
per_npu_configdb[asic_id].connect()
mux_tbl_cfg_db[asic_id] = per_npu_configdb[asic_id].get_table("MUX_CABLE")
peer_switch_tbl_cfg_db[asic_id] = per_npu_configdb[asic_id].get_table("PEER_SWITCH")
#peer_switch_tbl_cfg_db[asic_id] = swsscommon.Table(config_db[asic_id], swsscommon.CFG_PEER_SWITCH_TABLE_NAME)
port_mux_tbl_keys[asic_id] = mux_tbl_cfg_db[asic_id].keys()
if port is not None:
asic_index = None
if platform_sfputil is not None:
asic_index = platform_sfputil.get_asic_id_for_logical_port(port)
if asic_index is None:
# TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
# is fully mocked
import sonic_platform_base.sonic_sfp.sfputilhelper
asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port)
if asic_index is None:
port_name = platform_sfputil_helper.get_interface_alias(port, db)
click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port_name))
sys.exit(CONFIG_FAIL)
port_status_dict = {}
port_status_dict["MUX_CABLE"] = {}
port_status_dict["MUX_CABLE"]["PEER_TOR"] = {}
peer_switch_value = None
switch_name = get_switch_name(per_npu_configdb[asic_start_idx])
if asic_start_idx is not None:
peer_switch_value = get_value_for_key_in_config_tbl(
per_npu_configdb[asic_start_idx], switch_name, "address_ipv4", "PEER_SWITCH")
port_status_dict["MUX_CABLE"]["PEER_TOR"] = peer_switch_value
if port_mux_tbl_keys[asic_id] is not None:
if port in port_mux_tbl_keys[asic_id]:
if json_output:
port_status_dict["MUX_CABLE"] = {}
port_status_dict["MUX_CABLE"]["PORTS"] = {}
create_json_dump_per_port_config(db, port_status_dict, per_npu_configdb, asic_id, port)
click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
sys.exit(CONFIG_SUCCESSFUL)
else:
print_data = []
print_peer_tor = []
is_dualtor_active_active = [False]
create_table_dump_per_port_config(db, print_data, per_npu_configdb, asic_id, port, is_dualtor_active_active)
headers = ['SWITCH_NAME', 'PEER_TOR']
peer_tor_data = []
peer_tor_data.append(switch_name)
peer_tor_data.append(peer_switch_value)
print_peer_tor.append(peer_tor_data)
click.echo(tabulate(print_peer_tor, headers=headers))
if is_dualtor_active_active[0]:
headers = ['port', 'state', 'ipv4', 'ipv6', 'cable_type', 'soc_ipv4', 'soc_ipv6']
else:
headers = ['port', 'state', 'ipv4', 'ipv6']
click.echo(tabulate(print_data, headers=headers))
sys.exit(CONFIG_SUCCESSFUL)
else:
port_name = platform_sfputil_helper.get_interface_alias(port, db)
click.echo("this is not a valid port present on mux_cable".format(port_name))
sys.exit(CONFIG_FAIL)
else:
click.echo("there is not a valid asic table for this asic_index".format(asic_index))
sys.exit(CONFIG_FAIL)
else:
port_status_dict = {}
port_status_dict["MUX_CABLE"] = {}
port_status_dict["MUX_CABLE"]["PEER_TOR"] = {}
peer_switch_value = None
switch_name = get_switch_name(per_npu_configdb[asic_start_idx])
if asic_start_idx is not None:
peer_switch_value = get_value_for_key_in_config_tbl(
per_npu_configdb[asic_start_idx], switch_name, "address_ipv4", "PEER_SWITCH")
port_status_dict["MUX_CABLE"]["PEER_TOR"] = peer_switch_value
if json_output:
port_status_dict["MUX_CABLE"]["PORTS"] = {}
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
for port in natsorted(port_mux_tbl_keys[asic_id]):
create_json_dump_per_port_config(db, port_status_dict, per_npu_configdb, asic_id, port)
click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
else:
print_data = []
print_peer_tor = []
is_dualtor_active_active = [False]
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
for port in natsorted(port_mux_tbl_keys[asic_id]):
create_table_dump_per_port_config(db, print_data, per_npu_configdb, asic_id, port, is_dualtor_active_active)
headers = ['SWITCH_NAME', 'PEER_TOR']
peer_tor_data = []
peer_tor_data.append(switch_name)
peer_tor_data.append(peer_switch_value)
print_peer_tor.append(peer_tor_data)
click.echo(tabulate(print_peer_tor, headers=headers))
if is_dualtor_active_active[0]:
headers = ['port', 'state', 'ipv4', 'ipv6', 'cable_type', 'soc_ipv4', 'soc_ipv6']
else:
headers = ['port', 'state', 'ipv4', 'ipv6']
click.echo(tabulate(print_data, headers=headers))
sys.exit(CONFIG_SUCCESSFUL)
@muxcable.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.argument('target', metavar='<target> NIC TORA TORB LOCAL', required=True, default=None, type=click.Choice(["NIC", "TORA", "TORB", "LOCAL"]))
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
@clicommon.pass_db
def berinfo(db, port, target, json_output):
"""Show muxcable BER (bit error rate) information"""
port = platform_sfputil_helper.get_interface_name(port, db)
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_BER_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_BER_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES")
if port is not None:
res_dict = {}
result = {}
param_dict = {}
target = parse_target(target)
param_dict["target"] = target
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"
res_dict = update_and_get_response_for_xcvr_cmd(
"get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", None, port, 10, param_dict, "ber")
if res_dict[1] == "True":
result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_BER_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_BER_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES")
port = platform_sfputil_helper.get_interface_alias(port, db)
if json_output:
click.echo("{}".format(json.dumps(result, indent=4)))
else:
headers = ['PORT', 'ATTR', 'VALUE']
res = [[port]+[key] + [val] for key, val in result.items()]
click.echo(tabulate(res, headers=headers))
else:
click.echo("Did not get a valid Port for ber value".format(port))
sys.exit(CONFIG_FAIL)
@muxcable.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.argument('target', metavar='<target> NIC TORA TORB LOCAL', required=True, default=None, type=click.Choice(["NIC", "TORA", "TORB", "LOCAL"]))
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
@clicommon.pass_db
def eyeinfo(db, port, target, json_output):
"""Show muxcable eye information in mv"""
port = platform_sfputil_helper.get_interface_alias(port, db)
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_BER_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_BER_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES")