Skip to content

Commit

Permalink
[sfputilbase | sfputilhelper] Add support of platform.json (sonic-net#72
Browse files Browse the repository at this point in the history
)

Signed-off-by: Sangita Maity <sangitamaity0211@gmail.com>
  • Loading branch information
samaity authored May 29, 2020
1 parent 6e52993 commit 4040326
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 9 deletions.
61 changes: 57 additions & 4 deletions sonic_platform_base/sonic_sfp/sfputilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@
from .sff8436 import sff8436InterfaceId # Dot module supports both Python 2 and Python 3 using explicit relative import methods
from .sff8436 import sff8436Dom # Dot module supports both Python 2 and Python 3 using explicit relative import methods
from .inf8628 import inf8628InterfaceId # Dot module supports both Python 2 and Python 3 using explicit relative import methods
from portconfig import get_port_config
from collections import OrderedDict
from natsort import natsorted
from sonic_daemon_base.daemon_base import DaemonBase
import sys
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))

# Global Variable
PLATFORM_JSON = 'platform.json'
PORT_CONFIG_INI = 'portconfig.ini'

# definitions of the offset and width for values in XCVR info eeprom
XCVR_INTFACE_BULK_OFFSET = 0
XCVR_INTFACE_BULK_WIDTH_QSFP = 20
Expand Down Expand Up @@ -370,14 +379,59 @@ def read_porttab_mappings(self, porttabfile):
first = 1
port_pos_in_file = 0
parse_fmt_port_config_ini = False
parse_fmt_platform_json = False

parse_fmt_port_config_ini = (os.path.basename(porttabfile) == PORT_CONFIG_INI)
parse_fmt_platform_json = (os.path.basename(porttabfile) == PLATFORM_JSON)

(platform, hwsku) = DaemonBase().get_platform_and_hwsku()
if(parse_fmt_platform_json):
ports, _ = get_port_config(hwsku, platform)
if not ports:
print('Failed to get port config', file=sys.stderr)
sys.exit(1)
else:
logical_list = []
for intf in ports.keys():
logical_list.append(intf)

logical = natsorted(logical_list, key=lambda y: y.lower())
logical_to_bcm, logical_to_physical, physical_to_logical = OrderedDict(), OrderedDict(), OrderedDict()

for intf_name in logical:
bcm_port = str(port_pos_in_file)
logical_to_bcm[intf_name] = "xe"+ bcm_port

if 'index' in ports[intf_name].keys():
fp_port_index = ports[intf_name]['index']
logical_to_physical[intf_name] = [fp_port_index]

if physical_to_logical.get(fp_port_index) is None:
physical_to_logical[fp_port_index] = [intf_name]
else:
physical_to_logical[fp_port_index].append(intf_name)

port_pos_in_file +=1

self.logical = logical
self.logical_to_bcm = logical_to_bcm
self.logical_to_physical = logical_to_physical
self.physical_to_logical = physical_to_logical

"""
print("logical: {}".format(self.logical))
print("logical to bcm: {}".format(self.logical_to_bcm))
print("logical to physical: {}".format(self.logical_to_physical))
print("physical to logical: {}".format( self.physical_to_logical))
"""
return None


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.
#
Expand Down Expand Up @@ -432,8 +486,7 @@ def read_porttab_mappings(self, porttabfile):
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)
physical_to_logical[fp_port_index].append(portname)

last_fp_port_index = fp_port_index
last_portname = portname
Expand Down
59 changes: 54 additions & 5 deletions sonic_platform_base/sonic_sfp/sfputilhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@
import binascii
import os
import re
from portconfig import get_port_config
from collections import OrderedDict
from natsort import natsorted
from sonic_daemon_base.daemon_base import DaemonBase
import sys
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))

# Global Variable
PLATFORM_JSON = 'platform.json'
PORT_CONFIG_INI = 'portconfig.ini'

class SfpUtilHelper(object):
# List to specify filter for sfp_ports
# Needed by platforms like dni-6448 which
Expand Down Expand Up @@ -41,14 +50,56 @@ def read_porttab_mappings(self, porttabfile):
first = 1
port_pos_in_file = 0
parse_fmt_port_config_ini = False
parse_fmt_platform_json = False

parse_fmt_port_config_ini = (os.path.basename(porttabfile) == PORT_CONFIG_INI)
parse_fmt_platform_json = (os.path.basename(porttabfile) == PLATFORM_JSON)

(platform, hwsku) = DaemonBase().get_platform_and_hwsku()
if(parse_fmt_platform_json):
ports, _ = get_port_config(hwsku, platform)
if not ports:
print('Failed to get port config', file=sys.stderr)
sys.exit(1)
else:
logical_list = []
for intf in ports.keys():
logical_list.append(intf)

logical = natsorted(logical_list, key=lambda y: y.lower())
logical_to_physical, physical_to_logical = OrderedDict(), OrderedDict()

for intf_name in logical:
bcm_port = str(port_pos_in_file)

if 'index' in ports[intf_name].keys():
fp_port_index = ports[intf_name]['index']
logical_to_physical[intf_name] = [fp_port_index]

if physical_to_logical.get(fp_port_index) is None:
physical_to_logical[fp_port_index] = [intf_name]
else:
physical_to_logical[fp_port_index].append(intf_name)

port_pos_in_file +=1

self.logical = logical
self.logical_to_physical = logical_to_physical
self.physical_to_logical = physical_to_logical

"""
print("logical: {}".format(self.logical))
print("logical to physical: {}".format(self.logical_to_physical))
print("physical to logical: {}".format( self.physical_to_logical))
"""
return None


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.
#
Expand Down Expand Up @@ -102,8 +153,7 @@ def read_porttab_mappings(self, porttabfile):
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)
physical_to_logical[fp_port_index].append(portname)

last_fp_port_index = fp_port_index
last_portname = portname
Expand All @@ -119,7 +169,6 @@ def read_porttab_mappings(self, porttabfile):
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"""

Expand Down

0 comments on commit 4040326

Please sign in to comment.