#!/usr/bin/env python # sfputil.py # # Platform-specific SFP transceiver interface for SONiC # try: import time import os import logging import struct import syslog from socket import * from select import * from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: raise ImportError("%s - required module not found" % str(e)) def DBG_PRINT(str): print str + "\n" class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" SONIC_PORT_NAME_PREFIX = "Ethernet" PORT_START = 1 PORT_END = 54 PORTS_IN_BLOCK = 54 @property def port_start(self): return self.PORT_START @property def port_end(self): return self.PORT_END @property def qsfp_ports(self): return range(49, self.PORTS_IN_BLOCK + 1) @property def port_to_eeprom_mapping(self): return self.eeprom_mapping def is_logical_port(self, port_name): return True def get_logical_to_physical(self, port_name): if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX): return None port_idx = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):]) return [port_idx] def get_eeprom_data(self, port): (ctlid, devid) = self.fiber_mapping[port] offset = (128 if port in self.qsfp_ports else 0) r_sel = [self.udpClient] req = struct.pack('=HHHBBHIBBBBI', 0, 9, 16, # lchip/msgtype/msglen ctlid, # uint8 ctl_id devid, # uint8 slave_dev_id 0x50, # uint16 dev_addr (1< self.port_end: return False try: with open(self.f_sfp_present.format(port_num), 'r') as sfp_file: return 1 == int(sfp_file.read()) except IOError as e: DBG_PRINT(str(e)) return False def get_low_power_mode(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False return False def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False return False def reset(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False return False def get_transceiver_change_event(self, timeout=0): return False, {}