Skip to content

Commit

Permalink
[bug fix]: support to use bcm mdio to get sfp eeprom data (sonic-net#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
lguohan authored Mar 17, 2017
1 parent dea6e80 commit 22b3d7a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions sonic_sfp/bcmshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class bcmshell (object):
#---------------
#
def __init__(self, keepopen=False, timeout=10, opennow=False, logfileobj=None,
socketname="/var/run/sswsyncd.socket", prompt='^drivshell>\s*$'):
socketname="/var/run/docker-syncd/sswsyncd.socket", prompt='^drivshell>\s*$'):
"""Constructor:
keepopen - indicates that switchd socket should be kept open between
Expand All @@ -54,7 +54,7 @@ def __init__(self, keepopen=False, timeout=10, opennow=False, logfileobj=None,
raise SyntaxError("bcmshell constructor prompt expects an re string")
else:
self.re_prompt = re.compile(prompt, re.MULTILINE)
self.re_connectprompt = re.compile("bcmshell\r\n\r\r\n" + prompt, re.MULTILINE)
self.re_connectprompt = re.compile("bcmshell\r\n" + prompt, re.MULTILINE)

if timeout <= 0:
raise ValueError("bcmshell.timeout must be > 0")
Expand Down
28 changes: 23 additions & 5 deletions sonic_sfp/sfputilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _read_eeprom_devid(self, port_num, devid, offset):
i2c_adapter_id = self._get_port_i2c_adapter_id(port_num)
if i2c_adapter_id == None:
print 'Error getting i2c bus num'
return Non
return None

# Get i2c virtual bus path for the sfp
sysfs_sfp_i2c_adapter_path = sysfs_i2c_adapter_base_path + \
Expand Down Expand Up @@ -323,12 +323,16 @@ def read_porttab_mappings(cls, porttabfile):
last_physical_port = 0
last_logical_port = ''
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.
# XXX: move the porttab
Expand All @@ -338,11 +342,23 @@ def read_porttab_mappings(cls, porttabfile):
line.strip()
if re.search('^#', line) != None:
continue
logical_port = line.split()[0]
bcm_port = line.split()[1].split(',')[0]

physical_port = logical_port.split('Ethernet').pop()
physical_port = int(physical_port.split('s').pop(0))/4
# 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
logical_port = line.split()[0]

bcm_port = str(port_pos_in_file);

physical_port = logical_port.split('Ethernet').pop()
physical_port = int(physical_port.split('s').pop(0))/4
else: # Parsing logic for older 'portmap.ini' file
(logical_port, bcm_port) = line.split('=')[1].split(',')[:2]

physical_port = logical_port.split('Ethernet').pop()
physical_port = int(physical_port.split('s').pop(0))/4

if ((len(cls.sfp_ports) > 0) and
(physical_port not in cls.sfp_ports)):
Expand Down Expand Up @@ -379,6 +395,8 @@ def read_porttab_mappings(cls, porttabfile):
last_physical_port = physical_port
last_logical_port = logical_port

port_pos_in_file += 1

sfputilbase.logical = logical
sfputilbase.logical_to_bcm = logical_to_bcm
sfputilbase.logical_to_physical = logical_to_physical
Expand Down

0 comments on commit 22b3d7a

Please sign in to comment.