forked from sonic-net/sonic-platform-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmis.py
More file actions
1725 lines (1573 loc) · 87.2 KB
/
Copy pathcmis.py
File metadata and controls
1725 lines (1573 loc) · 87.2 KB
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
"""
cmis.py
Implementation of XcvrApi that corresponds to the CMIS specification.
"""
from ...fields import consts
from ..xcvr_api import XcvrApi
import logging
from ...fields import consts
from ..xcvr_api import XcvrApi
from .cmisCDB import CmisCdbApi
from .cmisVDM import CmisVdmApi
import time
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
class CmisApi(XcvrApi):
NUM_CHANNELS = 8
def __init__(self, xcvr_eeprom):
super(CmisApi, self).__init__(xcvr_eeprom)
self.vdm = CmisVdmApi(xcvr_eeprom)
self.cdb = CmisCdbApi(xcvr_eeprom)
def get_model(self):
'''
This function returns the part number of the module
'''
return self.xcvr_eeprom.read(consts.VENDOR_PART_NO_FIELD)
def get_vendor_rev(self):
'''
This function returns the revision level for part number provided by vendor
'''
return self.xcvr_eeprom.read(consts.VENDOR_REV_FIELD)
def get_serial(self):
'''
This function returns the serial number of the module
'''
return self.xcvr_eeprom.read(consts.VENDOR_SERIAL_NO_FIELD)
def get_module_type(self):
'''
This function returns the SFF8024Identifier (module type / form-factor). Table 4-1 in SFF-8024 Rev4.6
'''
return self.xcvr_eeprom.read(consts.ID_FIELD)
def get_connector_type(self):
'''
This function returns module connector. Table 4-3 in SFF-8024 Rev4.6
'''
return self.xcvr_eeprom.read(consts.CONNECTOR_FIELD)
def get_module_hardware_revision(self):
'''
This function returns the module hardware revision
'''
if self.is_flat_memory():
return '0.0'
hw_major_rev = self.xcvr_eeprom.read(consts.HW_MAJOR_REV)
hw_minor_rev = self.xcvr_eeprom.read(consts.HW_MAJOR_REV)
hw_rev = [str(num) for num in [hw_major_rev, hw_minor_rev]]
return '.'.join(hw_rev)
def get_cmis_rev(self):
'''
This function returns the CMIS version the module complies to
'''
cmis_major = self.xcvr_eeprom.read(consts.CMIS_MAJOR_REVISION)
cmis_minor = self.xcvr_eeprom.read(consts.CMIS_MINOR_REVISION)
cmis_rev = [str(num) for num in [cmis_major, cmis_minor]]
return '.'.join(cmis_rev)
# Transceiver status
def get_module_state(self):
'''
This function returns the module state
'''
return self.xcvr_eeprom.read(consts.MODULE_STATE)
def get_module_fault_cause(self):
'''
This function returns the module fault cause
'''
return self.xcvr_eeprom.read(consts.MODULE_FAULT_CAUSE)
def get_module_active_firmware(self):
'''
This function returns the active firmware version
'''
active_fw_major = self.xcvr_eeprom.read(consts.ACTIVE_FW_MAJOR_REV)
active_fw_minor = self.xcvr_eeprom.read(consts.ACTIVE_FW_MINOR_REV)
active_fw = [str(num) for num in [active_fw_major, active_fw_minor]]
return '.'.join(active_fw)
def get_module_inactive_firmware(self):
'''
This function returns the inactive firmware version
'''
if self.is_flat_memory():
return 'N/A'
inactive_fw_major = self.xcvr_eeprom.read(consts.INACTIVE_FW_MAJOR_REV)
inactive_fw_minor = self.xcvr_eeprom.read(consts.INACTIVE_FW_MINOR_REV)
inactive_fw = [str(num) for num in [inactive_fw_major, inactive_fw_minor]]
return '.'.join(inactive_fw)
def get_transceiver_info(self):
admin_info = self.xcvr_eeprom.read(consts.ADMIN_INFO_FIELD)
if admin_info is None:
return None
ext_id = admin_info[consts.EXT_ID_FIELD]
power_class = ext_id[consts.POWER_CLASS_FIELD]
max_power = ext_id[consts.MAX_POWER_FIELD]
xcvr_info = {
"type": admin_info[consts.ID_FIELD],
"type_abbrv_name": admin_info[consts.ID_ABBRV_FIELD],
"hardware_rev": self.get_module_hardware_revision(),
"serial": admin_info[consts.VENDOR_SERIAL_NO_FIELD],
"manufacturer": admin_info[consts.VENDOR_NAME_FIELD],
"model": admin_info[consts.VENDOR_PART_NO_FIELD],
"connector": admin_info[consts.CONNECTOR_FIELD],
"encoding": "N/A", # Not supported
"ext_identifier": "%s (%sW Max)" % (power_class, max_power),
"ext_rateselect_compliance": "N/A", # Not supported
"cable_type": "Length Cable Assembly(m)",
"cable_length": float(admin_info[consts.LENGTH_ASSEMBLY_FIELD]),
"nominal_bit_rate": 0, # Not supported
"specification_compliance": admin_info[consts.MEDIA_TYPE_FIELD],
"vendor_date": admin_info[consts.VENDOR_DATE_FIELD],
"vendor_oui": admin_info[consts.VENDOR_OUI_FIELD],
# TODO
"application_advertisement": "N/A",
}
xcvr_info['host_electrical_interface'] = self.get_host_electrical_interface()
xcvr_info['media_interface_code'] = self.get_module_media_interface()
xcvr_info['host_lane_count'] = self.get_host_lane_count()
xcvr_info['media_lane_count'] = self.get_media_lane_count()
xcvr_info['host_lane_assignment_option'] = self.get_host_lane_assignment_option()
xcvr_info['media_lane_assignment_option'] = self.get_media_lane_assignment_option()
apsel_dict = self.get_active_apsel_hostlane()
for lane in range(1, self.NUM_CHANNELS+1):
xcvr_info["%s%d" % ("active_apsel_hostlane", lane)] = \
apsel_dict["%s%d" % (consts.ACTIVE_APSEL_HOSTLANE, lane)]
xcvr_info['media_interface_technology'] = self.get_media_interface_technology()
xcvr_info['vendor_rev'] = self.get_vendor_rev()
xcvr_info['cmis_rev'] = self.get_cmis_rev()
xcvr_info['active_firmware'] = self.get_module_active_firmware()
xcvr_info['inactive_firmware'] = self.get_module_inactive_firmware()
xcvr_info['specification_compliance'] = self.get_module_media_type()
return xcvr_info
def get_transceiver_bulk_status(self):
rx_los = self.get_rx_los()
tx_fault = self.get_tx_fault()
tx_disable = self.get_tx_disable()
tx_disabled_channel = self.get_tx_disable_channel()
temp = self.get_module_temperature()
voltage = self.get_voltage()
tx_bias = self.get_tx_bias()
rx_power = self.get_rx_power()
tx_power = self.get_tx_power()
read_failed = rx_los is None or \
tx_fault is None or \
tx_disable is None or \
tx_disabled_channel is None or \
temp is None or \
voltage is None or \
tx_bias is None or \
rx_power is None or \
tx_power is None
if read_failed:
return None
bulk_status = {
"rx_los": all(rx_los.values()) if self.get_rx_los_support() else 'N/A',
"tx_fault": all(tx_fault.values()) if self.get_tx_fault_support() else 'N/A',
"tx_disable": all(tx_disable),
"tx_disabled_channel": tx_disabled_channel,
"temperature": temp,
"voltage": voltage
}
for i in range(1, self.NUM_CHANNELS + 1):
bulk_status["tx%dbias" % i] = tx_bias[i - 1]
bulk_status["rx%dpower" % i] = rx_power[i - 1]
bulk_status["tx%dpower" % i] = tx_power[i - 1]
laser_temp_dict = self.get_laser_temperature()
bulk_status['laser_temperature'] = laser_temp_dict['monitor value']
self.vdm_dict = self.get_vdm()
try:
bulk_status['prefec_ber'] = self.vdm_dict['Pre-FEC BER Average Media Input'][1][0]
bulk_status['postfec_ber'] = self.vdm_dict['Errored Frames Average Media Input'][1][0]
except KeyError:
pass
return bulk_status
def get_transceiver_threshold_info(self):
threshold_info_keys = ['temphighalarm', 'temphighwarning',
'templowalarm', 'templowwarning',
'vcchighalarm', 'vcchighwarning',
'vcclowalarm', 'vcclowwarning',
'rxpowerhighalarm', 'rxpowerhighwarning',
'rxpowerlowalarm', 'rxpowerlowwarning',
'txpowerhighalarm', 'txpowerhighwarning',
'txpowerlowalarm', 'txpowerlowwarning',
'txbiashighalarm', 'txbiashighwarning',
'txbiaslowalarm', 'txbiaslowwarning'
]
threshold_info_dict = dict.fromkeys(threshold_info_keys, 'N/A')
thresh_support = self.get_transceiver_thresholds_support()
if thresh_support is None:
return None
if not thresh_support:
return threshold_info_dict
thresh = self.xcvr_eeprom.read(consts.THRESHOLDS_FIELD)
if thresh is None:
return None
threshold_info_dict = {
"temphighalarm": float("{:.3f}".format(thresh[consts.TEMP_HIGH_ALARM_FIELD])),
"templowalarm": float("{:.3f}".format(thresh[consts.TEMP_LOW_ALARM_FIELD])),
"temphighwarning": float("{:.3f}".format(thresh[consts.TEMP_HIGH_WARNING_FIELD])),
"templowwarning": float("{:.3f}".format(thresh[consts.TEMP_LOW_WARNING_FIELD])),
"vcchighalarm": float("{:.3f}".format(thresh[consts.VOLTAGE_HIGH_ALARM_FIELD])),
"vcclowalarm": float("{:.3f}".format(thresh[consts.VOLTAGE_LOW_ALARM_FIELD])),
"vcchighwarning": float("{:.3f}".format(thresh[consts.VOLTAGE_HIGH_WARNING_FIELD])),
"vcclowwarning": float("{:.3f}".format(thresh[consts.VOLTAGE_LOW_WARNING_FIELD])),
"rxpowerhighalarm": float("{:.3f}".format(self.mw_to_dbm(thresh[consts.RX_POWER_HIGH_ALARM_FIELD]))),
"rxpowerlowalarm": float("{:.3f}".format(self.mw_to_dbm(thresh[consts.RX_POWER_LOW_ALARM_FIELD]))),
"rxpowerhighwarning": float("{:.3f}".format(self.mw_to_dbm(thresh[consts.RX_POWER_HIGH_WARNING_FIELD]))),
"rxpowerlowwarning": float("{:.3f}".format(self.mw_to_dbm(thresh[consts.RX_POWER_LOW_WARNING_FIELD]))),
"txpowerhighalarm": float("{:.3f}".format(self.mw_to_dbm(thresh[consts.TX_POWER_HIGH_ALARM_FIELD]))),
"txpowerlowalarm": float("{:.3f}".format(self.mw_to_dbm(thresh[consts.TX_POWER_LOW_ALARM_FIELD]))),
"txpowerhighwarning": float("{:.3f}".format(self.mw_to_dbm(thresh[consts.TX_POWER_HIGH_WARNING_FIELD]))),
"txpowerlowwarning": float("{:.3f}".format(self.mw_to_dbm(thresh[consts.TX_POWER_LOW_WARNING_FIELD]))),
"txbiashighalarm": float("{:.3f}".format(thresh[consts.TX_BIAS_HIGH_ALARM_FIELD])),
"txbiaslowalarm": float("{:.3f}".format(thresh[consts.TX_BIAS_LOW_ALARM_FIELD])),
"txbiashighwarning": float("{:.3f}".format(thresh[consts.TX_BIAS_HIGH_WARNING_FIELD])),
"txbiaslowwarning": float("{:.3f}".format(thresh[consts.TX_BIAS_LOW_WARNING_FIELD]))
}
laser_temp_dict = self.get_laser_temperature()
threshold_info_dict['lasertemphighalarm'] = laser_temp_dict['high alarm']
threshold_info_dict['lasertemplowalarm'] = laser_temp_dict['low alarm']
threshold_info_dict['lasertemphighwarning'] = laser_temp_dict['high warn']
threshold_info_dict['lasertemplowwarning'] = laser_temp_dict['low warn']
self.vdm_dict = self.get_vdm()
try:
threshold_info_dict['prefecberhighalarm'] = self.vdm_dict['Pre-FEC BER Average Media Input'][1][1]
threshold_info_dict['prefecberlowalarm'] = self.vdm_dict['Pre-FEC BER Average Media Input'][1][2]
threshold_info_dict['prefecberhighwarning'] = self.vdm_dict['Pre-FEC BER Average Media Input'][1][3]
threshold_info_dict['prefecberlowwarning'] = self.vdm_dict['Pre-FEC BER Average Media Input'][1][4]
threshold_info_dict['postfecberhighalarm'] = self.vdm_dict['Errored Frames Average Media Input'][1][1]
threshold_info_dict['postfecberlowalarm'] = self.vdm_dict['Errored Frames Average Media Input'][1][2]
threshold_info_dict['postfecberhighwarning'] = self.vdm_dict['Errored Frames Average Media Input'][1][3]
threshold_info_dict['postfecberlowwarning'] = self.vdm_dict['Errored Frames Average Media Input'][1][4]
except KeyError:
pass
return threshold_info_dict
def get_module_temperature(self):
'''
This function returns the module case temperature and its thresholds. Unit in deg C
'''
if not self.get_temperature_support():
return 'N/A'
temp = self.xcvr_eeprom.read(consts.TEMPERATURE_FIELD)
if temp is None:
return None
return float("{:.3f}".format(temp))
def get_voltage(self):
'''
This function returns the monitored value of the 3.3-V supply voltage and its thresholds.
Unit in V
'''
if not self.get_voltage_support():
return 'N/A'
voltage = self.xcvr_eeprom.read(consts.VOLTAGE_FIELD)
if voltage is None:
return None
return float("{:.3f}".format(voltage))
def is_flat_memory(self):
return self.xcvr_eeprom.read(consts.FLAT_MEM_FIELD)
def get_temperature_support(self):
return not self.is_flat_memory()
def get_voltage_support(self):
return not self.is_flat_memory()
def get_rx_los_support(self):
return not self.is_flat_memory()
def get_tx_cdr_lol_support(self):
return not self.is_flat_memory()
def get_tx_cdr_lol(self):
'''
This function returns TX CDR LOL flag on TX host lane
'''
tx_cdr_lol_support = self.get_tx_cdr_lol_support()
if tx_cdr_lol_support is None:
return None
if not tx_cdr_lol_support:
return ["N/A" for _ in range(self.NUM_CHANNELS)]
tx_cdr_lol = self.xcvr_eeprom.read(consts.TX_CDR_LOL)
if tx_cdr_lol is None:
return None
for key, value in tx_cdr_lol.items():
tx_cdr_lol[key] = bool(value)
return tx_cdr_lol
def get_rx_los(self):
'''
This function returns RX LOS flag on RX media lane
'''
rx_los_support = self.get_rx_los_support()
if rx_los_support is None:
return None
if not rx_los_support:
return ["N/A" for _ in range(self.NUM_CHANNELS)]
rx_los = self.xcvr_eeprom.read(consts.RX_LOS_FIELD)
if rx_los is None:
return None
for key, value in rx_los.items():
rx_los[key] = bool(value)
return rx_los
def get_rx_cdr_lol_support(self):
return not self.is_flat_memory()
def get_rx_cdr_lol(self):
'''
This function returns RX CDR LOL flag on RX media lane
'''
rx_cdr_lol_support = self.get_rx_cdr_lol_support()
if rx_cdr_lol_support is None:
return None
if not rx_cdr_lol_support:
return ["N/A" for _ in range(self.NUM_CHANNELS)]
rx_cdr_lol = self.xcvr_eeprom.read(consts.RX_CDR_LOL)
if rx_cdr_lol is None:
return None
for key, value in rx_cdr_lol.items():
rx_cdr_lol[key] = bool(value)
return rx_cdr_lol
def get_tx_power_flag(self):
'''
This function returns TX power out of range flag on TX media lane
'''
tx_power_high_alarm_dict = self.xcvr_eeprom.read(consts.TX_POWER_HIGH_ALARM_FLAG)
tx_power_low_alarm_dict = self.xcvr_eeprom.read(consts.TX_POWER_LOW_ALARM_FLAG)
tx_power_high_warn_dict = self.xcvr_eeprom.read(consts.TX_POWER_HIGH_WARN_FLAG)
tx_power_low_warn_dict = self.xcvr_eeprom.read(consts.TX_POWER_LOW_WARN_FLAG)
if tx_power_high_alarm_dict is None or tx_power_low_alarm_dict is None or tx_power_high_warn_dict is None or tx_power_low_warn_dict is None:
return None
for key, value in tx_power_high_alarm_dict.items():
tx_power_high_alarm_dict[key] = bool(value)
for key, value in tx_power_low_alarm_dict.items():
tx_power_low_alarm_dict[key] = bool(value)
for key, value in tx_power_high_warn_dict.items():
tx_power_high_warn_dict[key] = bool(value)
for key, value in tx_power_low_warn_dict.items():
tx_power_low_warn_dict[key] = bool(value)
tx_power_flag_dict = {'tx_power_high_alarm': tx_power_high_alarm_dict,
'tx_power_low_alarm': tx_power_low_alarm_dict,
'tx_power_high_warn': tx_power_high_warn_dict,
'tx_power_low_warn': tx_power_low_warn_dict,}
return tx_power_flag_dict
def get_tx_bias_flag(self):
'''
This function returns TX bias out of range flag on TX media lane
'''
tx_bias_high_alarm_dict = self.xcvr_eeprom.read(consts.TX_BIAS_HIGH_ALARM_FLAG)
tx_bias_low_alarm_dict = self.xcvr_eeprom.read(consts.TX_BIAS_LOW_ALARM_FLAG)
tx_bias_high_warn_dict = self.xcvr_eeprom.read(consts.TX_BIAS_HIGH_WARN_FLAG)
tx_bias_low_warn_dict = self.xcvr_eeprom.read(consts.TX_BIAS_LOW_WARN_FLAG)
if tx_bias_high_alarm_dict is None or tx_bias_low_alarm_dict is None or tx_bias_high_warn_dict is None or tx_bias_low_warn_dict is None:
return None
for key, value in tx_bias_high_alarm_dict.items():
tx_bias_high_alarm_dict[key] = bool(value)
for key, value in tx_bias_low_alarm_dict.items():
tx_bias_low_alarm_dict[key] = bool(value)
for key, value in tx_bias_high_warn_dict.items():
tx_bias_high_warn_dict[key] = bool(value)
for key, value in tx_bias_low_warn_dict.items():
tx_bias_low_warn_dict[key] = bool(value)
tx_bias_flag_dict = {'tx_bias_high_alarm': tx_bias_high_alarm_dict,
'tx_bias_low_alarm': tx_bias_low_alarm_dict,
'tx_bias_high_warn': tx_bias_high_warn_dict,
'tx_bias_low_warn': tx_bias_low_warn_dict,}
return tx_bias_flag_dict
def get_rx_power_flag(self):
'''
This function returns RX power out of range flag on RX media lane
'''
rx_power_high_alarm_dict = self.xcvr_eeprom.read(consts.RX_POWER_HIGH_ALARM_FLAG)
rx_power_low_alarm_dict = self.xcvr_eeprom.read(consts.RX_POWER_LOW_ALARM_FLAG)
rx_power_high_warn_dict = self.xcvr_eeprom.read(consts.RX_POWER_HIGH_WARN_FLAG)
rx_power_low_warn_dict = self.xcvr_eeprom.read(consts.RX_POWER_LOW_WARN_FLAG)
if rx_power_high_alarm_dict is None or rx_power_low_alarm_dict is None or rx_power_high_warn_dict is None or rx_power_low_warn_dict is None:
return None
for key, value in rx_power_high_alarm_dict.items():
rx_power_high_alarm_dict[key] = bool(value)
for key, value in rx_power_low_alarm_dict.items():
rx_power_low_alarm_dict[key] = bool(value)
for key, value in rx_power_high_warn_dict.items():
rx_power_high_warn_dict[key] = bool(value)
for key, value in rx_power_low_warn_dict.items():
rx_power_low_warn_dict[key] = bool(value)
rx_power_flag_dict = {'rx_power_high_alarm': rx_power_high_alarm_dict,
'rx_power_low_alarm': rx_power_low_alarm_dict,
'rx_power_high_warn': rx_power_high_warn_dict,
'rx_power_low_warn': rx_power_low_warn_dict,}
return rx_power_flag_dict
def get_tx_output_status(self):
'''
This function returns whether TX output signals are valid on TX media lane
'''
tx_output_status_dict = self.xcvr_eeprom.read(consts.TX_OUTPUT_STATUS)
if tx_output_status_dict is None:
return None
for key, value in tx_output_status_dict.items():
tx_output_status_dict[key] = bool(value)
return tx_output_status_dict
def get_rx_output_status(self):
'''
This function returns whether RX output signals are valid on RX host lane
'''
rx_output_status_dict = self.xcvr_eeprom.read(consts.RX_OUTPUT_STATUS)
if rx_output_status_dict is None:
return None
for key, value in rx_output_status_dict.items():
rx_output_status_dict[key] = bool(value)
return rx_output_status_dict
def get_tx_bias_support(self):
return not self.is_flat_memory()
def get_tx_bias(self):
'''
This function returns TX bias current on each media lane
'''
tx_bias_support = self.get_tx_bias_support()
if tx_bias_support is None:
return None
tx_bias = ["N/A" for _ in range(self.NUM_CHANNELS)]
if tx_bias_support:
tx_bias = self.xcvr_eeprom.read(consts.TX_BIAS_FIELD)
if tx_bias is not None:
tx_bias = [tx_bias['LaserBiasTx%dField' % i] for i in range(1, self.NUM_CHANNELS+1)]
return tx_bias
def get_tx_power(self):
'''
This function returns TX output power in mW on each media lane
'''
tx_power_support = self.get_tx_power_support()
if tx_power_support is None:
return None
tx_power = ["N/A" for _ in range(self.NUM_CHANNELS)]
if tx_power_support:
tx_power = self.xcvr_eeprom.read(consts.TX_POWER_FIELD)
if tx_power is not None:
tx_power = [tx_power['OpticalPowerTx%dField' %i] for i in range(1, self.NUM_CHANNELS+1)]
return tx_power
def get_tx_power_support(self):
return not self.is_flat_memory()
def get_rx_power(self):
'''
This function returns RX input power in mW on each media lane
'''
rx_power_support = self.get_rx_power_support()
if rx_power_support is None:
return None
rx_power = ["N/A" for _ in range(self.NUM_CHANNELS)]
if rx_power_support:
rx_power = self.xcvr_eeprom.read(consts.RX_POWER_FIELD)
if rx_power is not None:
rx_power = [rx_power['OpticalPowerRx%dField' %i] for i in range(1, self.NUM_CHANNELS+1)]
return rx_power
def get_rx_power_support(self):
return not self.is_flat_memory()
def get_tx_fault_support(self):
return not self.is_flat_memory() and self.xcvr_eeprom.read(consts.TX_FAULT_SUPPORT_FIELD)
def get_tx_fault(self):
'''
This function returns TX fault flag on TX media lane
'''
tx_fault_support = self.get_tx_fault_support()
if tx_fault_support is None:
return None
if not tx_fault_support:
return ["N/A" for _ in range(self.NUM_CHANNELS)]
tx_fault = self.xcvr_eeprom.read(consts.TX_FAULT_FIELD)
if tx_fault is None:
return None
for key, value in tx_fault.items():
tx_fault[key] = bool(value)
return tx_fault
def get_tx_los_support(self):
return not self.is_flat_memory()
def get_tx_los(self):
'''
This function returns TX LOS flag on TX host lane
'''
tx_los_support = self.get_tx_los_support()
if tx_los_support is None:
return None
if not tx_los_support:
return ["N/A" for _ in range(self.NUM_CHANNELS)]
tx_los = self.xcvr_eeprom.read(consts.TX_LOS_FIELD)
if tx_los is None:
return None
for key, value in tx_los.items():
tx_los[key] = bool(value)
return tx_los
def get_tx_disable_support(self):
return not self.is_flat_memory() and self.xcvr_eeprom.read(consts.TX_DISABLE_SUPPORT_FIELD)
def get_tx_disable(self):
tx_disable_support = self.get_tx_disable_support()
if tx_disable_support is None:
return None
if not tx_disable_support:
return ["N/A" for _ in range(self.NUM_CHANNELS)]
tx_disable = self.xcvr_eeprom.read(consts.TX_DISABLE_FIELD)
if tx_disable is None:
return None
return [bool(tx_disable & (1 << i)) for i in range(self.NUM_CHANNELS)]
def tx_disable(self, tx_disable):
val = 0xFF if tx_disable else 0x0
return self.xcvr_eeprom.write(consts.TX_DISABLE_FIELD, val)
def get_tx_disable_channel(self):
tx_disable_support = self.get_tx_disable_support()
if tx_disable_support is None:
return None
if not tx_disable_support:
return 'N/A'
return self.xcvr_eeprom.read(consts.TX_DISABLE_FIELD)
def tx_disable_channel(self, channel, disable):
channel_state = self.get_tx_disable_channel()
if channel_state is None or channel_state == 'N/A':
return False
for i in range(self.NUM_CHANNELS):
mask = (1 << i)
if not (channel & mask):
continue
if disable:
channel_state |= mask
else:
channel_state &= ~mask
return self.xcvr_eeprom.write(consts.TX_DISABLE_FIELD, channel_state)
def get_power_override(self):
return None
def set_power_override(self, power_override, power_set):
return True
def get_transceiver_thresholds_support(self):
return not self.is_flat_memory()
def get_lpmode_support(self):
power_class = self.xcvr_eeprom.read(consts.POWER_CLASS_FIELD)
if power_class is None:
return False
return "Power Class 1" not in power_class
def get_power_override_support(self):
return False
def get_module_media_type(self):
'''
This function returns module media type: MMF, SMF, Passive Copper Cable, Active Cable Assembly or Base-T.
'''
return self.xcvr_eeprom.read(consts.MEDIA_TYPE_FIELD)
def get_host_electrical_interface(self):
'''
This function returns module host electrical interface. Table 4-5 in SFF-8024 Rev4.6
'''
return self.xcvr_eeprom.read(consts.HOST_ELECTRICAL_INTERFACE)
def get_module_media_interface(self):
'''
This function returns module media electrical interface. Table 4-6 ~ 4-10 in SFF-8024 Rev4.6
'''
media_type = self.get_module_media_type()
if media_type == 'nm_850_media_interface':
return self.xcvr_eeprom.read(consts.MODULE_MEDIA_INTERFACE_850NM)
elif media_type == 'sm_media_interface':
return self.xcvr_eeprom.read(consts.MODULE_MEDIA_INTERFACE_SM)
elif media_type == 'passive_copper_media_interface':
return self.xcvr_eeprom.read(consts.MODULE_MEDIA_INTERFACE_PASSIVE_COPPER)
elif media_type == 'active_cable_media_interface':
return self.xcvr_eeprom.read(consts.MODULE_MEDIA_INTERFACE_ACTIVE_CABLE)
elif media_type == 'base_t_media_interface':
return self.xcvr_eeprom.read(consts.MODULE_MEDIA_INTERFACE_BASE_T)
else:
return 'Unknown media interface'
def is_coherent_module(self):
'''
Returns True if the module follow C-CMIS spec, False otherwise
'''
mintf = self.get_module_media_interface()
return False if 'ZR' not in mintf else True
def get_host_lane_count(self):
'''
This function returns number of host lanes for default application
'''
return self.xcvr_eeprom.read(consts.HOST_LANE_COUNT)
def get_media_lane_count(self):
'''
This function returns number of media lanes for default application
'''
if self.is_flat_memory():
return 0
return self.xcvr_eeprom.read(consts.MEDIA_LANE_COUNT)
def get_media_interface_technology(self):
'''
This function returns the media lane technology
'''
return self.xcvr_eeprom.read(consts.MEDIA_INTERFACE_TECH)
def get_host_lane_assignment_option(self):
'''
This function returns the host lane that the application begins on
'''
return self.xcvr_eeprom.read(consts.HOST_LANE_ASSIGNMENT_OPTION)
def get_media_lane_assignment_option(self):
'''
This function returns the media lane that the application is allowed to begin on
'''
if self.is_flat_memory():
return 'N/A'
return self.xcvr_eeprom.read(consts.MEDIA_LANE_ASSIGNMENT_OPTION)
def get_active_apsel_hostlane(self):
'''
This function returns the application select code that each host lane has
'''
if (self.is_flat_memory()):
return {'{}{}'.format(consts.ACTIVE_APSEL_HOSTLANE, i) : 'N/A' for i in range(1, self.NUM_CHANNELS+1)}
return self.xcvr_eeprom.read(consts.ACTIVE_APSEL_CODE)
def get_tx_config_power(self):
'''
This function returns the configured TX output power. Unit in dBm
'''
return self.xcvr_eeprom.read(consts.TX_CONFIG_POWER)
def get_media_output_loopback(self):
'''
This function returns the media output loopback status
'''
result = self.xcvr_eeprom.read(consts.MEDIA_OUTPUT_LOOPBACK)
if result is None:
return None
return result == 1
def get_media_input_loopback(self):
'''
This function returns the media input loopback status
'''
result = self.xcvr_eeprom.read(consts.MEDIA_INPUT_LOOPBACK)
if result is None:
return None
return result == 1
def get_host_output_loopback(self):
'''
This function returns the host output loopback status
'''
result = self.xcvr_eeprom.read(consts.HOST_OUTPUT_LOOPBACK)
if result is None:
return None
loopback_status = []
for bitpos in range(self.NUM_CHANNELS):
loopback_status.append(bool((result >> bitpos) & 0x1))
return loopback_status
def get_host_input_loopback(self):
'''
This function returns the host input loopback status
'''
result = self.xcvr_eeprom.read(consts.HOST_INPUT_LOOPBACK)
if result is None:
return None
loopback_status = []
for bitpos in range(self.NUM_CHANNELS):
loopback_status.append(bool((result >> bitpos) & 0x1))
return loopback_status
def get_aux_mon_type(self):
'''
This function returns the aux monitor types
'''
result = self.xcvr_eeprom.read(consts.AUX_MON_TYPE)
if result is None:
return None
aux1_mon_type = result & 0x1
aux2_mon_type = (result >> 1) & 0x1
aux3_mon_type = (result >> 2) & 0x1
return aux1_mon_type, aux2_mon_type, aux3_mon_type
def get_laser_temperature(self):
'''
This function returns the laser temperature monitor value
'''
laser_temp_dict = {
'monitor value' : 'N/A',
'high alarm' : 'N/A',
'low alarm' : 'N/A',
'high warn' : 'N/A',
'low warn' : 'N/A'
}
if self.is_flat_memory():
return laser_temp_dict
try:
aux1_mon_type, aux2_mon_type, aux3_mon_type = self.get_aux_mon_type()
except TypeError:
return None
LASER_TEMP_SCALE = 256.0
if aux2_mon_type == 0:
laser_temp = self.xcvr_eeprom.read(consts.AUX2_MON)/LASER_TEMP_SCALE
laser_temp_high_alarm = self.xcvr_eeprom.read(consts.AUX2_HIGH_ALARM)/LASER_TEMP_SCALE
laser_temp_low_alarm = self.xcvr_eeprom.read(consts.AUX2_LOW_ALARM)/LASER_TEMP_SCALE
laser_temp_high_warn = self.xcvr_eeprom.read(consts.AUX2_HIGH_WARN)/LASER_TEMP_SCALE
laser_temp_low_warn = self.xcvr_eeprom.read(consts.AUX2_LOW_WARN)/LASER_TEMP_SCALE
elif aux2_mon_type == 1 and aux3_mon_type == 0:
laser_temp = self.xcvr_eeprom.read(consts.AUX3_MON)/LASER_TEMP_SCALE
laser_temp_high_alarm = self.xcvr_eeprom.read(consts.AUX3_HIGH_ALARM)/LASER_TEMP_SCALE
laser_temp_low_alarm = self.xcvr_eeprom.read(consts.AUX3_LOW_ALARM)/LASER_TEMP_SCALE
laser_temp_high_warn = self.xcvr_eeprom.read(consts.AUX3_HIGH_WARN)/LASER_TEMP_SCALE
laser_temp_low_warn = self.xcvr_eeprom.read(consts.AUX3_LOW_WARN)/LASER_TEMP_SCALE
else:
return laser_temp_dict
laser_temp_dict = {'monitor value': laser_temp,
'high alarm': laser_temp_high_alarm,
'low alarm': laser_temp_low_alarm,
'high warn': laser_temp_high_warn,
'low warn': laser_temp_low_warn}
return laser_temp_dict
def get_laser_TEC_current(self):
'''
This function returns the laser TEC current monitor value
'''
try:
aux1_mon_type, aux2_mon_type, aux3_mon_type = self.get_aux_mon_type()
except TypeError:
return None
LASER_TEC_CURRENT_SCALE = 32767.0
if aux1_mon_type == 1:
laser_tec_current = self.xcvr_eeprom.read(consts.AUX1_MON)/LASER_TEC_CURRENT_SCALE
laser_tec_current_high_alarm = self.xcvr_eeprom.read(consts.AUX1_HIGH_ALARM)/LASER_TEC_CURRENT_SCALE
laser_tec_current_low_alarm = self.xcvr_eeprom.read(consts.AUX1_LOW_ALARM)/LASER_TEC_CURRENT_SCALE
laser_tec_current_high_warn = self.xcvr_eeprom.read(consts.AUX1_HIGH_WARN)/LASER_TEC_CURRENT_SCALE
laser_tec_current_low_warn = self.xcvr_eeprom.read(consts.AUX1_LOW_WARN)/LASER_TEC_CURRENT_SCALE
elif aux1_mon_type == 0 and aux2_mon_type == 1:
laser_tec_current = self.xcvr_eeprom.read(consts.AUX2_MON)/LASER_TEC_CURRENT_SCALE
laser_tec_current_high_alarm = self.xcvr_eeprom.read(consts.AUX2_HIGH_ALARM)/LASER_TEC_CURRENT_SCALE
laser_tec_current_low_alarm = self.xcvr_eeprom.read(consts.AUX2_LOW_ALARM)/LASER_TEC_CURRENT_SCALE
laser_tec_current_high_warn = self.xcvr_eeprom.read(consts.AUX2_HIGH_WARN)/LASER_TEC_CURRENT_SCALE
laser_tec_current_low_warn = self.xcvr_eeprom.read(consts.AUX2_LOW_WARN)/LASER_TEC_CURRENT_SCALE
else:
return None
laser_tec_current_dict = {'monitor value': laser_tec_current,
'high alarm': laser_tec_current_high_alarm,
'low alarm': laser_tec_current_low_alarm,
'high warn': laser_tec_current_high_warn,
'low warn': laser_tec_current_low_warn}
return laser_tec_current_dict
def get_config_datapath_hostlane_status(self):
'''
This function returns configuration command execution
/ result status for the datapath of each host lane
'''
return self.xcvr_eeprom.read(consts.CONFIG_LANE_STATUS)
def get_datapath_state(self):
'''
This function returns the eight datapath states
'''
return self.xcvr_eeprom.read(consts.DATA_PATH_STATE)
def get_dpinit_pending(self):
'''
This function returns datapath init pending status.
0 means datapath init not pending.
1 means datapath init pending. DPInit not yet executed after successful ApplyDPInit.
Hence the active control set content may deviate from the actual hardware config
'''
dpinit_pending_dict = self.xcvr_eeprom.read(consts.DPINIT_PENDING)
if dpinit_pending_dict is None:
return None
for key, value in dpinit_pending_dict.items():
dpinit_pending_dict[key] = bool(value)
return dpinit_pending_dict
def get_supported_power_config(self):
'''
This function returns the supported TX power range
'''
min_prog_tx_output_power = self.xcvr_eeprom.read(consts.MIN_PROG_OUTPUT_POWER)
max_prog_tx_output_power = self.xcvr_eeprom.read(consts.MAX_PROG_OUTPUT_POWER)
return min_prog_tx_output_power, max_prog_tx_output_power
def reset_module(self, reset = False):
'''
This function resets the module
Return True if the provision succeeds, False if it fails
Return True if no action.
'''
if reset:
reset_control = reset << 3
return self.xcvr_eeprom.write(consts.MODULE_LEVEL_CONTROL, reset_control)
else:
return True
def get_lpmode(self):
'''
Retrieves Low power module status
Returns True if module in low power else returns False.
'''
if self.is_flat_memory() or not self.get_lpmode_support():
return False
lpmode = self.xcvr_eeprom.read(consts.TRANS_MODULE_STATUS_FIELD)
if lpmode is not None:
if lpmode.get('ModuleState') == 'ModuleLowPwr':
return True
return False
def set_lpmode(self, lpmode):
'''
This function sets the module to low power state.
lpmode being False means "set to high power"
lpmode being True means "set to low power"
Return True if the provision succeeds, False if it fails
'''
if self.is_flat_memory() or not self.get_lpmode_support():
return False
lpmode_val = self.xcvr_eeprom.read(consts.MODULE_LEVEL_CONTROL)
if lpmode_val is not None:
if lpmode is True:
lpmode_val = lpmode_val | (1 << 4)
self.xcvr_eeprom.write(consts.MODULE_LEVEL_CONTROL, lpmode_val)
time.sleep(0.1)
return self.get_lpmode()
else:
lpmode_val = lpmode_val & ~(1 << 4)
self.xcvr_eeprom.write(consts.MODULE_LEVEL_CONTROL, lpmode_val)
time.sleep(1)
lpmode = self.xcvr_eeprom.read(consts.TRANS_MODULE_STATUS_FIELD)
if lpmode is not None:
if lpmode.get('ModuleState') == 'ModuleReady':
return True
return False
return False
def get_loopback_capability(self):
'''
This function returns the module loopback capability as advertised
'''
allowed_loopback_result = self.xcvr_eeprom.read(consts.LOOPBACK_CAPABILITY)
if allowed_loopback_result is None:
return None
loopback_capability = dict()
loopback_capability['simultaneous_host_media_loopback_supported'] = bool((allowed_loopback_result >> 6) & 0x1)
loopback_capability['per_lane_media_loopback_supported'] = bool((allowed_loopback_result >> 5) & 0x1)
loopback_capability['per_lane_host_loopback_supported'] = bool((allowed_loopback_result >> 4) & 0x1)
loopback_capability['host_side_input_loopback_supported'] = bool((allowed_loopback_result >> 3) & 0x1)
loopback_capability['host_side_output_loopback_supported'] = bool((allowed_loopback_result >> 2) & 0x1)
loopback_capability['media_side_input_loopback_supported'] = bool((allowed_loopback_result >> 1) & 0x1)
loopback_capability['media_side_output_loopback_supported'] = bool((allowed_loopback_result >> 0) & 0x1)
return loopback_capability
def set_loopback_mode(self, loopback_mode):
'''
This function sets the module loopback mode.
Loopback mode has to be one of the five:
1. "none" (default)
2. "host-side-input"
3. "host-side-output"
4. "media-side-input"
5. "media-side-output"
The function will look at 13h:128 to check advertized loopback capabilities.
Return True if the provision succeeds, False if it fails
'''
loopback_capability = self.get_loopback_capability()
if loopback_capability is None:
return None
if loopback_mode == 'none':
status_host_input = self.xcvr_eeprom.write(consts.HOST_INPUT_LOOPBACK, 0)
status_host_output = self.xcvr_eeprom.write(consts.HOST_OUTPUT_LOOPBACK, 0)
status_media_input = self.xcvr_eeprom.write(consts.MEDIA_INPUT_LOOPBACK, 0)
status_media_output = self.xcvr_eeprom.write(consts.MEDIA_OUTPUT_LOOPBACK, 0)
return all([status_host_input, status_host_output, status_media_input, status_media_output])
elif loopback_mode == 'host-side-input':
assert loopback_capability['host_side_input_loopback_supported']
return self.xcvr_eeprom.write(consts.HOST_INPUT_LOOPBACK, 0xff)
elif loopback_mode == 'host-side-output':
assert loopback_capability['host_side_output_loopback_supported']
return self.xcvr_eeprom.write(consts.HOST_OUTPUT_LOOPBACK, 0xff)
elif loopback_mode == 'media-side-input':
assert loopback_capability['media_side_input_loopback_supported']
return self.xcvr_eeprom.write(consts.MEDIA_INPUT_LOOPBACK, 0xff)
elif loopback_mode == 'media-side-output':
assert loopback_capability['media_side_output_loopback_supported']
return self.xcvr_eeprom.write(consts.MEDIA_OUTPUT_LOOPBACK, 0xff)
else:
return 'N/A'
def get_vdm(self):
'''
This function returns all the VDM items, including real time monitor value, threholds and flags
'''
vdm = self.vdm.get_vdm_allpage() if not self.is_flat_memory() else {}
return vdm
def get_module_firmware_fault_state_changed(self):
'''
This function returns datapath firmware fault state, module firmware fault state
and whether module state changed
'''
result = self.xcvr_eeprom.read(consts.MODULE_FIRMWARE_FAULT_INFO)
if result is None:
return None
datapath_firmware_fault = bool((result >> 2) & 0x1)
module_firmware_fault = bool((result >> 1) & 0x1)
module_state_changed = bool(result & 0x1)
return datapath_firmware_fault, module_firmware_fault, module_state_changed
def get_module_level_flag(self):
'''
This function returns teh module level flags, including
- 3.3 V voltage supply flags
- Case temperature flags
- Aux 1 flags
- Aux 2 flags
- Aux 3 flags
- Custom field flags
'''
module_flag_byte1 = self.xcvr_eeprom.read(consts.MODULE_FLAG_BYTE1)
module_flag_byte2 = self.xcvr_eeprom.read(consts.MODULE_FLAG_BYTE2)
module_flag_byte3 = self.xcvr_eeprom.read(consts.MODULE_FLAG_BYTE3)
if module_flag_byte1 is None or module_flag_byte2 is None or module_flag_byte3 is None:
return None
voltage_high_alarm_flag = bool((module_flag_byte1 >> 4) & 0x1)
voltage_low_alarm_flag = bool((module_flag_byte1 >> 5) & 0x1)
voltage_high_warn_flag = bool((module_flag_byte1 >> 6) & 0x1)