-
Notifications
You must be signed in to change notification settings - Fork 665
/
muxcable.py
1271 lines (953 loc) · 51.6 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 os
import sys
import time
import click
import re
import utilities_common.cli as clicommon
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
# The empty namespace refers to linux host namespace.
EMPTY_NAMESPACE = ''
CONFIG_SUCCESSFUL = 0
CONFIG_FAIL = 1
VENDOR_NAME = "Credo"
VENDOR_MODEL_REGEX = re.compile(r"CAC\w{3}321P2P\w{2}MS")
# Helper functions
def db_connect(db_name, namespace=EMPTY_NAMESPACE):
return swsscommon.DBConnector(db_name, REDIS_TIMEOUT_MSECS, True, namespace)
target_dict = { "NIC":"0",
"TORA":"1",
"TORB":"2",
"LOCAL":"3"}
def parse_target(target):
return target_dict.get(target, None)
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(CONFIG_FAIL)
return value
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)
def update_and_get_response_for_xcvr_cmd(cmd_name, rsp_name, exp_rsp, cmd_table_name, cmd_arg_table_name, rsp_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()
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)
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_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)
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]
if result == exp_rsp:
res_dict[1] = result
res_dict[0] = 0
else:
res_dict[1] = result
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
else:
res_dict[1] = 'unknown'
res_dict[0] = CONFIG_FAIL
firmware_rsp_tbl[asic_index]._del(port)
break
delete_all_keys_in_db_table("STATE_DB", rsp_table_name)
return res_dict
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(CONFIG_FAIL)
value = get_value_for_key_in_dict(info_dict, port, key, table)
return value
#
# 'muxcable' command ("config muxcable")
#
@click.group(name='muxcable', cls=clicommon.AliasedGroup)
def muxcable():
"""Show muxcable information"""
if os.geteuid() != 0:
click.echo("Root privileges are required for this operation")
sys.exit(CONFIG_FAIL)
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 lookup_statedb_and_update_configdb(db, per_npu_statedb, config_db, port, state_cfg_val, port_status_dict):
muxcable_statedb_dict = per_npu_statedb.get_all(per_npu_statedb.STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))
configdb_state = get_value_for_key_in_config_tbl(config_db, port, "state", "MUX_CABLE")
ipv4_value = get_value_for_key_in_config_tbl(config_db, port, "server_ipv4", "MUX_CABLE")
ipv6_value = get_value_for_key_in_config_tbl(config_db, port, "server_ipv6", "MUX_CABLE")
soc_ipv4_value = get_optional_value_for_key_in_config_tbl(config_db, port, "soc_ipv4", "MUX_CABLE")
cable_type = get_optional_value_for_key_in_config_tbl(config_db, port, "cable_type", "MUX_CABLE")
ctx = click.get_current_context()
state = get_value_for_key_in_dict(muxcable_statedb_dict, port, "state", "MUX_CABLE_TABLE")
port_name = platform_sfputil_helper.get_interface_alias(port, db)
if str(state_cfg_val) == str(configdb_state):
port_status_dict[port_name] = 'OK'
else:
if cable_type is not None or soc_ipv4_value is not None:
try:
config_db.set_entry("MUX_CABLE", port, {"state": state_cfg_val,
"server_ipv4": ipv4_value,
"server_ipv6": ipv6_value,
"soc_ipv4":soc_ipv4_value,
"cable_type": cable_type})
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))
else:
try:
config_db.set_entry("MUX_CABLE", port, {"state": state_cfg_val,
"server_ipv4": ipv4_value,
"server_ipv6": ipv6_value})
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))
if (str(state_cfg_val) == 'active' and str(state) != 'active') or (str(state_cfg_val) == 'standby' and str(state) != 'standby'):
port_status_dict[port_name] = 'INPROGRESS'
else:
port_status_dict[port_name] = 'OK'
def update_configdb_pck_loss_data(config_db, port, val):
configdb_state = get_value_for_key_in_config_tbl(config_db, port, "state", "MUX_CABLE")
ipv4_value = get_value_for_key_in_config_tbl(config_db, port, "server_ipv4", "MUX_CABLE")
ipv6_value = get_value_for_key_in_config_tbl(config_db, port, "server_ipv6", "MUX_CABLE")
try:
config_db.set_entry("MUX_CABLE", port, {"state": configdb_state,
"server_ipv4": ipv4_value, "server_ipv6": ipv6_value,
"pck_loss_data_reset": val})
except ValueError as e:
ctx = click.get_current_context()
ctx.fail("Invalid ConfigDB. Error: {}".format(e))
# 'muxcable' command ("config muxcable mode <port|all> active|auto")
@muxcable.command()
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "auto", "manual", "standby", "detach"]))
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL)
@clicommon.pass_db
def mode(db, state, port, json_output):
"""Config muxcable mode"""
port = platform_sfputil_helper.get_interface_name(port, db)
port_table_keys = {}
y_cable_asic_table_keys = {}
per_npu_configdb = {}
per_npu_statedb = {}
mux_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)
# replace these with correct macros
per_npu_configdb[asic_id] = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
per_npu_configdb[asic_id].connect()
per_npu_statedb[asic_id] = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB)
mux_tbl_cfg_db[asic_id] = per_npu_configdb[asic_id].get_table("MUX_CABLE")
port_table_keys[asic_id] = per_npu_statedb[asic_id].keys(
per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|*')
if port is not None and port != "all":
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:
click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port))
sys.exit(CONFIG_FAIL)
if per_npu_statedb[asic_index] is not None:
y_cable_asic_table_keys = port_table_keys[asic_index]
logical_key = "MUX_CABLE_TABLE|{}".format(port)
if logical_key in y_cable_asic_table_keys:
port_status_dict = {}
lookup_statedb_and_update_configdb(
db, per_npu_statedb[asic_index], per_npu_configdb[asic_index], port, state, port_status_dict)
if json_output:
click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
else:
headers = ['port', 'state']
data = sorted([(k, v) for k, v in port_status_dict.items()])
click.echo(tabulate(data, headers=headers))
sys.exit(CONFIG_SUCCESSFUL)
else:
click.echo("this is not a valid port present on mux_cable".format(port))
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)
elif port == "all" and port is not None:
port_status_dict = {}
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
for key in port_table_keys[asic_id]:
logical_port = key.split("|")[1]
lookup_statedb_and_update_configdb(
db, per_npu_statedb[asic_id], per_npu_configdb[asic_id], logical_port, state, port_status_dict)
if json_output:
click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
else:
data = sorted([(k, v) for k, v in port_status_dict.items()])
headers = ['port', 'state']
click.echo(tabulate(data, headers=headers))
sys.exit(CONFIG_SUCCESSFUL)
# 'muxcable' command ("config muxcable kill-radv <enable|disable> ")
@muxcable.command(short_help="Kill radv service when it is meant to be stopped, so no good-bye packet is sent for ceasing To Be an Advertising Interface")
@click.argument('knob', metavar='<feature_knob>', required=True, type=click.Choice(["enable", "disable"]))
@clicommon.pass_db
def kill_radv(db, knob):
"""config muxcable kill radv"""
namespaces = multi_asic.get_front_end_namespaces()
for namespace in namespaces:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
mux_lmgrd_cfg_tbl = config_db.get_table("MUX_LINKMGR")
config_db.mod_entry("MUX_LINKMGR", "SERVICE_MGMT", {"kill_radv": "True" if knob == "enable" else "False"})
#'muxcable' command ("config muxcable packetloss reset <port|all>")
@muxcable.command()
@click.argument('action', metavar='<action_name>', required=True, type=click.Choice(["reset"]))
@click.argument('port', metavar='<port_name>', required=True, default=None)
@clicommon.pass_db
def packetloss(db, action, port):
"""config muxcable packetloss reset"""
port = platform_sfputil_helper.get_interface_name(port, db)
port_table_keys = {}
mux_cable_table_keys = {}
pck_loss_table_keys = {}
per_npu_configdb = {}
per_npu_statedb = {}
# 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)
# replace these with correct macros
per_npu_configdb[asic_id] = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
per_npu_configdb[asic_id].connect()
per_npu_statedb[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB)
port_table_keys[asic_id] = per_npu_statedb[asic_id].keys(
per_npu_statedb[asic_id].STATE_DB, 'LINK_PROBE_STATS|*')
mux_cable_table_keys[asic_id] = per_npu_configdb[asic_id].get_table("MUX_CABLE").keys() # keys here are port names
if port is not None and port != "all":
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:
click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port))
sys.exit(CONFIG_FAIL)
if per_npu_statedb[asic_index] is not None:
pck_loss_table_keys = port_table_keys[asic_index]
logical_key = "LINK_PROBE_STATS|{}".format(port)
if logical_key in pck_loss_table_keys:
update_configdb_pck_loss_data(per_npu_configdb[asic_index], port, "reset")
sys.exit(CONFIG_SUCCESSFUL)
else:
click.echo("this is not a valid port present on pck_loss_stats".format(port))
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)
elif port == "all" and port is not None:
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
for key in port_table_keys[asic_id]:
logical_port = key.split("|")[1]
if logical_port in mux_cable_table_keys[asic_id]:
update_configdb_pck_loss_data(per_npu_configdb[asic_id], logical_port, "reset")
sys.exit(CONFIG_SUCCESSFUL)
@muxcable.group(cls=clicommon.AbbreviationGroup)
def prbs():
"""Enable/disable PRBS mode on a port"""
pass
@prbs.command()
@click.argument('port', 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.argument('mode_value', required=True, default=None, type=click.INT)
@click.argument('lane_mask', required=True, default=None, type=click.INT)
@click.argument('prbs_direction', metavar='<PRBS_DIRECTION> PRBS_DIRECTION_BOTH = 0 PRBS_DIRECTION_GENERATOR = 1 PRBS_DIRECTION_CHECKER = 2', required=False, default="0", type=click.Choice(["0", "1", "2"]))
@clicommon.pass_db
def enable(db, port, target, mode_value, lane_mask, prbs_direction):
"""Enable PRBS mode on a port args port target mode_value lane_mask prbs_direction
example sudo config mux prbs enable Ethernet48 0 3 3 0
"""
port = platform_sfputil_helper.get_interface_name(port, db)
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP")
if port is not None:
click.confirm(('Muxcable at port {} will be changed to PRBS mode {} state; disable traffic Continue?'.format(
port, mode_value)), abort=True)
res_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"
param_dict = {}
target = parse_target(target)
param_dict["target"] = target
param_dict["mode_value"] = mode_value
param_dict["lane_mask"] = lane_mask
param_dict["direction"] = prbs_direction
res_dict = update_and_get_response_for_xcvr_cmd(
"config_prbs", "status", "True", "XCVRD_CONFIG_PRBS_CMD", "XCVRD_CONFIG_PRBS_CMD_ARG", "XCVRD_CONFIG_PRBS_RSP", port, 30, param_dict, "enable")
rc = res_dict[0]
port = platform_sfputil_helper.get_interface_alias(port, db)
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP")
if rc == 0:
click.echo("Success in PRBS mode port {} to {}".format(port, mode_value))
else:
click.echo("ERR: Unable to set PRBS mode port {} to {}".format(port, mode_value))
sys.exit(CONFIG_FAIL)
@prbs.command()
@click.argument('port', 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.argument('prbs_direction', metavar='<PRBS_DIRECTION> PRBS_DIRECTION_BOTH = 0 PRBS_DIRECTION_GENERATOR = 1 PRBS_DIRECTION_CHECKER = 2', required=False, default="0", type=click.Choice(["0", "1", "2"]))
@clicommon.pass_db
def disable(db, port, target, prbs_direction):
"""Disable PRBS mode on a port
example sudo config mux prbs disable Ethernet48 0
"""
port = platform_sfputil_helper.get_interface_name(port, db)
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP")
if port is not None:
click.confirm(('Muxcable at port {} will be changed to disable PRBS mode {} target; disable traffic Continue?'.format(
port, target)), abort=True)
res_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"
param_dict = {}
target = parse_target(target)
param_dict["target"] = target
param_dict["direction"] = prbs_direction
res_dict = update_and_get_response_for_xcvr_cmd(
"config_prbs", "status", "True", "XCVRD_CONFIG_PRBS_CMD", "XCVRD_CONFIG_PRBS_CMD_ARG", "XCVRD_CONFIG_PRBS_RSP", port, 30, param_dict, "disable")
rc = res_dict[0]
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP")
port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in disable PRBS mode port {} on target {}".format(port, target))
else:
click.echo("ERR: Unable to disable PRBS mode port {} on target {}".format(port, target))
sys.exit(CONFIG_FAIL)
@muxcable.group(cls=clicommon.AbbreviationGroup)
def loopback():
"""Enable/disable loopback mode on a port"""
pass
@loopback.command()
@click.argument('port', 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.argument('lane_mask', required=True, default=None, type=click.INT)
@click.argument('mode_value', required=False, metavar='<Loop mode> 1 LOOPBACK_MODE_NEAR_END 2 LOOPBACK_MODE_FAR_END', default="1", type=click.Choice(["1", "2"]))
@clicommon.pass_db
def enable(db, port, target, lane_mask, mode_value):
"""Enable loopback mode on a port args port target lane_map mode_value"""
port = platform_sfputil_helper.get_interface_name(port, db)
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_LOOP_RSP")
if port is not None:
click.confirm(('Muxcable at port {} will be changed to LOOP mode {} state; disable traffic Continue?'.format(
port, mode_value)), abort=True)
res_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"
param_dict = {}
target = parse_target(target)
param_dict["target"] = target
param_dict["mode_value"] = mode_value
param_dict["lane_mask"] = lane_mask
res_dict = update_and_get_response_for_xcvr_cmd(
"config_loop", "status", "True", "XCVRD_CONFIG_LOOP_CMD", "XCVRD_CONFIG_LOOP_CMD_ARG", "XCVRD_CONFIG_LOOP_RSP", port, 30, param_dict, "enable")
rc = res_dict[0]
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_LOOP_RSP")
port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in LOOP mode port {} to {}".format(port, mode_value))
else:
click.echo("ERR: Unable to set LOOP mode port {} to {}".format(port, mode_value))
sys.exit(CONFIG_FAIL)
@loopback.command()
@click.argument('port', required=True, default=None)
@click.argument('target', metavar='<target> NIC TORA TORB LOCAL', required=True, default=None, type=click.Choice(["NIC", "TORA", "TORB", "LOCAL"]))
@clicommon.pass_db
def disable(db, port, target):
"""Disable loopback mode on a port"""
port = platform_sfputil_helper.get_interface_name(port, db)
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_LOOP_RSP")
if port is not None:
click.confirm(('Muxcable at port {} will be changed to disable LOOP mode {} state; disable traffic Continue?'.format(
port, target)), abort=True)
res_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"
param_dict = {}
target = parse_target(target)
param_dict["target"] = target
res_dict = update_and_get_response_for_xcvr_cmd(
"config_loop", "status", "True", "XCVRD_CONFIG_LOOP_CMD", "XCVRD_CONFIG_LOOP_CMD_ARG", "XCVRD_CONFIG_LOOP_RSP", port, 30, param_dict, "disable")
rc = res_dict[0]
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_LOOP_RSP")
port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in disable LOOP mode port {} to {}".format(port, target))
else:
click.echo("ERR: Unable to set disable LOOP mode port {} to {}".format(port, target))
sys.exit(CONFIG_FAIL)
@muxcable.group(cls=clicommon.AbbreviationGroup)
def hwmode():
"""Configure muxcable hardware directly"""
pass
@hwmode.command()
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "standby"]))
@click.argument('port', metavar='<port_name>', required=True, default=None)
@clicommon.pass_db
def state(db, state, port):
"""Configure the muxcable mux state {active/standby}"""
port = platform_sfputil_helper.get_interface_name(port, db)
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_DIR_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_DIR_RSP")
if port is not None and port != "all":
click.confirm(('Muxcable at port {} will be changed to {} state. Continue?'.format(port, state)), abort=True)
res_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"
res_dict = update_and_get_response_for_xcvr_cmd(
"config", "result", "True", "XCVRD_CONFIG_HWMODE_DIR_CMD", None, "XCVRD_CONFIG_HWMODE_DIR_RSP", port, 1, None, state)
rc = res_dict[0]
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_DIR_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_DIR_RSP")
port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in toggling port {} to {}".format(port, state))
else:
click.echo("ERR: Unable to toggle port {} to {}".format(port, state))
sys.exit(CONFIG_FAIL)
elif port == "all":
click.confirm(('Muxcable at all ports will be changed to {} state. Continue?'.format(state)), abort=True)
logical_port_list = platform_sfputil_helper.get_logical_list()
rc_exit = 0
for port in logical_port_list:
if platform_sfputil is not None:
physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(port)
if not isinstance(physical_port_list, list):
continue
if len(physical_port_list) != 1:
continue
physical_port = physical_port_list[0]
logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical()
logical_port_list_per_port = logical_port_list_for_physical_port.get(physical_port, None)
""" This check is required for checking whether or not this logical port is the one which is
actually mapped to physical port and by convention it is always the first port.
TODO: this should be removed with more logic to check which logical port maps to actual physical port
being used"""
if port != logical_port_list_per_port[0]:
continue
res_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = 'unknown'
res_dict = update_and_get_response_for_xcvr_cmd(
"config", "result", "True", "XCVRD_CONFIG_HWMODE_DIR_CMD", None, "XCVRD_CONFIG_HWMODE_DIR_RSP", port, 1, None, state)
rc = res_dict[0]
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_DIR_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_DIR_RSP")
port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in toggling port {} to {}".format(port, state))
else:
click.echo("ERR: Unable to toggle port {} to {}".format(port, state))
rc_exit = CONFIG_FAIL
sys.exit(rc_exit)
@hwmode.command()
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["auto", "manual"]))
@click.argument('port', metavar='<port_name>', required=True, default=None)
@clicommon.pass_db
def setswitchmode(db, state, port):
"""Configure the muxcable mux switching mode {auto/manual}"""
port = platform_sfputil_helper.get_interface_name(port, db)
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_SWMODE_RSP")
if port is not None and port != "all":
click.confirm(('Muxcable at port {} will be changed to {} switching mode. Continue?'.format(port, state)), abort=True)
res_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"
res_dict = update_and_get_response_for_xcvr_cmd(
"config", "result", "True", "XCVRD_CONFIG_HWMODE_SWMODE_CMD", None, "XCVRD_CONFIG_HWMODE_SWMODE_RSP", port, 1, None, state)
rc = res_dict[0]
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_SWMODE_RSP")
port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in switch muxcable mode port {} to {}".format(port, state))
else:
click.echo("ERR: Unable to switch muxcable mode port {} to {}".format(port, state))
sys.exit(CONFIG_FAIL)
elif port == "all":
click.confirm(('Muxcable at all ports will be changed to {} switching mode. Continue?'.format(state)), abort=True)
logical_port_list = platform_sfputil_helper.get_logical_list()
rc_exit = 0
for port in logical_port_list:
if platform_sfputil is not None:
physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(port)
if not isinstance(physical_port_list, list):
continue
if len(physical_port_list) != 1:
continue
physical_port = physical_port_list[0]
logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical()
logical_port_list_per_port = logical_port_list_for_physical_port.get(physical_port, None)
""" This check is required for checking whether or not this logical port is the one which is
actually mapped to physical port and by convention it is always the first port.
TODO: this should be removed with more logic to check which logical port maps to actual physical port
being used"""
if port != logical_port_list_per_port[0]:
continue
res_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"
res_dict = update_and_get_response_for_xcvr_cmd(
"config", "result", "True", "XCVRD_CONFIG_HWMODE_SWMODE_CMD", None, "XCVRD_CONFIG_HWMODE_SWMODE_RSP", port, 1, None, state)
rc = res_dict[0]
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_SWMODE_RSP")
port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in toggling port {} to {}".format(port, state))
else:
click.echo("ERR: Unable to toggle port {} to {}".format(port, state))
rc_exit = CONFIG_FAIL
sys.exit(rc_exit)
@muxcable.group(cls=clicommon.AbbreviationGroup)
def firmware():
"""Configure muxcable firmware command"""
pass
@firmware.command()
@click.argument('fwfile', metavar='<firmware_file>', required=True)
@click.argument('port', metavar='<port_name>', required=True, default=None)
@clicommon.pass_db
def download(db, fwfile, port):
"""Config muxcable firmware download"""
port = platform_sfputil_helper.get_interface_name(port, db)
delete_all_keys_in_db_table("STATE_DB", "XCVRD_DOWN_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_DOWN_FW_CMD")
if port is not None and port != "all":
res_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"
res_dict = update_and_get_response_for_xcvr_cmd(
"download_firmware", "status", "0", "XCVRD_DOWN_FW_CMD", None, "XCVRD_DOWN_FW_RSP", port, 1000, None, fwfile)
rc = res_dict[0]
delete_all_keys_in_db_table("STATE_DB", "XCVRD_DOWN_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_DOWN_FW_CMD")
port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in downloading firmware port {} {}".format(port, fwfile))
else:
click.echo("ERR: Unable to download firmware port {} {}".format(port, fwfile))
sys.exit(CONFIG_FAIL)
elif port == "all":
click.confirm(('Muxcable at all ports will be changed to {} switching mode. Continue?'.format(state)), abort=True)
logical_port_list = platform_sfputil_helper.get_logical_list()
rc_exit = True
for port in logical_port_list:
if platform_sfputil is not None:
physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(port)
if not isinstance(physical_port_list, list):
continue
if len(physical_port_list) != 1:
continue
physical_port = physical_port_list[0]
logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical()
logical_port_list_per_port = logical_port_list_for_physical_port.get(physical_port, None)
""" This check is required for checking whether or not this logical port is the one which is
actually mapped to physical port and by convention it is always the first port.
TODO: this should be removed with more logic to check which logical port maps to actual physical port
being used"""
if port != logical_port_list_per_port[0]:
continue
res_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"
res_dict = update_and_get_response_for_xcvr_cmd(
"download_firmware", "status", "0", "XCVRD_DOWN_FW_CMD", "XCVRD_DOWN_FW_RSP", port, 1000, fwfile)
rc = res_dict[0]
delete_all_keys_in_db_table("STATE_DB", "XCVRD_DOWN_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_DOWN_FW_CMD")
port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in downloading firmware port {} {}".format(port, fwfile))
else:
click.echo("ERR: Unable to download firmware port {} {}".format(port, fwfile))
rc_exit = CONFIG_FAIL
sys.exit(rc_exit)
@firmware.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.argument('fwfile', metavar='<firmware_file>', required=False, default=None)
@click.option('--nonhitless', 'nonhitless', required=False, is_flag=True, type=click.BOOL)
@clicommon.pass_db
def activate(db, port, fwfile, nonhitless):
"""Config muxcable firmware activate"""
port = platform_sfputil_helper.get_interface_name(port, db)
delete_all_keys_in_db_table("STATE_DB", "XCVRD_ACTI_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ACTI_FW_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ACTI_FW_CMD_ARG")
if port is not None and port != "all":
res_dict = {}
param_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"
if nonhitless:
param_dict["hitless"] = "1"
res_dict = update_and_get_response_for_xcvr_cmd(
"activate_firmware", "status", "0", "XCVRD_ACTI_FW_CMD", "XCVRD_ACTI_FW_CMD_ARG", "XCVRD_ACTI_FW_RSP", port, 60, param_dict, fwfile)
rc = res_dict[0]
delete_all_keys_in_db_table("STATE_DB", "XCVRD_ACTI_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ACTI_FW_CMD")
port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in activate firmware port {} fwfile {}".format(port, fwfile))
else:
click.echo("ERR: Unable to activate firmware port {} fwfile {}".format(port, fwfile))
sys.exit(CONFIG_FAIL)
elif port == "all":
logical_port_list = platform_sfputil_helper.get_logical_list()
rc_exit = True
for port in logical_port_list:
if platform_sfputil is not None:
physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(port)
if not isinstance(physical_port_list, list):
continue
if len(physical_port_list) != 1:
continue
physical_port = physical_port_list[0]
logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical()
logical_port_list_per_port = logical_port_list_for_physical_port.get(physical_port, None)
""" This check is required for checking whether or not this logical port is the one which is
actually mapped to physical port and by convention it is always the first port.
TODO: this should be removed with more logic to check which logical port maps to actual physical port
being used"""
if port != logical_port_list_per_port[0]:
continue
res_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"