2019-08-15 02:50:13 -05:00
|
|
|
# led_control.py
|
|
|
|
#
|
|
|
|
# Platform-specific LED control functionality for SONiC
|
|
|
|
#
|
|
|
|
|
|
|
|
try:
|
|
|
|
from sonic_led.led_control_base import LedControlBase
|
|
|
|
import swsssdk
|
|
|
|
import threading
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
import struct
|
|
|
|
import time
|
|
|
|
import syslog
|
|
|
|
from socket import *
|
|
|
|
from select import *
|
|
|
|
from minipack.pimutil import PimUtil
|
2020-11-25 12:28:36 -06:00
|
|
|
except ImportError as e:
|
2019-08-15 02:50:13 -05:00
|
|
|
raise ImportError(str(e) + " - required module not found")
|
|
|
|
|
|
|
|
|
|
|
|
class LedControl(LedControlBase):
|
|
|
|
"""Platform specific LED control class"""
|
|
|
|
SONIC_PORT_NAME_PREFIX = "Ethernet"
|
2020-11-25 12:28:36 -06:00
|
|
|
|
2019-08-15 02:50:13 -05:00
|
|
|
def __init__(self):
|
2020-11-25 12:28:36 -06:00
|
|
|
pim = PimUtil()
|
2019-08-15 02:50:13 -05:00
|
|
|
pim.init_pim_fpga()
|
2020-11-25 12:28:36 -06:00
|
|
|
|
2019-08-15 02:50:13 -05:00
|
|
|
def _port_name_to_index(self, port_name):
|
|
|
|
# Strip "Ethernet" off port name
|
|
|
|
if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX):
|
|
|
|
return -1
|
|
|
|
|
|
|
|
port_idx = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):])
|
|
|
|
return port_idx
|
2020-11-25 12:28:36 -06:00
|
|
|
|
2019-08-15 02:50:13 -05:00
|
|
|
def _port_state_to_mode(self, port_idx, state):
|
|
|
|
if state == "up":
|
2020-11-25 12:28:36 -06:00
|
|
|
return 1, 4 # port linkup, led is green
|
2019-08-15 02:50:13 -05:00
|
|
|
else:
|
2020-11-25 12:28:36 -06:00
|
|
|
return 0, 0 # port linkdown, led is off
|
2019-08-15 02:50:13 -05:00
|
|
|
|
|
|
|
def port_link_state_change(self, portname, state):
|
2020-11-25 12:28:36 -06:00
|
|
|
pim = PimUtil()
|
2019-08-15 02:50:13 -05:00
|
|
|
port_idx = self._port_name_to_index(portname)
|
|
|
|
new_control, led_mode = self._port_state_to_mode(port_idx, state)
|
2020-11-25 12:28:36 -06:00
|
|
|
color, control = pim.get_port_led(port_idx)
|
|
|
|
|
|
|
|
if color == led_mode:
|
|
|
|
if control == new_control:
|
2019-08-15 02:50:13 -05:00
|
|
|
return
|
|
|
|
|
2020-11-25 12:28:36 -06:00
|
|
|
pim.set_port_led(port_idx, led_mode, new_control) # port linkup, led is green
|
|
|
|
# port linkdown, led is off
|