-
Notifications
You must be signed in to change notification settings - Fork 175
/
chassis_base.py
788 lines (624 loc) · 25 KB
/
chassis_base.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
"""
chassis_base.py
Base class for implementing a platform-specific class with which
to interact with a chassis device in SONiC.
"""
import sys
from . import device_base
from . import sfp_base
class ChassisBase(device_base.DeviceBase):
"""
Base class for interfacing with a platform chassis
"""
# Device type definition. Note, this is a constant.
DEVICE_TYPE = "chassis"
# Possible reboot causes
REBOOT_CAUSE_POWER_LOSS = "Power Loss"
REBOOT_CAUSE_THERMAL_OVERLOAD_CPU = "Thermal Overload: CPU"
REBOOT_CAUSE_THERMAL_OVERLOAD_ASIC = "Thermal Overload: ASIC"
REBOOT_CAUSE_THERMAL_OVERLOAD_OTHER = "Thermal Overload: Other"
REBOOT_CAUSE_INSUFFICIENT_FAN_SPEED = "Insufficient Fan Speed"
REBOOT_CAUSE_WATCHDOG = "Watchdog"
REBOOT_CAUSE_HARDWARE_OTHER = "Hardware - Other"
REBOOT_CAUSE_HARDWARE_BIOS = "BIOS"
REBOOT_CAUSE_HARDWARE_CPU = "CPU"
REBOOT_CAUSE_HARDWARE_BUTTON = "Push button"
REBOOT_CAUSE_HARDWARE_RESET_FROM_ASIC = "Reset from ASIC"
REBOOT_CAUSE_NON_HARDWARE = "Non-Hardware"
def __init__(self):
# List of ComponentBase-derived objects representing all components
# available on the chassis
self._component_list = []
# List of ModuleBase-derived objects representing all modules
# available on the chassis (for use with modular chassis)
self._module_list = []
# List of FanBase-derived objects representing all fans
# available on the chassis
self._fan_list = []
# List of FanDrawerBase-derived objects representing all fan drawers
# available on the chassis
self._fan_drawer_list = []
# List of PsuBase-derived objects representing all power supply units
# available on the chassis
self._psu_list = []
# List of ThermalBase-derived objects representing all thermals
# available on the chassis
self._thermal_list = []
self._voltage_sensor_list = []
self._current_sensor_list = []
# List of SfpBase-derived objects representing all sfps
# available on the chassis
self._sfp_list = []
# Object derived from WatchdogBase for interacting with hardware watchdog
self._watchdog = None
# Object derived from eeprom_tlvinfo.TlvInfoDecoder indicating the eeprom on the chassis
self._eeprom = None
# System status LED
self._status_led = None
def get_base_mac(self):
"""
Retrieves the base MAC address for the chassis
Returns:
A string containing the MAC address in the format
'XX:XX:XX:XX:XX:XX'
"""
raise NotImplementedError
def get_system_eeprom_info(self):
"""
Retrieves the full content of system EEPROM information for the chassis
Returns:
A dictionary where keys are the type code defined in
OCP ONIE TlvInfo EEPROM format and values are their corresponding
values.
Ex. { '0x21':'AG9064', '0x22':'V1.0', '0x23':'AG9064-0109867821',
'0x24':'001c0f000fcd0a', '0x25':'02/03/2018 16:22:00',
'0x26':'01', '0x27':'REV01', '0x28':'AG9064-C2358-16G'}
"""
raise NotImplementedError
def get_reboot_cause(self):
"""
Retrieves the cause of the previous reboot
Returns:
A tuple (string, string) where the first element is a string
containing the cause of the previous reboot. This string must be
one of the predefined strings in this class. If the first string
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
to pass a description of the reboot cause.
"""
raise NotImplementedError
def get_supervisor_slot(self):
"""
Retrieves the physical-slot of the supervisor-module in the modular
chassis. On the supervisor or line-card modules, it will return the
physical-slot of the supervisor-module.
On the fixed-platforms, the API can be ignored.
Users of the API can catch the exception and return a default
ModuleBase.MODULE_INVALID_SLOT and bypass code for fixed-platforms.
Returns:
An integer, the vendor specific physical slot identifier of the
supervisor module in the modular-chassis.
"""
return NotImplementedError
def get_my_slot(self):
"""
Retrieves the physical-slot of this module in the modular chassis.
On the supervisor, it will return the physical-slot of the supervisor
module. On the linecard, it will return the physical-slot of the
linecard module where this instance of SONiC is running.
On the fixed-platforms, the API can be ignored.
Users of the API can catch the exception and return a default
ModuleBase.MODULE_INVALID_SLOT and bypass code for fixed-platforms.
Returns:
An integer, the vendor specific physical slot identifier of this
module in the modular-chassis.
"""
return NotImplementedError
def is_modular_chassis(self):
"""
Retrieves whether the sonic instance is part of modular chassis
Returns:
A bool value, should return False by default or for fixed-platforms.
Should return True for supervisor-cards, line-cards etc running as part
of modular-chassis.
For SmartSwitch this should return False.
"""
return False
def init_midplane_switch(self):
"""
Initializes the midplane functionality of the modular chassis. For
example, any validation of midplane, populating any lookup tables etc
can be done here. The expectation is that the required kernel modules,
ip-address assignment etc are done before the pmon, database dockers
are up.
Returns:
A bool value, should return True if the midplane initialized
successfully.
"""
return NotImplementedError
##############################################
# Component methods
##############################################
def get_num_components(self):
"""
Retrieves the number of components available on this chassis
Returns:
An integer, the number of components available on this chassis
"""
return len(self._component_list)
def get_all_components(self):
"""
Retrieves all components available on this chassis
Returns:
A list of objects derived from ComponentBase representing all components
available on this chassis
"""
return self._component_list
def get_component(self, index):
"""
Retrieves component represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the component to retrieve
Returns:
An object dervied from ComponentBase representing the specified component
"""
component = None
try:
component = self._component_list[index]
except IndexError:
sys.stderr.write("Component index {} out of range (0-{})\n".format(
index, len(self._component_list)-1))
return component
##############################################
# Module methods
##############################################
def get_num_modules(self):
"""
Retrieves the number of modules available on this chassis
On a SmarSwitch chassis this will be the number of DPUs.
Returns:
An integer, the number of modules available on this chassis.
On a SmartSwitch this will be the number of DPUs
"""
return len(self._module_list)
def get_all_modules(self):
"""
Retrieves all modules available on this chassis. On a SmartSwitch
chassis this will return all the DPUs.
Returns:
A list of objects derived from ModuleBase representing all
modules available on this chassis. On a SmartSwitch this
will be a list of DPU objects.
"""
return self._module_list
def get_module(self, index):
"""
Retrieves module represented by (0-based) index <index>
On a SmartSwitch index:0 will fetch DPU0 and so on
Args:
index: An integer, the index (0-based) of the module to
retrieve
Returns:
An object derived from ModuleBase representing the specified
module
"""
module = None
try:
module = self._module_list[index]
except IndexError:
sys.stderr.write("Module index {} out of range (0-{})\n".format(
index, len(self._module_list)-1))
return module
def get_module_index(self, module_name):
"""
Retrieves module index from the module name
Args:
module_name: A string, prefixed by SUPERVISOR, LINE-CARD or FABRIC-CARD
Ex. SUPERVISOR0, LINE-CARD1, FABRIC-CARD5
SmartSwitch Example: DPU0, DPU1, DPU2 ... DPUX
Returns:
An integer, the index of the ModuleBase object in the module_list
"""
raise NotImplementedError
##############################################
# SmartSwitch methods
##############################################
def get_dpu_id(self, **kwargs):
"""
Retrieves the DPU ID for the specified DPU module on a Smart Switch chassis.
When run on the Smart Switch chassis, it fetches the ID corresponding to provided DPU module name.
When run on the Smart Switch DPU chassis, returns the ID of the DPU.
This method is relevant only for Smart Switch chassis.
Args:
name (str, optional): The name of the DPU module (e.g., "DPU0", "DPU1").
Returns:
int: The DPU ID associated with the given module name.
For example, for name "DPU0", returns 0; for "DPU1", returns 1, and so on.
"""
raise NotImplementedError
def is_smartswitch(self):
"""
Checks whether the current SONiC instance is part of a Smart Switch platform.
Returns:
bool: True if the instance is part of a Smart Switch, False otherwise.
"""
return False
def is_dpu(self):
"""
Checks whether the current SONiC instance is running on a DPU.
Returns:
bool: True if the instance is running on a DPU, False otherwise.
"""
return False
def get_dataplane_state(self):
"""
Retrieves the status of the dataplane.
Returns:
bool: True if the dataplane is UP, False if it is down.
"""
raise NotImplementedError
def get_controlplane_state(self):
"""
Retrieves the status of the DPU control plane.
Returns:
bool: True if the control plane is UP, False if it is down.
"""
raise NotImplementedError
##############################################
# Fan methods
##############################################
def get_num_fans(self):
"""
Retrieves the number of fans available on this chassis
Returns:
An integer, the number of fan modules available on this chassis
"""
return len(self._fan_list)
def get_all_fans(self):
"""
Retrieves all fan modules available on this chassis
Returns:
A list of objects derived from FanBase representing all fan
modules available on this chassis
"""
return self._fan_list
def get_fan(self, index):
"""
Retrieves fan module represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the fan module to
retrieve
Returns:
An object dervied from FanBase representing the specified fan
module
"""
fan = None
try:
fan = self._fan_list[index]
except IndexError:
sys.stderr.write("Fan index {} out of range (0-{})\n".format(
index, len(self._fan_list)-1))
return fan
def get_num_fan_drawers(self):
"""
Retrieves the number of fan drawers available on this chassis
Returns:
An integer, the number of fan drawers available on this chassis
"""
return len(self._fan_drawer_list)
def get_all_fan_drawers(self):
"""
Retrieves all fan drawers available on this chassis
Returns:
A list of objects derived from FanDrawerBase representing all fan
drawers available on this chassis
"""
return self._fan_drawer_list
def get_fan_drawer(self, index):
"""
Retrieves fan drawers represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the fan drawer to
retrieve
Returns:
An object dervied from FanDrawerBase representing the specified fan
drawer
"""
fan_drawer = None
try:
fan_drawer = self._fan_drawer_list[index]
except IndexError:
sys.stderr.write("Fan drawer index {} out of range (0-{})\n".format(
index, len(self._fan_drawer_list)-1))
return fan_drawer
##############################################
# PSU methods
##############################################
def get_num_psus(self):
"""
Retrieves the number of power supply units available on this chassis
Returns:
An integer, the number of power supply units available on this
chassis
"""
return len(self._psu_list)
def get_all_psus(self):
"""
Retrieves all power supply units available on this chassis
Returns:
A list of objects derived from PsuBase representing all power
supply units available on this chassis
"""
return self._psu_list
def get_psu(self, index):
"""
Retrieves power supply unit represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the power supply unit to
retrieve
Returns:
An object dervied from PsuBase representing the specified power
supply unit
"""
psu = None
try:
psu = self._psu_list[index]
except IndexError:
sys.stderr.write("PSU index {} out of range (0-{})\n".format(
index, len(self._psu_list)-1))
return psu
##############################################
# THERMAL methods
##############################################
def get_num_thermals(self):
"""
Retrieves the number of thermals available on this chassis
Returns:
An integer, the number of thermals available on this chassis
"""
return len(self._thermal_list)
def get_all_thermals(self):
"""
Retrieves all thermals available on this chassis
Returns:
A list of objects derived from ThermalBase representing all thermals
available on this chassis
"""
return self._thermal_list
def get_thermal(self, index):
"""
Retrieves thermal unit represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the thermal to
retrieve
Returns:
An object dervied from ThermalBase representing the specified thermal
"""
thermal = None
try:
thermal = self._thermal_list[index]
except IndexError:
sys.stderr.write("THERMAL index {} out of range (0-{})\n".format(
index, len(self._thermal_list)-1))
return thermal
def get_thermal_manager(self):
"""
Retrieves thermal manager class on this chassis
:return: A class derived from ThermalManagerBase representing the
specified thermal manager. ThermalManagerBase is returned as default
"""
raise NotImplementedError
##############################################
# Voltage Sensor Methods
##############################################
def get_num_voltage_sensors(self):
"""
Retrieves the number of voltage sensors available on this chassis
Returns:
An integer, the number of voltage sensors available on this chassis
"""
return len(self._voltage_sensor_list)
def get_all_voltage_sensors(self):
"""
Retrieves all voltage sensors available on this chassis
Returns:
A list of objects derived from VoltageSensorBase representing all voltage
sensors available on this chassis
"""
return self._voltage_sensor_list
def get_voltage_sensor(self, index):
"""
Retrieves voltage sensor unit represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the voltage sensor to
retrieve
Returns:
An object derived from VoltageSensorBase representing the specified voltage sensor
"""
voltage_sensor = None
try:
voltage_sensor = self._voltage_sensor_list[index]
except IndexError:
sys.stderr.write("Voltage sensor index {} out of range (0-{})\n".format(
index, len(self._voltage_sensor_list)-1))
return voltage_sensor
##############################################
# Current Sensor Methods
##############################################
def get_num_current_sensors(self):
"""
Retrieves the number of current sensors available on this chassis
Returns:
An integer, the number of current sensors available on this chassis
"""
return len(self._current_sensor_list)
def get_all_current_sensors(self):
"""
Retrieves all current sensors available on this chassis
Returns:
A list of objects derived from CurrentSensorBase representing all current
sensors available on this chassis
"""
return self._current_sensor_list
def get_current_sensor(self, index):
"""
Retrieves current sensor object represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the current sensor to
retrieve
Returns:
An object derived from CurrentSensorBase representing the specified current
sensor
"""
current_sensor = None
try:
current_sensor = self._current_sensor_list[index]
except IndexError:
sys.stderr.write("Current sensor index {} out of range (0-{})\n".format(
index, len(self._current_sensor_list)-1))
return current_sensor
##############################################
# SFP methods
##############################################
def get_num_sfps(self):
"""
Retrieves the number of sfps available on this chassis
Returns:
An integer, the number of sfps available on this chassis
"""
return len(self._sfp_list)
def get_all_sfps(self):
"""
Retrieves all sfps available on this chassis
Returns:
A list of objects derived from SfpBase representing all sfps
available on this chassis
"""
return [ sfp for sfp in self._sfp_list if sfp is not None ]
def get_sfp(self, index):
"""
Retrieves sfp corresponding to physical port <index>
Args:
index: An integer (>=0), the index of the sfp to retrieve.
The index should correspond to the physical port in a chassis.
For example:-
1 for Ethernet0, 2 for Ethernet4 and so on for one platform.
0 for Ethernet0, 1 for Ethernet4 and so on for another platform.
Returns:
An object dervied from SfpBase representing the specified sfp
"""
sfp = None
try:
sfp = self._sfp_list[index]
except IndexError:
sys.stderr.write("SFP index {} out of range (0-{})\n".format(
index, len(self._sfp_list)-1))
return sfp
def get_port_or_cage_type(self, index):
"""
Retrieves sfp port or cage type corresponding to physical port <index>
Args:
index: An integer (>=0), the index of the sfp to retrieve.
The index should correspond to the physical port in a chassis.
For example:-
1 for Ethernet0, 2 for Ethernet4 and so on for one platform.
0 for Ethernet0, 1 for Ethernet4 and so on for another platform.
Returns:
The masks of all types of port or cage that can be supported on the port
Types are defined in sfp_base.py
Eg.
Both SFP and SFP+ are supported on the port, the return value should be 0x0a
which is 0x02 | 0x08
"""
raise NotImplementedError
##############################################
# System LED methods
##############################################
def set_status_led(self, color):
"""
Sets the state of the system LED
Args:
color: A string representing the color with which to set the
system LED
Returns:
bool: True if system LED state is set successfully, False if not
"""
raise NotImplementedError
def get_status_led(self):
"""
Gets the state of the system LED
Returns:
A string, one of the valid LED color strings which could be vendor
specified.
"""
raise NotImplementedError
##############################################
# System LED methods
##############################################
def set_uid_led(self, color):
"""
Sets the state of the system UID LED
Args:
color: A string representing the color with which to set the
system UID LED
Returns:
bool: True if system LED state is set successfully, False if not
"""
raise NotImplementedError
def get_uid_led(self):
"""
Gets the state of the system UID LED
Returns:
A string, one of the valid LED color strings which could be vendor
specified.
"""
raise NotImplementedError
##############################################
# Other methods
##############################################
def get_watchdog(self):
"""
Retreives hardware watchdog device on this chassis
Returns:
An object derived from WatchdogBase representing the hardware
watchdog device
"""
return self._watchdog
def get_eeprom(self):
"""
Retreives eeprom device on this chassis
Returns:
An object derived from WatchdogBase representing the hardware
eeprom device
"""
return self._eeprom
def get_change_event(self, timeout=0):
"""
Returns a nested dictionary containing all devices which have
experienced a change at chassis level
Args:
timeout: Timeout in milliseconds (optional). If timeout == 0,
this method will block until a change is detected.
Returns:
(bool, dict):
- True if call successful, False if not;
- A nested dictionary where key is a device type,
value is a dictionary with key:value pairs in the format of
{'device_id':'device_event'},
where device_id is the device ID for this device and
device_event,
status='1' represents device inserted,
status='0' represents device removed.
Ex. {'fan':{'0':'0', '2':'1'}, 'sfp':{'11':'0'}}
indicates that fan 0 has been removed, fan 2
has been inserted and sfp 11 has been removed.
Specifically for SFP event, besides SFP plug in and plug out,
there are some other error event could be raised from SFP, when
these error happened, SFP eeprom will not be avalaible, XCVRD shall
stop to read eeprom before SFP recovered from error status.
status='2' I2C bus stuck,
status='3' Bad eeprom,
status='4' Unsupported cable,
status='5' High Temperature,
status='6' Bad cable.
"""
raise NotImplementedError