-
Notifications
You must be signed in to change notification settings - Fork 177
/
cmis.py
3157 lines (2834 loc) · 160 KB
/
cmis.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
"""
cmis.py
Implementation of XcvrApi that corresponds to the CMIS specification.
"""
from enum import Enum
from ...fields import consts
from ..xcvr_api import XcvrApi
import logging
from ...codes.public.cmis import CmisCodes
from ...codes.public.sff8024 import Sff8024
from ...fields import consts
from ..xcvr_api import XcvrApi
from .cmisCDB import CmisCdbApi
from .cmisVDM import CmisVdmApi
import time
from collections import defaultdict
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
VDM_FREEZE = 128
VDM_UNFREEZE = 0
class VdmSubtypeIndex(Enum):
VDM_SUBTYPE_REAL_VALUE = 0
VDM_SUBTYPE_HALARM_THRESHOLD = 1
VDM_SUBTYPE_LALARM_THRESHOLD = 2
VDM_SUBTYPE_HWARN_THRESHOLD = 3
VDM_SUBTYPE_LWARN_THRESHOLD = 4
VDM_SUBTYPE_HALARM_FLAG = 5
VDM_SUBTYPE_LALARM_FLAG = 6
VDM_SUBTYPE_HWARN_FLAG = 7
VDM_SUBTYPE_LWARN_FLAG = 8
THRESHOLD_TYPE_STR_MAP = {
VdmSubtypeIndex.VDM_SUBTYPE_HALARM_THRESHOLD: "halarm",
VdmSubtypeIndex.VDM_SUBTYPE_LALARM_THRESHOLD: "lalarm",
VdmSubtypeIndex.VDM_SUBTYPE_HWARN_THRESHOLD: "hwarn",
VdmSubtypeIndex.VDM_SUBTYPE_LWARN_THRESHOLD: "lwarn"
}
FLAG_TYPE_STR_MAP = {
VdmSubtypeIndex.VDM_SUBTYPE_HALARM_FLAG: "halarm",
VdmSubtypeIndex.VDM_SUBTYPE_LALARM_FLAG: "lalarm",
VdmSubtypeIndex.VDM_SUBTYPE_HWARN_FLAG: "hwarn",
VdmSubtypeIndex.VDM_SUBTYPE_LWARN_FLAG: "lwarn"
}
CMIS_VDM_KEY_TO_DB_PREFIX_KEY_MAP = {
"Laser Temperature [C]" : "laser_temperature_media",
"eSNR Media Input [dB]" : "esnr_media_input",
"PAM4 Level Transition Parameter Media Input [dB]" : "pam4_level_transition_media_input",
"Pre-FEC BER Minimum Media Input" : "prefec_ber_min_media_input",
"Pre-FEC BER Maximum Media Input" : "prefec_ber_max_media_input",
"Pre-FEC BER Average Media Input" : "prefec_ber_avg_media_input",
"Pre-FEC BER Current Value Media Input" : "prefec_ber_curr_media_input",
"Errored Frames Minimum Media Input" : "errored_frames_min_media_input",
"Errored Frames Maximum Media Input" : "errored_frames_max_media_input",
"Errored Frames Average Media Input" : "errored_frames_avg_media_input",
"Errored Frames Current Value Media Input" : "errored_frames_curr_media_input",
"eSNR Host Input [dB]" : "esnr_host_input",
"PAM4 Level Transition Parameter Host Input [dB]" : "pam4_level_transition_host_input",
"Pre-FEC BER Minimum Host Input" : "prefec_ber_min_host_input",
"Pre-FEC BER Maximum Host Input" : "prefec_ber_max_host_input",
"Pre-FEC BER Average Host Input" : "prefec_ber_avg_host_input",
"Pre-FEC BER Current Value Host Input" : "prefec_ber_curr_host_input",
"Errored Frames Minimum Host Input" : "errored_frames_min_host_input",
"Errored Frames Maximum Host Input" : "errored_frames_max_host_input",
"Errored Frames Average Host Input" : "errored_frames_avg_host_input",
"Errored Frames Current Value Host Input" : "errored_frames_curr_host_input"
}
class CmisApi(XcvrApi):
NUM_CHANNELS = 8
LowPwrRequestSW = 4
LowPwrAllowRequestHW = 6
def __init__(self, xcvr_eeprom):
super(CmisApi, self).__init__(xcvr_eeprom)
self.vdm = CmisVdmApi(xcvr_eeprom) if not self.is_flat_memory() else None
self.cdb = CmisCdbApi(xcvr_eeprom) if not self.is_flat_memory() else None
def _get_vdm_key_to_db_prefix_map(self):
return CMIS_VDM_KEY_TO_DB_PREFIX_KEY_MAP
def _update_vdm_dict(self, dict_to_update, new_key, vdm_raw_dict, vdm_observable_type, vdm_subtype_index, lane):
"""
Updates the dictionary with the VDM value if the vdm_observable_type exists.
If the key does not exist, it will update the dictionary with 'N/A'.
Args:
dict_to_update (dict): The dictionary to be updated.
new_key (str): The key to be added in dict_to_update.
vdm_raw_dict (dict): The raw VDM dictionary to be parsed.
vdm_observable_type (str): Lookup key in the VDM dictionary.
vdm_subtype_index (VdmSubtypeIndex): The index of the VDM subtype in the VDM page.
lane (int): The lane number to be looked up in the VDM dictionary.
Returns:
bool: True if the key exists in the VDM dictionary, False if not.
"""
try:
dict_to_update[new_key] = vdm_raw_dict[vdm_observable_type][lane][vdm_subtype_index.value]
except (KeyError, TypeError):
dict_to_update[new_key] = 'N/A'
logger.debug('key {} not present in VDM'.format(new_key))
return False
return True
def freeze_vdm_stats(self):
'''
This function freeze all the vdm statistics reporting registers.
When raised by the host, causes the module to freeze and hold all
reported statistics reporting registers (minimum, maximum and
average values)in Pages 24h-27h.
Returns True if the provision succeeds and False incase of failure.
'''
return self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_FREEZE)
def get_vdm_freeze_status(self):
'''
This function reads and returns the vdm Freeze done status.
Returns True if the vdm stats freeze is successful and False if not freeze.
'''
return self.xcvr_eeprom.read(consts.VDM_FREEZE_DONE)
def unfreeze_vdm_stats(self):
'''
This function unfreeze all the vdm statistics reporting registers.
When freeze is ceased by the host, releases the freeze request, allowing the
reported minimum, maximum and average values to update again.
Returns True if the provision succeeds and False incase of failure.
'''
return self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_UNFREEZE)
def get_vdm_unfreeze_status(self):
'''
This function reads and returns the vdm unfreeze status.
Returns True if the vdm stats unfreeze is successful and False if not unfreeze.
'''
return self.xcvr_eeprom.read(consts.VDM_UNFREEZE_DONE)
def get_manufacturer(self):
'''
This function returns the manufacturer of the module
'''
return self.xcvr_eeprom.read(consts.VENDOR_NAME_FIELD)
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_cable_length_type(self):
'''
This function returns the cable type of the module
'''
return "Length Cable Assembly(m)"
def get_cable_length(self):
'''
This function returns the cable length of the module
'''
return self.xcvr_eeprom.read(consts.LENGTH_ASSEMBLY_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_module_type_abbreviation(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_ABBRV_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_MINOR_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_length": float(admin_info[consts.LENGTH_ASSEMBLY_FIELD]),
"nominal_bit_rate": 0, # Not supported
"vendor_date": admin_info[consts.VENDOR_DATE_FIELD],
"vendor_oui": admin_info[consts.VENDOR_OUI_FIELD]
}
appl_advt = self.get_application_advertisement()
xcvr_info['application_advertisement'] = str(appl_advt) if len(appl_advt) > 0 else '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()
xcvr_info['cable_type'] = self.get_cable_length_type()
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['specification_compliance'] = self.get_module_media_type()
# In normal case will get a valid value for each of the fields. If get a 'None' value
# means there was a failure while reading the EEPROM, either because the EEPROM was
# not ready yet or experincing some other issues. It shouldn't return a dict with a
# wrong field value, instead should return a 'None' to indicate to XCVRD that retry is
# needed.
if None in xcvr_info.values():
return None
else:
return xcvr_info
def get_transceiver_info_firmware_versions(self):
return_dict = {"active_firmware" : "N/A", "inactive_firmware" : "N/A"}
result = self.get_module_fw_info()
if result is None:
return return_dict
try:
( _, _, _, _, _, _, _, _, ActiveFirmware, InactiveFirmware) = result['result']
except (ValueError, TypeError):
return return_dict
return_dict["active_firmware"] = ActiveFirmware
return_dict["inactive_firmware"] = InactiveFirmware
return return_dict
def get_transceiver_bulk_status(self):
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 = 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 = {
"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] = float("{:.3f}".format(self.mw_to_dbm(rx_power[i - 1]))) if rx_power[i - 1] != 'N/A' else 'N/A'
bulk_status["tx%dpower" % i] = float("{:.3f}".format(self.mw_to_dbm(tx_power[i - 1]))) if tx_power[i - 1] != 'N/A' else 'N/A'
laser_temp_dict = self.get_laser_temperature()
self.vdm_dict = self.get_vdm(self.vdm.VDM_REAL_VALUE)
try:
bulk_status['laser_temperature'] = laser_temp_dict['monitor value']
except (KeyError, TypeError):
pass
for vdm_key, db_key in CMIS_VDM_KEY_TO_DB_PREFIX_KEY_MAP.items():
for lane in range(1, self.NUM_CHANNELS + 1):
try:
bulk_status_key = "%s%d" % (db_key, lane)
bulk_status[bulk_status_key] = self.vdm_dict[vdm_key][lane][0]
except (KeyError, TypeError):
pass
return bulk_status
def get_transceiver_dom_flags(self):
dom_flag_dict = dict()
module_flag = self.get_module_level_flag()
try:
case_temp_flags = module_flag['case_temp_flags']
voltage_flags = module_flag['voltage_flags']
dom_flag_dict.update({
'temphighalarm': case_temp_flags['case_temp_high_alarm_flag'],
'templowalarm': case_temp_flags['case_temp_low_alarm_flag'],
'temphighwarning': case_temp_flags['case_temp_high_warn_flag'],
'templowwarning': case_temp_flags['case_temp_low_warn_flag'],
'vcchighalarm': voltage_flags['voltage_high_alarm_flag'],
'vcclowalarm': voltage_flags['voltage_low_alarm_flag'],
'vcchighwarning': voltage_flags['voltage_high_warn_flag'],
'vcclowwarning': voltage_flags['voltage_low_warn_flag']
})
except TypeError:
pass
tx_power_flag_dict = self.get_tx_power_flag()
if tx_power_flag_dict:
for lane in range(1, self.NUM_CHANNELS+1):
dom_flag_dict['txpowerhighalarm%d' % lane] = tx_power_flag_dict['tx_power_high_alarm']['TxPowerHighAlarmFlag%d' % lane]
dom_flag_dict['txpowerlowalarm%d' % lane] = tx_power_flag_dict['tx_power_low_alarm']['TxPowerLowAlarmFlag%d' % lane]
dom_flag_dict['txpowerhighwarning%d' % lane] = tx_power_flag_dict['tx_power_high_warn']['TxPowerHighWarnFlag%d' % lane]
dom_flag_dict['txpowerlowwarning%d' % lane] = tx_power_flag_dict['tx_power_low_warn']['TxPowerLowWarnFlag%d' % lane]
rx_power_flag_dict = self.get_rx_power_flag()
if rx_power_flag_dict:
for lane in range(1, self.NUM_CHANNELS+1):
dom_flag_dict['rxpowerhighalarm%d' % lane] = rx_power_flag_dict['rx_power_high_alarm']['RxPowerHighAlarmFlag%d' % lane]
dom_flag_dict['rxpowerlowalarm%d' % lane] = rx_power_flag_dict['rx_power_low_alarm']['RxPowerLowAlarmFlag%d' % lane]
dom_flag_dict['rxpowerhighwarning%d' % lane] = rx_power_flag_dict['rx_power_high_warn']['RxPowerHighWarnFlag%d' % lane]
dom_flag_dict['rxpowerlowwarning%d' % lane] = rx_power_flag_dict['rx_power_low_warn']['RxPowerLowWarnFlag%d' % lane]
tx_bias_flag_dict = self.get_tx_bias_flag()
if tx_bias_flag_dict:
for lane in range(1, self.NUM_CHANNELS+1):
dom_flag_dict['txbiashighalarm%d' % lane] = tx_bias_flag_dict['tx_bias_high_alarm']['TxBiasHighAlarmFlag%d' % lane]
dom_flag_dict['txbiaslowalarm%d' % lane] = tx_bias_flag_dict['tx_bias_low_alarm']['TxBiasLowAlarmFlag%d' % lane]
dom_flag_dict['txbiashighwarning%d' % lane] = tx_bias_flag_dict['tx_bias_high_warn']['TxBiasHighWarnFlag%d' % lane]
dom_flag_dict['txbiaslowwarning%d' % lane] = tx_bias_flag_dict['tx_bias_low_warn']['TxBiasLowWarnFlag%d' % lane]
try:
_, aux2_mon_type, aux3_mon_type = self.get_aux_mon_type()
if aux2_mon_type == 0:
dom_flag_dict['lasertemphighalarm'] = module_flag['aux2_flags']['aux2_high_alarm_flag']
dom_flag_dict['lasertemplowalarm'] = module_flag['aux2_flags']['aux2_low_alarm_flag']
dom_flag_dict['lasertemphighwarning'] = module_flag['aux2_flags']['aux2_high_warn_flag']
dom_flag_dict['lasertemplowwarning'] = module_flag['aux2_flags']['aux2_low_warn_flag']
elif aux2_mon_type == 1 and aux3_mon_type == 0:
dom_flag_dict['lasertemphighalarm'] = module_flag['aux3_flags']['aux3_high_alarm_flag']
dom_flag_dict['lasertemplowalarm'] = module_flag['aux3_flags']['aux3_low_alarm_flag']
dom_flag_dict['lasertemphighwarning'] = module_flag['aux3_flags']['aux3_high_warn_flag']
dom_flag_dict['lasertemplowwarning'] = module_flag['aux3_flags']['aux3_low_warn_flag']
except TypeError:
pass
return dom_flag_dict
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
tx_bias_scale_raw = self.xcvr_eeprom.read(consts.TX_BIAS_SCALE)
if tx_bias_scale_raw is not None:
tx_bias_scale = 2**tx_bias_scale_raw if tx_bias_scale_raw < 3 else 1
else:
tx_bias_scale = 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]*tx_bias_scale))
if tx_bias_scale is not None else 'N/A',
"txbiaslowalarm": float("{:.3f}".format(thresh[consts.TX_BIAS_LOW_ALARM_FIELD]*tx_bias_scale))
if tx_bias_scale is not None else 'N/A',
"txbiashighwarning": float("{:.3f}".format(thresh[consts.TX_BIAS_HIGH_WARNING_FIELD]*tx_bias_scale))
if tx_bias_scale is not None else 'N/A',
"txbiaslowwarning": float("{:.3f}".format(thresh[consts.TX_BIAS_LOW_WARNING_FIELD]*tx_bias_scale))
if tx_bias_scale is not None else 'N/A'
}
laser_temp_dict = self.get_laser_temperature()
try:
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']
except (KeyError, TypeError):
pass
self.vdm_dict = self.get_vdm(self.vdm.VDM_THRESHOLD)
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, TypeError):
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) is not False
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() and self.xcvr_eeprom.read(consts.RX_LOS_SUPPORT)
def get_tx_cdr_lol_support(self):
return not self.is_flat_memory() and self.xcvr_eeprom.read(consts.TX_CDR_LOL_SUPPORT_FIELD)
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
keys = sorted(tx_cdr_lol.keys())
tx_cdr_lol_final = []
for key in keys:
tx_cdr_lol_final.append(bool(tx_cdr_lol[key]))
return tx_cdr_lol_final
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
keys = sorted(rx_los.keys())
rx_los_final = []
for key in keys:
rx_los_final.append(bool(rx_los[key]))
return rx_los_final
def get_rx_cdr_lol_support(self):
return not self.is_flat_memory() and self.xcvr_eeprom.read(consts.RX_CDR_LOL_SUPPORT_FIELD)
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
keys = sorted(rx_cdr_lol.keys())
rx_cdr_lol_final = []
for key in keys:
rx_cdr_lol_final.append(bool(rx_cdr_lol[key]))
return rx_cdr_lol_final
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() and self.xcvr_eeprom.read(consts.TX_BIAS_SUPPORT_FIELD)
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
if not tx_bias_support:
return ["N/A" for _ in range(self.NUM_CHANNELS)]
scale_raw = self.xcvr_eeprom.read(consts.TX_BIAS_SCALE)
if scale_raw is None:
return ["N/A" for _ in range(self.NUM_CHANNELS)]
scale = 2**scale_raw if scale_raw < 3 else 1
tx_bias = self.xcvr_eeprom.read(consts.TX_BIAS_FIELD)
if tx_bias is None:
return ["N/A" for _ in range(self.NUM_CHANNELS)]
for key, value in tx_bias.items():
tx_bias[key] *= scale
return [tx_bias['LaserBiasTx%dField' % i] for i in range(1, self.NUM_CHANNELS + 1)]
def get_tx_power(self):
'''
This function returns TX output power in mW on each media lane
'''
tx_power = ["N/A" for _ in range(self.NUM_CHANNELS)]
tx_power_support = self.get_tx_power_support()
if not tx_power_support:
return tx_power
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() and self.xcvr_eeprom.read(consts.TX_POWER_SUPPORT_FIELD)
def get_rx_power(self):
'''
This function returns RX input power in mW on each media lane
'''
rx_power = ["N/A" for _ in range(self.NUM_CHANNELS)]
rx_power_support = self.get_rx_power_support()
if not rx_power_support:
return rx_power
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() and self.xcvr_eeprom.read(consts.RX_POWER_SUPPORT_FIELD)
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
keys = sorted(tx_fault.keys())
tx_fault_final = []
for key in keys:
tx_fault_final.append(bool(tx_fault[key]))
return tx_fault_final
def get_tx_los_support(self):
return not self.is_flat_memory() and self.xcvr_eeprom.read(consts.TX_LOS_SUPPORT_FIELD)
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
keys = sorted(tx_los.keys())
tx_los_final = []
for key in keys:
tx_los_final.append(bool(tx_los[key]))
return tx_los_final
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_laser_tuning_summary(self):
'''
This function returns laser tuning status summary on media lane
'''
result = self.xcvr_eeprom.read(consts.LASER_TUNING_DETAIL)
laser_tuning_summary = []
if (result >> 5) & 0x1:
laser_tuning_summary.append("TargetOutputPowerOOR")
if (result >> 4) & 0x1:
laser_tuning_summary.append("FineTuningOutOfRange")
if (result >> 3) & 0x1:
laser_tuning_summary.append("TuningNotAccepted")
if (result >> 2) & 0x1:
laser_tuning_summary.append("InvalidChannel")
if (result >> 1) & 0x1:
laser_tuning_summary.append("WavelengthUnlocked")
if (result >> 0) & 0x1:
laser_tuning_summary.append("TuningComplete")
return laser_tuning_summary
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
'''
if self.is_flat_memory():
return 'N/A'
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_datapath_init_duration(self):
'''
This function returns the duration of datapath init
'''
if self.is_flat_memory():
return 0
duration = self.xcvr_eeprom.read(consts.DP_PATH_INIT_DURATION)
return float(duration) if duration is not None else 0
def get_datapath_deinit_duration(self):
'''
This function returns the duration of datapath deinit
'''
if self.is_flat_memory():
return 0
duration = self.xcvr_eeprom.read(consts.DP_PATH_DEINIT_DURATION)
return float(duration) if duration is not None else 0
def get_datapath_tx_turnon_duration(self):
'''
This function returns the duration of datapath tx turnon
'''
if self.is_flat_memory():
return 0
duration = self.xcvr_eeprom.read(consts.DP_TX_TURNON_DURATION)
return float(duration) if duration is not None else 0
def get_datapath_tx_turnoff_duration(self):
'''
This function returns the duration of datapath tx turnoff
'''
if self.is_flat_memory():
return 0
duration = self.xcvr_eeprom.read(consts.DP_TX_TURNOFF_DURATION)
return float(duration) if duration is not None else 0
def get_module_pwr_up_duration(self):
'''
This function returns the duration of module power up
'''
if self.is_flat_memory():
return 0
duration = self.xcvr_eeprom.read(consts.MODULE_PWRUP_DURATION)
return float(duration) if duration is not None else 0
def get_module_pwr_down_duration(self):
'''
This function returns the duration of module power down
'''
if self.is_flat_memory():
return 0
duration = self.xcvr_eeprom.read(consts.MODULE_PWRDN_DURATION)
return float(duration) if duration is not None else 0
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, appl=1):
'''
This function returns number of media lanes for default application
'''
if self.is_flat_memory():
return 0
if (appl <= 0):
return 0
appl_advt = self.get_application_advertisement()
return appl_advt[appl]['media_lane_count'] if len(appl_advt) >= appl else 0
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, appl=1):
'''
This function returns the host lane that the application begins on
Args:
app:
Integer, desired application for which host_lane_assignment_options are requested
'''
if (appl <= 0):