-
Notifications
You must be signed in to change notification settings - Fork 5
/
read-optic.py
executable file
·2179 lines (1884 loc) · 75.6 KB
/
read-optic.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
#!/usr/bin/python3
# XXX FIXME: Need to implement SFF-8636 to read 4-lane optics
#
# XXX FIXME: Need to read all user-pages on 0xa0 with page-select-byte (?)
# (c) 2015-2023 Jared Mauch jared@puck.nether.net
# (c) 2015 WhiteBoxOptical LLC
#
# Unauthorized copying Prohibited
#
# Raspberry PI 2 setup details:
# % # echo dtparam=i2c_arm=on >> /boot/config.txt
# % # echo dtparam=i2c_vc=on >> /boot/config.txt
# % # apt-get install python-smbus2
# % # modprobe i2c_dev ; echo i2c_dev >> /etc/modules
# % ** append bcm2708.vc_i2c_override=1 to /boot/cmdline.txt
#
# INF-8074 version: 1.0
# INF-8077 version: 4.5
# SFF-8024 version: 4.1
# SFF-8436 version: FIXME (needs to be 4.8)
# SFF-8472 version: 12.4
# SFF-8636 version: FIXME (needs to be x)
# SFF-8679 version: FIXME (needs to be x)
# SFF-8690 version: FIXME
#
#
#
from __future__ import division
from __future__ import print_function
# some optics (eg: GLC-T) come soft-disabled for some reason
# added code to soft-enable them
from builtins import chr
from builtins import range
real_hardware = True
if real_hardware:
import smbus2
import time
import json
import math
from curses.ascii import isprint
usleep = lambda x: time.sleep(x/1000000.0)
# globals
address_one = 0x50 # A0
address_two = 0x51 # A2 DDM and SFF-8690 Tunable support
tmp102_address = 0x48
#tmp102_address = 0x4e
# lower page
optic_lower_page = bytearray.fromhex("0304070000000000000000066f00500000000000465320202020202020202020202020200000000e445734342d3130472d38302d343231343030303106060e7a051a000043323030373038383832312020202020323030373239202068f004d69f001140582c22d8ecbfaaa8bf97f51d83983a00000000000000000031d51b76ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00")
# page 0
optic_sff = bytearray.fromhex("0304070000000000000000066f00500000000000465320202020202020202020202020200000000e445734342d3130472d38302d343231343030303106060e7a051a000043323030373038383832312020202020323030373239202068f004d69f001140582c22d8ecbfaaa8bf97f51d83983a00000000000000000031d51b76ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00")
optic_sff_read = len(optic_sff)
upper_page = { }
#upper_page{1} = bytearray.fromhex("030402004a000000000065a4051424f017c2460000009c1a00fa773b03070613075d3d77ff00003822000000000000000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099")
#upper_page{2}=bytearray.fromhex("4b00fb00460000008dcc7404875a7a76000000000000000000000000000000003f8029803c802c8000000000000000009f220a847e6714fac35030d4afc8445c9f2202777e6704eb000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007c")
#upper_page{0x10}=bytearray.fromhex("00000000000000000000000000000000001010101010101010ff000000000000ffff2222222200000000333333330000000000002121212121212121ff000000000000ffff2222222200000000333333330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
#upper_page{0x11}=bytearray.fromhex("44444444000000000000000000000000000000000000000000005552564c549b561b00000000000000007417687461a861a80000000000000000481a4bbf432546810000000000000000111111111010101010101010ff000000000000ffff222222220000000033333333000000000011213141000000001121314100000000")
# page 1
optic_ddm = bytearray.fromhex("5000f6004b00fb0088b8785087f07918d6d82710c3503a986e181ba7621f1f070c5a002809d00032000000000000000000000000000000000000000000000000000000003f8000000000000001000000010000000100000001000000000000b116a980d7000000000000000000000000054000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
optic_ddm_read = 255
optic_dwdm =[]
optic_dwdm_read = -1
def reset_muxes(busno):
mcp23017_bus = smbus2.SMBus(busno)
for mcp23017 in [0x20, 0x21, 0x22, 0x23]:
try:
optic_bus.write_byte_data(mcp23017, 0, 0)
usleep(20)
optic_bus.write_byte_data(mcp23017, 0, 0xff)
except IOError:
usleep(0)
def fetch_psu_data(busno):
try:
psu_bus = smbus2.SMBus(busno)
except:
return
for psu_address in [0x40, 0x47]:
psu=[]
psu_read = -1
# psu_address= 0x40
while psu_read < 128:
try:
if (psu_read == -1):
psu_tmp = psu_bus.read_i2c_block_data(psu_address, 0, 32)
else:
psu_tmp = psu_bus.read_i2c_block_data(psu_address, psu_read, 32)
for member in psu_tmp:
psu.append(member)
psu_read = len(psu)
# print("psu_read=%d, %d" % (psu_read, len(psu))
except IOError:
break
# print("PSU_ADDRESS: 0x%x" % psu_address
if psu_read >= 128:
psu_model=""
psu_sn=""
psu_rev=""
psu_mfg=""
# print("PSU: %d bytes in model#" % psu[0]
for byte in range (1, 16):
if (isprint(chr(psu[byte]))):
psu_model += "%c" % psu[byte]
for byte in range (17, 26):
if (isprint(chr(psu[byte]))):
psu_sn += "%c" % psu[byte]
for byte in range (27, 29):
if (isprint(chr(psu[byte]))):
psu_rev += "%c" % psu[byte]
for byte in range (33, 42):
if (isprint(chr(psu[byte]))):
psu_mfg += "%c" % psu[byte]
psu_date = "%4.4d-%-2.2d-%2.2d" % (psu[29]+2000, psu[30], psu[31])
print("PSU_MODEL: %s" % psu_model)
print("PSU_SN: %s" % psu_sn)
print("PSU_DATE: %s" % psu_date)
print("PSU_MFG: %s" % psu_mfg)
print("PSU_MFG_LOC: %d" % psu[42])
print("PSU_SPEC_VOLTAGE: %d" % ((psu[43]*256)+psu[44]))
print("PSU_SPEC_CURRENT: %d" % ((psu[46]*256)+psu[47]))
print("PSU_SPEC_POWER: %d" % ((psu[49]*256)+psu[50]))
print("PSU_SPEC_MIN_AC: %d" % ((psu[51]*256)+psu[52]))
print("PSU_SPEC_MAX_AC: %d" % ((psu[53]*256)+psu[54]))
print("PSU_CHECKSUM: %d" % psu[55])
print("PSU_FAULT: 0x%x" % psu[56])
# if (psu[56] & 0x80): # 0b10000000
# if (psu[56] & 0x40): # 0b01000000
# if (psu[56] & 0x20): # 0b00100000
if (psu[56] & 0x10): # 0b00010000
print("PSU_FAULT: OVER_TEMP")
if (psu[56] & 0x08): #
print("PSU_FAULT: FAN_FAIL")
if (psu[56] & 0x04): #
print("PSU_FAULT: DC_OUTPUT_FAIL")
if (psu[56] & 0x02): #
print("PSU_FAULT: AC_INPUT_FAIL")
if (psu[56] & 0x01): #
print("PSU_FAULT: SEATED_IMPROPERLY")
print("PSU_FAN_SPEED: %d RPM" % (psu[57]*100))
if (psu[58] & 0x80):
print("PSU_TEMP: OUT_OF_RANGE")
else:
psu_temp = (psu[58] & 0b01111111)-34
print("PSU_TEMP: %d C" % psu_temp)
print("PSU_ROHS_BYTE: %c" % psu[59])
def fetch_optic_data(optic_bus):
# import as globals
global optic_sff
global optic_sff_read
#
global optic_ddm
global optic_ddm_read
#
global optic_dwdm
global optic_dwdm_read
# initalize them
optic_sff =[]
optic_sff_read = 0
optic_ddm =[]
optic_ddm_read = -1
optic_dwdm =[]
optic_dwdm_read = -1
fast_read = 0
# read SFF data
while optic_sff_read < 256:
try:
if fast_read == 1:
optic_sff_tmp = optic_bus.read_i2c_block_data(address_one, optic_sff_read, 32, force=True)
# print("DEBUG: read %d bytes" % len(optic_sff_tmp))
for member in optic_sff_tmp:
optic_sff.append(member)
optic_sff_read = len(optic_sff)
else:
value = optic_bus.read_byte_data(address_one, optic_sff_read)
optic_sff.append(value)
optic_sff_read = len(optic_sff)
# print("optic_sff_read=%d, %d" % (optic_sff_read, len(optic_sff)))
except IOError:
break
# regular page
try:
# write data to set to default page
# print("Switching optic to page 0"
optic_bus.write_byte_data(address_two, 127, 0x0)
except IOError:
# error switching to dwdm data page
# print("IOError while trying to switch optic page"
pass
# read DDM data
# for byte in range (0, 256):
# try:
# value = optic_bus.read_byte_data(address_two, byte)
# optic_ddm.insert(byte, value)
# optic_ddm_read = byte+1
# # IOError reading DDM data
# except IOError:
# a=0
while optic_ddm_read < 256:
try:
if fast_read == 1:
if (optic_ddm_read == -1):
optic_ddm_tmp = optic_bus.read_i2c_block_data(address_two, 0, 32)
else:
optic_ddm_tmp = optic_bus.read_i2c_block_data(address_two, optic_ddm_read, 32)
for member in optic_ddm_tmp:
optic_ddm.append(member)
optic_ddm_read = len(optic_ddm)
else:
value = optic_bus.read_byte_data(address_two, optic_ddm_read)
optic_ddm.append(value)
optic_ddm_read = len(optic_ddm)
# print("optic_ddm_read=%d, %d" % (optic_ddm_read, len(optic_ddm))
except IOError:
break
# print("optic_ddm_read=%d" % optic_ddm_read
# if dwdm optic value
if (optic_sff_read > 65):
if (optic_sff[65] & 0x40):
# switch to page with DWDM dwdm data
try:
# write data
# print("Switching to page 2"
optic_bus.write_byte_data(address_two, 127, 0x2)
except IOError:
# error switching to dwdm data page
a=0
# read DWDM-DDM data
while optic_dwdm_read < 256:
try:
if (optic_dwdm_read == -1):
optic_dwdm_tmp = optic_bus.read_i2c_block_data(address_two, 0, 32)
else:
optic_dwdm_tmp = optic_bus.read_i2c_block_data(address_two, optic_dwdm_read, 32)
for member in optic_dwdm_tmp:
optic_dwdm.append(member)
optic_dwdm_read = len(optic_dwdm)
# print("optic_dwdm_read=%d, %d" % (optic_dwdm_read, len(optic_dwdm))
except IOError:
break
# print("optic_dwdm(PAGE2)_read=%d" % optic_dwdm_read
def read_optic_type():
# defined in SFF-8024 4.11
# updated 2023-12-05
if optic_sff[0] == 0x00:
sff_type_text = "Unknown or unspecified"
elif optic_sff[0] == 0x01:
sff_type_text = "GBIC"
elif optic_sff[0] == 0x02:
sff_type_text = "Module soldered to motherboard" # SFF-8472
elif optic_sff[0] == 0x03:
sff_type_text = "SFP/SFP+/SFP28" # SFF-8472
elif optic_sff[0] == 0x04:
sff_type_text = "300 pin XBI"
elif optic_sff[0] == 0x05:
sff_type_text = "XENPAK"
elif optic_sff[0] == 0x06:
sff_type_text = "XFP" # INF-8077i, SFF-8477
elif optic_sff[0] == 0x07:
sff_type_text = "XFF"
elif optic_sff[0] == 0x08:
sff_type_text = "XFP-E"
elif optic_sff[0] == 0x09:
sff_type_text = "XPAK"
elif optic_sff[0] == 0x0A:
sff_type_text = "X2"
elif optic_sff[0] == 0x0B:
sff_type_text = "DWDM-SFP/SFP+" # DOES NOT USE SFF-8472
elif optic_sff[0] == 0x0C:
sff_type_text = "QSFP"
elif optic_sff[0] == 0x0D:
sff_type_text = "QSFP+" # SFF-8436 SFF-8635 SFF-8665 SFF-8685
elif optic_sff[0] == 0x0E:
sff_type_text = "CXP"
elif optic_sff[0] == 0x0F:
sff_type_text = "Shielded Mini Multilane HD 4X"
elif optic_sff[0] == 0x10:
sff_type_text = "Shielded Mini Multilane HD 8X"
elif optic_sff[0] == 0x11:
sff_type_text = "QSFP28" # SFF-8636/SFF-8665
elif optic_sff[0] == 0x12:
sff_type_text = "CXP2/CFP28"
elif optic_sff[0] == 0x13:
sff_type_text = "CDFP" # INF-TA-1003 style 1/2
elif optic_sff[0] == 0x14:
sff_type_text = "Shielded Mini Multilane HD 4X Fanout"
elif optic_sff[0] == 0x15:
sff_type_text = "Shielded Mini Multilane HD 8X Fanout"
elif optic_sff[0] == 0x16:
sff_type_text = "CDFP Style 3" # INF-TA-1003
elif optic_sff[0] == 0x17:
sff_type_text = "microQSFP"
elif optic_sff[0] == 0x18:
sff_type_text = "QSFP-DD" # CMIS 5.0
elif optic_sff[0] == 0x19:
sff_type_text = "OSPF 8X Pluggable Transceiver"
elif optic_sff[0] == 0x1a:
sff_type_text = "SFP-DD Double Density 2X Pluggable Transceiver"
elif optic_sff[0] == 0x1b:
sff_type_text = "DSFP Dual Small Form Factor Pluggable Transceiver"
elif optic_sff[0] == 0x1c:
sff_type_text = "x4 MiniLink/OcuLink"
elif optic_sff[0] == 0x1d:
sff_type_text = "x4 MiniLink"
elif optic_sff[0] == 0x1f:
sff_type_text = "QSFP+ or later with Common Management Interface Specification (CMIS)"
elif optic_sff[0] == 0x20:
sff_type_text = "SFP+ CMIS"
elif optic_sff[0] == 0x21:
sff_type_text = "OSFP-XD CMIS"
elif optic_sff[0] == 0x22:
sff_type_text = "OIF-ELSFP CMIS"
elif optic_sff[0] == 0x23:
sff_type_text = "CDFP (x4 PCIe) SFF-TA-1032 CMIS"
elif optic_sff[0] == 0x24:
sff_type_text = "CDFP (x8 PCIe) SFF-TA-1032 CMIS"
elif optic_sff[0] == 0x25:
sff_type_text = "CDFP (x16 PCIe) SFF-TA-1032 CMIS"
elif optic_sff[0] >= 0x80:
sff_type_text = "Vendor Specific"
else:
sff_type_text = "Not yet specified value (%d) check SFF-8024" % optic_sff[0]
print("SFF Type:", sff_type_text)
return int(optic_sff[0])
def read_optic_mod_def():
# SFF-8472 Physical Device Extended Identifer Values
# Byte 1 Table 5-2
if optic_sff[1] == 0x00:
mod_def_text = ("Not Specified")
elif optic_sff[1] == 0x01:
mod_def_text = ("MOD_DEF 1")
elif optic_sff[1] == 0x02:
mod_def_text = ("MOD_DEF 2")
elif optic_sff[1] == 0x03:
mod_def_text = ("MOD_DEF 3")
elif optic_sff[1] == 0x04:
mod_def_text = ("function defined by i2c ID only")
elif optic_sff[1] == 0x05:
mod_def_text = ("MOD_DEF 5")
elif optic_sff[1] == 0x06:
mod_def_text = ("MOD_DEF 6")
elif optic_sff[1] == 0x07:
mod_def_text = ("MOD_DEF 7")
else:
mod_def_text = ("Unallocated (%d)" % optic_sff[1])
print("Extended Identifier Value:", mod_def_text)
def read_optic_connector_type(connector_type):
# defined in SFF-8024 4-3, INF-8077 Table 48
# connector_type = optic_sff[2]
# if (optic_sff[0] == 0x06): # XFP
# connector_type = optic_sff[130]
if connector_type == 0x00:
connector_type_text = "Unknown or unspecified"
elif connector_type == 0x01:
connector_type_text = "SC"
elif connector_type == 0x02:
connector_type_text ="Fibre Channel Style 1 copper connector"
elif connector_type == 0x03:
connector_type_text ="Fibre Channel Style 2 copper connector"
elif connector_type == 0x04:
connector_type_text ="BNC/TNC"
elif connector_type == 0x05:
connector_type_text ="Fiber Channel coax headers"
elif connector_type == 0x06:
connector_type_text ="Fiber Jack"
elif connector_type == 0x07:
connector_type_text ="LC"
elif connector_type == 0x08:
connector_type_text ="MT-RJ"
elif connector_type == 0x09:
connector_type_text ="MU"
elif connector_type == 0x0A:
connector_type_text ="SG"
elif connector_type == 0x0B:
connector_type_text ="Optical Pigtail"
elif connector_type == 0x0C:
connector_type_text ="MPO 1x12"
elif connector_type == 0x0D:
connector_type_text ="MPO 2x16"
elif connector_type == 0x20:
connector_type_text ="HSSDC II"
elif connector_type == 0x21:
connector_type_text = "Copper Pigtail"
elif connector_type == 0x22:
connector_type_text = "RJ45"
elif connector_type == 0x23:
connector_type_text = "No separable connector"
elif connector_type == 0x24:
connector_type_text = "MXC 2x16"
elif connector_type == 0x25:
connector_type_text = "CS optical connector"
elif connector_type == 0x26:
connector_type_text = "SN optical connector (Mini CS)"
elif connector_type == 0x27:
connector_type_text = "MPO 2x12"
elif connector_type == 0x28:
connector_type_text = "MPO 1x16"
elif connector_type >= 0x80:
connector_type_text = "Vendor Specific" # sff-8024 4.3
else:
connector_type_text = "Not yet specified value (%d) check SFF-8024" % connector_type
print("Connector Type:", connector_type_text)
def read_sff_optic_encoding():
# SFF 8472 11
# SFF 8024 4-2
# SFF-8436 & SFF-8636
if optic_sff[11] == 0x00:
encoding_type_text = ("Unspecified")
elif optic_sff[11] == 0x01:
encoding_type_text = ("8B/10B")
elif optic_sff[11] == 0x02:
encoding_type_text = ("4B/5B")
elif optic_sff[11] == 0x03:
encoding_type_text = ("NRZ")
# 0x4-0x6 only valid for SFF-8472, SFF-8436 and SFF-8636 has other encodings
elif optic_sff[11] == 0x04:
encoding_type_text = ("Manchester")
elif optic_sff[11] == 0x05:
encoding_type_text = ("SONET Scrambled")
elif optic_sff[11] == 0x06:
encoding_type_text = ("64B/66B")
elif optic_sff[11] == 0x07:
encoding_type_text = ("256B/257B")
elif optic_sff[11] == 0x08:
encoding_type_text = ("PAM-4")
else:
encoding_type_text = ("Not yet specified value (%d) check SFF-8024" % optic_sff[11])
print("Encoding Type:", encoding_type_text)
def read_xfp_encoding():
# INF-8077 Table 50 Byte 139
xfp_encoding= []
if (optic_sff[139] & 0x80): # bit 7
xfp_encoding.append('64B/66B')
if (optic_sff[139] & 0x40): # bit 6
xfp_encoding.append('8B10B')
if (optic_sff[139] & 0x20): # bit 5
xfp_encoding.append('SONET Scrambled')
if (optic_sff[139] & 0x10): # bit 4
xfp_encoding.append('NRZ')
if (optic_sff[139] & 0x8): # bit 3
xfp_encoding.append('RZ')
if (optic_sff[139] & 0x4): # bit 2
xfp_encoding.append('139-2-Reserved')
if (optic_sff[139] & 0x2): # bit 1
xfp_encoding.append('139-1-Reserved')
if (optic_sff[139] & 0x1): # bit 0
xfp_encoding.append('139-0-Reserved')
comma=","
print("XFP Encoding:", comma.join(xfp_encoding))
def read_xfp_br():
xfp_min_br = optic_sff[140] * 100
xfp_max_br = optic_sff[141] * 100
print("XFP Min-Bitrate = %d Mbps" % xfp_min_br)
print("XFP Max-Bitrate = %d Mbps" % xfp_max_br)
def read_xfp_lengths():
xfp_len_km_smf = optic_sff[142]
xfp_len_om2_mmf = optic_sff[143] *2 # convert to meters
xfp_len_mmf = optic_sff[144]
xfp_len_om1_mmf = optic_sff[145]
xfp_len_copper = optic_sff[146] # meters
print("XFP Distances:")
print("\tSMF %d KM" % xfp_len_km_smf)
print("\tOM2 MMF %d meters" % xfp_len_om2_mmf)
print("\tOM2 MMF %d meters" % xfp_len_mmf)
print("\tOM1 MMF %d meters" % xfp_len_om1_mmf)
print("\tCopper %d meters" % xfp_len_copper)
def read_xfp_technology():
xfp_device_technology = []
if (optic_sff[147] & 0x8): # bit 3
xfp_device_technology.append('Active Wavelength Control')
else:
xfp_device_technology.append('No Wavelength Control')
if (optic_sff[147] & 0x4): # bit 2
xfp_device_technology.append('Cooled transmitter')
else:
xfp_device_technology.append('Uncooled transmitter')
if (optic_sff[147] & 0x2): # bit 1
xfp_device_technology.append('APD Detector')
else:
xfp_device_technology.append('PIN detector')
if (optic_sff[147] & 0x1): # bit 0
xfp_device_technology.append('Transmitter Tunable')
else:
xfp_device_technology.append('Transmitter not Tunable')
comma=","
print("XFP Technology:", comma.join(xfp_device_technology))
xfp_technology_bits = optic_sff[147] >> 4
print("XFP Transmitter Technology:")
if (xfp_technology_bits == 0x0):
print("\t850 nm VCSEL")
elif (xfp_technology_bits == 0x1):
print("\t1310 nm VCSEL")
elif (xfp_technology_bits == 0x2):
print("\t1550 nm VCSEL")
elif (xfp_technology_bits == 0x3):
print("\t1310 nm FP")
elif (xfp_technology_bits == 0x4):
print("\t1310 nm DFB")
elif (xfp_technology_bits == 0x5):
print("\t1550 nm DFB")
elif (xfp_technology_bits == 0x6):
print("\t1310 nm EML")
elif (xfp_technology_bits == 0x7):
print("\t1550 nm EML")
elif (xfp_technology_bits == 0x8):
print("\tCopper")
else:
print("\tReserved (%x)" % xfp_technology_bits)
def read_qsfpdd_vendor():
# QSFP-DD-CMIS rev4p0
# 16 bytes ASCII at bytes 129-144
vendor = ""
for byte in range (129, 145):
vendor=vendor +('%c' % optic_sff[byte])
print("Vendor:", vendor)
def read_xfp_vendor():
# INF-8077 5.XX
# 16 bytes ASCII at bytes 148-163
vendor = ""
for byte in range (148, 164):
vendor=vendor +('%c' % optic_sff[byte])
print("Vendor:", vendor)
def read_xfp_vendor_pn():
# INF-8077 5.31
vendor_pn = ""
for byte in range (168, 184):
vendor_pn = vendor_pn + ('%c' % optic_sff[byte])
print("Vendor PN:", vendor_pn)
def read_qsfpdd_vendor_pn():
# QSFP-DD-CMIS rev4p0 8.3
# 16 bytes 148-163
vendor_pn = ""
for byte in range (148, 164):
vendor_pn = vendor_pn + ('%c' % optic_sff[byte])
print("Vendor PN:", vendor_pn)
def read_qsfpdd_vendor_rev():
# QSFP-DD-CMIS rev4p0 8.3
# 2 bytes 164-165
vendor_rev = ""
for byte in range (164, 166):
vendor_rev = vendor_rev + ('%c' % optic_sff[byte])
print("Vendor rev:", vendor_rev)
def read_xfp_vendor_rev():
# INF-8077 5.32 (184-185)
vendor_rev = ""
for byte in range (184, 186):
vendor_rev = vendor_rev + ('%c' % optic_sff[byte])
print("Vendor REV:", vendor_rev)
def read_xfp_wavelength():
# INF-8077 5.33 (186,187)
xfp_wavelength = ((optic_sff[186]*256)+optic_sff[187])*.05
print("XFP Wavelength: %d nm" % xfp_wavelength)
# INF-8077 5.34
print("XFP Wavelength Tolerance: %d nm" % (((optic_sff[188]*256)+optic_sff[189]) *.005))
def read_xfp_max_temp():
# INF-8077 5.35
xfp_max_temp_c = optic_sff[190]
print("XFP Max Temp: %d C" % xfp_max_temp_c)
def read_xfp_cc_base():
# INF-8077 5.36
# checksum of bytes 128-190
calc_cc_base = 0
for byte in range (128, 191):
calc_cc_base = calc_cc_base + optic_sff[byte]
print("XFP CC Base = %x, Calc = %x" % (optic_sff[191], calc_cc_base & 0xff))
def read_xfp_power_supply():
# INF-8077 5.37
# 192-195
xfp_max_power_disp = optic_sff[192] * 20
xfp_total_power_disp = optic_sff[193] * 10
xfp_max_current_5v = (optic_sff[194] >> 4) * 50
xfp_max_current_3v = (optic_sff[194] & 0xf) * 100
xfp_max_current_1v = (optic_sff[195] >> 4) * 100
xfp_max_current_neg5v = (optic_sff[195] & 0xf) * 50
print("Maximum Power Dissipation: %d mW" % xfp_max_power_disp)
print("Maximum Total Power Dissipation (P_Down): %d mW" % xfp_total_power_disp)
print("Maximum current required 5V: %d mA" % xfp_max_current_5v)
print("Maximum current required 3V3: %d mA" % xfp_max_current_3v)
print("Maximum current required 1V8: %d mA" % xfp_max_current_1v)
print("Maximum current required -5.2V: %d mA" % xfp_max_current_neg5v)
def read_xfp_ext_ddm_type():
# INF-8077 5.40 Byte 220
xfp_ddm_type=[]
if (optic_sff[220] & 0x10): # bit 4
xfp_ddm_type.append('BER Support')
else:
xfp_ddm_type.append('No BER Support')
if (optic_sff[220] & 0x8): # bit 3
xfp_ddm_type.append('OMA')
else:
xfp_ddm_type.append('Average Power')
comma=','
print("XFP DDM Type:", comma.join(xfp_ddm_type))
def read_xfp_ext_enh_monitoring():
# INF-8077 5.41 Table 57 Byte 221
xfp_enh_options=[]
if (optic_sff[221] & 0x80): # bit 7
xfp_enh_options.append('VPS supported')
if (optic_sff[221] & 0x40): # bit 6
xfp_enh_options.append('Soft TX_DISABLE supported')
if (optic_sff[221] & 0x20): # bit 5
xfp_enh_options.append('Soft P_Down supported')
if (optic_sff[221] & 0x10): # bit 4
xfp_enh_options.append('VPS LV regulator supported')
if (optic_sff[221] & 0x8): # bit 3
xfp_enh_options.append('VPS bypassed regulator modes supported')
if (optic_sff[221] & 0x4): # bit 2
xfp_enh_options.append('Active FEC control functions supported')
if (optic_sff[221] & 0x2): # bit 1
xfp_enh_options.append('Wavelength tunable supported')
if (optic_sff[221] & 0x1): # bit 0
xfp_enh_options.append('CMU Support Mode Supported')
comma=','
print("XFP Enhanced Options:", comma.join(xfp_enh_options))
def read_xfp_cdr():
xfp_cdr_support=[]
if (optic_sff[164] & 0x80): # bit 7
xfp_cdr_support.append('9.95Gb/s')
if (optic_sff[164] & 0x40): # bit 6
xfp_cdr_support.append('10.3Gb/s')
if (optic_sff[164] & 0x20): # bit 5
xfp_cdr_support.append('10.5Gb/s')
if (optic_sff[164] & 0x10): # bit 4
xfp_cdr_support.append('10.7Gb/s')
if (optic_sff[164] & 0x8): # bit 3
xfp_cdr_support.append('11.1Gb/s')
if (optic_sff[164] & 0x4): # bit 2
xfp_cdr_support.append('Reserved')
if (optic_sff[164] & 0x2): # bit 1
xfp_cdr_support.append('Lineside Loopback Mode Supported')
if (optic_sff[164] & 0x1): # bit 0
xfp_cdr_support.append('XFP Loopback Mode Supported')
comma=','
print("XFP CDR Support:", comma.join(xfp_cdr_support))
def read_optic_signaling_rate():
# SFF-8472 12
print("Optic Sigaling Rate: %d Mbit" % (optic_sff[12] *100))
def read_optic_rate_identifier():
# SFF-8472 13
print("Optic Rate Identifier: %d" % optic_sff[13])
def read_optic_vendor():
# SFF-8472
# 16 bytes ASCII at bytes 20-35
vendor = ""
for byte in range (20, 36):
vendor=vendor +('%c' % optic_sff[byte])
print("Vendor:", vendor)
def read_optic_transciever():
# SFF-8472 Table 5-3
# Bytes 3-9
# Extended 1 byte 36
#
# XXX This code is a hack
# XXX
# Decode Table 5-3
if (optic_sff[3] & 0x80):
print("10G-Base-ER")
if (optic_sff[3] & 0x40):
print("10G-Base-LRM")
if (optic_sff[3] & 0x20):
print("10G-Base-LR")
if (optic_sff[3] & 0x10):
print("10G-Base-SR")
if (optic_sff[3] & 0x08):
print("Infiniband 1X SX")
if (optic_sff[3] & 0x04):
print("Infiniband 1X LX")
if (optic_sff[3] & 0x02):
print("infiniband 1X Copper Active")
if (optic_sff[3] & 0x01):
print("Infiniband 1X Copper Passive")
if (optic_sff[6] & 0x80):
print("Base-PX")
if (optic_sff[6] & 0x40):
print("Base-BX10")
if (optic_sff[6] & 0x20):
print("100Base-FX")
if (optic_sff[6] & 0x10):
print("100Base-LX/LX10")
if (optic_sff[6] & 0x08):
print("1000Base-T")
if (optic_sff[6] & 0x04):
print("1000Base-CX")
if (optic_sff[6] & 0x02):
print("1000Base-LX")
if (optic_sff[6] & 0x01):
print("1000Base-SX")
print("extended compliance_code %d" % optic_sff[36])
def read_qsfpdd_vendor_oui():
# QSFP-DD-CMIS-rev4p0
# 3 bytes 145-147
vendor_oui=""
for byte in range (145, 148):
vendor_oui = vendor_oui + ("%2.2x" % optic_sff[byte])
print("vendor_oui: %s" % vendor_oui)
def read_optic_vendor_oui():
# SFF-8472 4-1
# 3 bytes 37-39
vendor_oui=""
for byte in range (37, 40):
vendor_oui = vendor_oui + ("%2.2x" % optic_sff[byte])
print("vendor_oui: %s" % vendor_oui)
def read_xfp_vendor_oui():
# INF-8077 5.30
# 3 bytes 165-167
vendor_oui=""
for byte in range (165, 168):
vendor_oui = vendor_oui + ("%2.2x" % optic_sff[byte])
print("vendor_oui: %s" % vendor_oui)
def read_optic_vendor_partnum():
# QSFP-DD-CMIS-rev4p0
# 16 bytes ASCII at bytes 148-163
vendor_partnum = ""
for byte in range (148, 164):
vendor_partnum=vendor_partnum +('%c' % optic_sff[byte])
print("PN:", vendor_partnum)
def read_optic_vendor_partnum():
# SFF-8472
# 16 bytes ASCII at bytes 40-55
vendor_partnum = ""
for byte in range (40, 56):
vendor_partnum=vendor_partnum +('%c' % optic_sff[byte])
print("PN:", vendor_partnum)
def read_qsfpdd_vendor_sn():
# QSFP-DD-CMIS-rev4p0
# 16 bytes ASCII at bytes 166-181
vendor_serialnum = ""
for byte in range (166, 182):
if (optic_sff[byte] == 0 or optic_sff[byte] == 0xff):
break
vendor_serialnum=vendor_serialnum +('%c' % optic_sff[byte])
print("SN:", vendor_serialnum)
def read_optic_vendor_serialnum():
# SFF-8472
# 16 bytes ASCII at bytes 68-83
vendor_serialnum = ""
for byte in range (68, 84):
if (optic_sff[byte] == 0 or optic_sff[byte] == 0xff):
break
vendor_serialnum=vendor_serialnum +('%c' % optic_sff[byte])
print("SN:", vendor_serialnum)
def read_xfp_ext_vendor_sn():
# INF-8077 5.38 196-211
vendor_serialnum = ""
for byte in range (196, 212):
if (optic_sff[byte] == 0 or optic_sff[byte] == 0xff):
break
vendor_serialnum=vendor_serialnum +('%c' % optic_sff[byte])
print("Vendor SN:", vendor_serialnum)
def read_qsfpdd_date():
# QSFP-DD-CMIS-rev4p0
# 8 bytes ASCII at bytes 182-189
vendor_datecode = ""
for byte in range (182, 190):
if (optic_sff[byte] == 0 or optic_sff[byte] == 0xff):
break
vendor_datecode = vendor_datecode + ('%c' % optic_sff[byte])
print("Date Code:", vendor_datecode)
def read_qsfpdd_clei_code():
# QSFP-DD-CMIS-rev4p0
# 10 bytes ASCII at bytes 190-199
optic_clei_code = ""
for byte in range (190, 199):
if (optic_sff[byte] == 0 or optic_sff[byte] == 0xff):
break
optic_clei_code = optic_clei_code + ('%c' % optic_sff[byte])
print("CLEI Code:", optic_clei_code)
def read_qsfpdd_mod_power():
# QSFP-DD-CMIS-rev4p0
# 2 bytes at 200-201
print("Module Card power Class:", bin(optic_sff[200] >> 5), int(optic_sff[200] >> 5)+1)
print("Module Max Power : %4.2f W" % float(int(optic_sff[201])*.25))
# read_qsfpdd_cable_len
def read_qsfpdd_cable_len():
# QSFP-DD-CMIS-rev4p0
print("read_qsfpdd_length_multiplier:", bin(optic_sff[202]>>6))
print("read_qsfpdd_length_baselength:", optic_sff[202] & 0x1f)
# read_qsfpdd_connector_type
def read_qsfpdd_connector_type():
# QSFP-DD-CMIS-rev4p0
read_optic_connector_type(optic_sff[203])
# read_qsfpdd_copper_attenuation
def read_qsfpdd_copper_attenuation():
# QSFP-DD-CMIS-rev5p0
# bytes 204-209
# 204 - AttenuationAt 5GHz - 1 dB increments
# 205 - AttenuationAt 7GHz - 1 dB increments
# 206 - AttenuationAt 12.9GHz - 1dB increments
# 207 - AttenuationAt 25.8GHz - 1dB increments
# 208-209 reserved
print("read_qsfpdd_copper_attenuation not implemented yet")
# read_qsfpdd_cable_lane_info
def read_qsfpdd_media_lane_info():
# QSFP-DD-CMIS-rev5p0
# 1 byte at 210 bit set for lanes 8-1 in order
# The module indicates which Media Lanes are not supported
print("cmis_media_lane_info:", bin(optic_sff[210]))
# read_qsfpdd_media_interface_tech
def read_qsfpdd_media_interface_tech():
# QSFP-DD-CMIS-rev4p0
# byte 212
if optic_sff[212] == 0x00:
media_interface_technology = ("850nm VCSEL")
elif optic_sff[212] == 0x01:
media_interface_technology = ("1310nm VCSEL")
elif optic_sff[212] == 0x02:
media_interface_technology = ("1550nm VCSEL")
elif optic_sff[212] == 0x03:
media_interface_technology = ("1310nm FP")
elif optic_sff[212] == 0x04:
media_interface_technology = ("1310nm DFB")
elif optic_sff[212] == 0x05:
media_interface_technology = ("850nm VCSEL")
elif optic_sff[212] == 0x06:
media_interface_technology = ("1310nm EML")
elif optic_sff[212] == 0x07:
media_interface_technology = ("1550nm EML")
elif optic_sff[212] == 0x08:
media_interface_technology = ("Others")
elif optic_sff[212] == 0x09:
media_interface_technology = ("1490nm DFB")
elif optic_sff[212] == 0x0a:
media_interface_technology = ("Copper cable unequalized")
elif optic_sff[212] == 0x0b:
media_interface_technology = ("Copper cable passive equalized")
elif optic_sff[212] == 0x0c:
media_interface_technology = ("Copper cable, near and far end limiting active equalizers")
elif optic_sff[212] == 0x0d:
media_interface_technology = ("Copper cable, far end limiting active equalizers")
elif optic_sff[212] == 0x0e:
media_interface_technology = ("Copper cable, near end limiting active equalizers")
elif optic_sff[212] == 0x0f:
media_interface_technology = ("Copper cable, linear active equalizers")
elif optic_sff[212] == 0x10:
media_interface_technology = ("C-band tunble laser")
elif optic_sff[212] == 0x11:
media_interface_technology = ("L-band tunble laser")
else:
media_interface_technology = "Reserved (as of CMIS5p0)";
print("media_interface_technology:", media_interface_technology)
def read_optic_datecode():
# SFF-8472
# 8 bytes ASCII at bytes 84-91
vendor_datecode = ""
for byte in range (84, 92):
if (optic_sff[byte] == 0 or optic_sff[byte] == 0xff):
break
vendor_datecode = vendor_datecode + ('%c' % optic_sff[byte])
print("Date Code:", vendor_datecode)
def read_xfp_datecode():
# INF-8077
# 8 Bytes ASCII at 212-219
vendor_datecode = ""
for byte in range (212, 220):
if (optic_sff[byte] == 0 or optic_sff[byte] == 0xff):
break
vendor_datecode = vendor_datecode + ('%c' % optic_sff[byte])
print("Date Code:", vendor_datecode)
def read_qsfpdd_datecode():
# CMIS rev4p0
# 8 Bytes ASCII at 182-189
vendor_datecode = ""
for byte in range (182, 190):
if (optic_sff[byte] == 0 or optic_sff[byte] == 0xff):
break
vendor_datecode = vendor_datecode + ('%c' % optic_sff[byte])
print("Date Code:", vendor_datecode)