Skip to content

Commit 5d8f98e

Browse files
authored
[sfputil]: Use front panel index in port_config.ini to locate the front panel port (sonic-net#77)
allow flexible mapping between front panel port name and index
1 parent 7ab269a commit 5d8f98e

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

sonic_sfp/sfputilbase.py

+29-26
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ def read_porttab_mappings(cls, porttabfile):
320320
logical_to_bcm = {}
321321
logical_to_physical = {}
322322
physical_to_logical = {}
323-
last_physical_port = 0
324-
last_logical_port = ''
323+
last_fp_port_index = 0
324+
last_portname = ''
325325
first = 1
326326
port_pos_in_file = 0
327327
parse_fmt_port_config_ini = False
@@ -348,52 +348,55 @@ def read_porttab_mappings(cls, porttabfile):
348348
# bcm_port is not explicitly listed in port_config.ini format
349349
# Currently we assume ports are listed in numerical order according to bcm_port
350350
# so we use the port's position in the file (zero-based) as bcm_port
351-
logical_port = line.split()[0]
351+
portname = line.split()[0]
352352

353353
bcm_port = str(port_pos_in_file);
354354

355-
physical_port = logical_port.split('Ethernet').pop()
356-
physical_port = int(physical_port.split('s').pop(0))/4
355+
if len(line.split()) == 4:
356+
fp_port_index = int(line.split()[3])
357+
else:
358+
fp_port_index = portname.split('Ethernet').pop()
359+
fp_port_index = int(fp_port_index.split('s').pop(0))/4
357360
else: # Parsing logic for older 'portmap.ini' file
358-
(logical_port, bcm_port) = line.split('=')[1].split(',')[:2]
361+
(portname, bcm_port) = line.split('=')[1].split(',')[:2]
359362

360-
physical_port = logical_port.split('Ethernet').pop()
361-
physical_port = int(physical_port.split('s').pop(0))/4
363+
fp_port_index = portname.split('Ethernet').pop()
364+
fp_port_index = int(fp_port_index.split('s').pop(0))/4
362365

363366
if ((len(cls.sfp_ports) > 0) and
364-
(physical_port not in cls.sfp_ports)):
367+
(fp_port_index not in cls.sfp_ports)):
365368
continue
366369

367370
if first == 1:
368371
# Initialize last_[physical|logical]_port
369372
# to the first valid port
370-
last_physical_port = physical_port
371-
last_logical_port = logical_port
373+
last_fp_port_index = fp_port_index
374+
last_portname = portname
372375
first = 0
373376

374-
logical.append(logical_port)
377+
logical.append(portname)
375378

376-
logical_to_bcm[logical_port] = 'xe' + bcm_port
377-
logical_to_physical[logical_port] = [physical_port]
378-
if physical_to_logical.get(physical_port) == None:
379-
physical_to_logical[physical_port] = [logical_port]
379+
logical_to_bcm[portname] = 'xe' + bcm_port
380+
logical_to_physical[portname] = [fp_port_index]
381+
if physical_to_logical.get(fp_port_index) == None:
382+
physical_to_logical[fp_port_index] = [portname]
380383
else:
381-
physical_to_logical[physical_port].append(
382-
logical_port)
384+
physical_to_logical[fp_port_index].append(
385+
portname)
383386

384-
if (physical_port - last_physical_port) > 1:
387+
if (fp_port_index - last_fp_port_index) > 1:
385388
# last port was a gang port
386-
for p in range (last_physical_port+1,
387-
physical_port):
388-
logical_to_physical[last_logical_port].append(p)
389+
for p in range (last_fp_port_index+1,
390+
fp_port_index):
391+
logical_to_physical[last_portname].append(p)
389392
if physical_to_logical.get(p) == None:
390-
physical_to_logical[p] = [last_logical_port]
393+
physical_to_logical[p] = [last_portname]
391394
else:
392395
physical_to_logical[p].append(
393-
last_logical_port)
396+
last_portname)
394397

395-
last_physical_port = physical_port
396-
last_logical_port = logical_port
398+
last_fp_port_index = fp_port_index
399+
last_portname = portname
397400

398401
port_pos_in_file += 1
399402

0 commit comments

Comments
 (0)