forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sonic_platform_base] support new-platform-api-based daemons (sonic-n…
…et#48) [sonic_platform_base/chassis] 1. add _eeprom and get_eeprom into class ChassisBase so that syseepromd can access eeprom related stuff. 2. fix typo (non-asic characters) [sonic_platform_base/sonic_sfp/sfputilhelper] For xcvrd, originally we plan to remain the module sfputilbase to provide functions like mapping between logical and physical interfaces. However, SfpUtilBase is an abstract class and can not be instantiated. In that case, a new module sfputilhelper has to be introduced to provide the required interfaces. 1. read_porttab_mappings, which reads port_config.ini and generats mappings 2. get_physical_to_logical 3. get_logical_to_physical 4. is_logical_port [sonic_platform_base/sfp_base] support interface get_transceiver_threshold_status
- Loading branch information
Showing
3 changed files
with
191 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# sfputilbase.py | ||
# | ||
# Base class for creating platform-specific SFP transceiver interfaces for SONiC | ||
# | ||
|
||
from __future__ import print_function | ||
|
||
try: | ||
import abc | ||
import binascii | ||
import os | ||
import re | ||
except ImportError as e: | ||
raise ImportError("%s - required module not found" % str(e)) | ||
|
||
class SfpUtilHelper(object): | ||
# List to specify filter for sfp_ports | ||
# Needed by platforms like dni-6448 which | ||
# have only a subset of ports that support sfp | ||
sfp_ports = [] | ||
|
||
# List of logical port names available on a system | ||
""" ["swp1", "swp5", "swp6", "swp7", "swp8" ...] """ | ||
logical = [] | ||
|
||
# dicts for easier conversions between logical, physical and bcm ports | ||
logical_to_physical = {} | ||
|
||
physical_to_logical = {} | ||
physical_to_phyaddrs = {} | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def read_porttab_mappings(self, porttabfile): | ||
logical = [] | ||
logical_to_physical = {} | ||
physical_to_logical = {} | ||
last_fp_port_index = 0 | ||
last_portname = "" | ||
first = 1 | ||
port_pos_in_file = 0 | ||
parse_fmt_port_config_ini = False | ||
|
||
try: | ||
f = open(porttabfile) | ||
except: | ||
raise | ||
|
||
parse_fmt_port_config_ini = (os.path.basename(porttabfile) == "port_config.ini") | ||
|
||
# Read the porttab file and generate dicts | ||
# with mapping for future reference. | ||
# | ||
# TODO: Refactor this to use the portconfig.py module that now | ||
# exists as part of the sonic-config-engine package. | ||
title = [] | ||
for line in f: | ||
line.strip() | ||
if re.search("^#", line) is not None: | ||
# The current format is: # name lanes alias index speed | ||
# Where the ordering of the columns can vary | ||
title = line.split()[1:] | ||
continue | ||
|
||
# Parsing logic for 'port_config.ini' file | ||
if (parse_fmt_port_config_ini): | ||
# bcm_port is not explicitly listed in port_config.ini format | ||
# Currently we assume ports are listed in numerical order according to bcm_port | ||
# so we use the port's position in the file (zero-based) as bcm_port | ||
portname = line.split()[0] | ||
|
||
bcm_port = str(port_pos_in_file) | ||
|
||
if "index" in title: | ||
fp_port_index = int(line.split()[title.index("index")]) | ||
# Leave the old code for backward compatibility | ||
elif len(line.split()) >= 4: | ||
fp_port_index = int(line.split()[3]) | ||
else: | ||
fp_port_index = portname.split("Ethernet").pop() | ||
fp_port_index = int(fp_port_index.split("s").pop(0))/4 | ||
else: # Parsing logic for older 'portmap.ini' file | ||
(portname, bcm_port) = line.split("=")[1].split(",")[:2] | ||
|
||
fp_port_index = portname.split("Ethernet").pop() | ||
fp_port_index = int(fp_port_index.split("s").pop(0))/4 | ||
|
||
if ((len(self.sfp_ports) > 0) and (fp_port_index not in self.sfp_ports)): | ||
continue | ||
|
||
if first == 1: | ||
# Initialize last_[physical|logical]_port | ||
# to the first valid port | ||
last_fp_port_index = fp_port_index | ||
last_portname = portname | ||
first = 0 | ||
|
||
logical.append(portname) | ||
|
||
logical_to_physical[portname] = [fp_port_index] | ||
if physical_to_logical.get(fp_port_index) is None: | ||
physical_to_logical[fp_port_index] = [portname] | ||
else: | ||
physical_to_logical[fp_port_index].append( | ||
portname) | ||
|
||
last_fp_port_index = fp_port_index | ||
last_portname = portname | ||
|
||
port_pos_in_file += 1 | ||
|
||
self.logical = logical | ||
self.logical_to_physical = logical_to_physical | ||
self.physical_to_logical = physical_to_logical | ||
|
||
""" | ||
print("logical: " + self.logical) | ||
print("logical to physical: " + self.logical_to_physical) | ||
print("physical to logical: " + self.physical_to_logical) | ||
""" | ||
|
||
def get_physical_to_logical(self, port_num): | ||
"""Returns list of logical ports for the given physical port""" | ||
|
||
return self.physical_to_logical[port_num] | ||
|
||
def get_logical_to_physical(self, logical_port): | ||
"""Returns list of physical ports for the given logical port""" | ||
|
||
return self.logical_to_physical[logical_port] | ||
|
||
def is_logical_port(self, port): | ||
if port in self.logical: | ||
return 1 | ||
else: | ||
return 0 |