Skip to content

Commit be04b80

Browse files
authored
[multiasic][sfputil]Fix the sftpuitlhelper on mutilasic platform issue (sonic-net#286)
Signed-off-by: mlok <[email protected]>
1 parent 04b08ba commit be04b80

File tree

8 files changed

+308
-51
lines changed

8 files changed

+308
-51
lines changed

sonic_platform_base/sonic_sfp/bcmshell.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def getreg(self, reg, fields=False):
227227
#
228228
t = self.re_oneline.sub('', t)
229229
t = t.split('\n')
230-
if t[-1] is '':
230+
if t[-1] == '':
231231
t.pop()
232232

233233
# get the results into a dict (module) of lists (array) of values/fields
@@ -253,10 +253,10 @@ def __parse_reg__(text, fields=False):
253253
# now optimize the return
254254
#
255255
for I in iter(d):
256-
if len(d[I]) is 1:
256+
if len(d[I]) == 1:
257257
d[I] = d[I][0]
258258

259-
if len(d) is 1:
259+
if len(d) == 1:
260260
return d.values()[0]
261261
else:
262262
return d
@@ -319,7 +319,7 @@ def gettable(self, table, fields=False, start=None, entries=None):
319319
t = self.re_table_header.sub('', t)
320320
t = self.re_table_trailer.sub('', t)
321321
t = t.split('\n')
322-
if t[-1] is '':
322+
if t[-1] == '':
323323
t.pop()
324324

325325
# parse the contents

sonic_platform_base/sonic_sfp/sfputilhelper.py

+24-17
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from natsort import natsorted
1515
from portconfig import get_port_config
16-
from sonic_py_common import device_info
16+
from sonic_py_common import device_info, multi_asic
1717
from sonic_py_common.interface import backplane_prefix, inband_prefix, recirc_prefix
1818

1919
except ImportError as e:
@@ -22,6 +22,7 @@
2222
# Global Variable
2323
PLATFORM_JSON = 'platform.json'
2424
PORT_CONFIG_INI = 'port_config.ini'
25+
ASIC_NAME_PREFIX = 'asic'
2526

2627
class SfpUtilHelper(object):
2728
# List to specify filter for sfp_ports
@@ -52,7 +53,12 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0):
5253
fp_port_index = 1
5354

5455
(platform, hwsku) = device_info.get_platform_and_hwsku()
55-
ports, _, _ = get_port_config(hwsku, platform)
56+
57+
asic_name = None
58+
if multi_asic.is_multi_asic():
59+
asic_name = ASIC_NAME_PREFIX + str(asic_inst)
60+
61+
ports, _, _ = get_port_config(hwsku, platform, asic_name=asic_name)
5662

5763
if not ports:
5864
ports, _, _ = get_port_config(hwsku, platform, porttabfile)
@@ -65,9 +71,9 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0):
6571
logical_list.append(intf)
6672

6773
# Ignore if this is an internal backplane interface and Inband interface
68-
logical = [name for name in logical
74+
logical = [name for name in logical_list
6975
if not name.startswith((backplane_prefix(), inband_prefix(), recirc_prefix()))]
70-
logical = natsorted(logical_list, key=lambda y: y.lower())
76+
logical = natsorted(logical, key=lambda y: y.lower())
7177
logical_to_physical, physical_to_logical = OrderedDict(), OrderedDict()
7278

7379
for intf_name in logical:
@@ -83,24 +89,25 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0):
8389
# Mapping of logical port names available on a system to ASIC instance
8490
self.logical_to_asic[intf_name] = asic_inst
8591

86-
self.logical = logical
87-
self.logical_to_physical = logical_to_physical
88-
self.physical_to_logical = physical_to_logical
92+
self.logical.extend(logical)
93+
self.logical = list(set(self.logical))
94+
self.logical_to_physical.update(logical_to_physical)
95+
self.physical_to_logical.update(physical_to_logical)
8996

9097
return None
9198

9299

93100
def read_all_porttab_mappings(self, platform_dir, num_asic_inst):
94-
# In multi asic scenario, get all the port_config files for different asics
95-
for inst in range(num_asic_inst):
96-
port_map_dir = os.path.join(platform_dir, str(inst))
97-
port_map_file = os.path.join(port_map_dir, PORT_CONFIG_INI)
98-
if os.path.exists(port_map_file):
99-
self.read_porttab_mappings(port_map_file, inst)
100-
else:
101-
port_json_file = os.path.join(port_map_dir, PLATFORM_JSON)
102-
if os.path.exists(port_json_file):
103-
self.read_porttab_mappings(port_json_file, inst)
101+
# In multi asic scenario, get all the port_config files for different asic
102+
for inst in range(num_asic_inst):
103+
port_map_dir = os.path.join(platform_dir, str(inst))
104+
port_map_file = os.path.join(port_map_dir, PORT_CONFIG_INI)
105+
if os.path.exists(port_map_file):
106+
self.read_porttab_mappings(port_map_file, inst)
107+
else:
108+
port_json_file = os.path.join(platform_dir, PLATFORM_JSON)
109+
if os.path.exists(port_json_file):
110+
self.read_porttab_mappings(port_json_file, inst)
104111

105112
def get_physical_to_logical(self, port_num):
106113
"""Returns list of logical ports for the given physical port"""

tests/0/port_config.ini

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# name lanes alias index
2+
Ethernet0 29,30,31,32 fortyGigE0/0 1
3+
Ethernet4 25,26,27,28 fortyGigE0/4 2
4+
Ethernet8 37,38,39,40 fortyGigE0/8 3
5+
Ethernet12 33,34,35,36 fortyGigE0/12 4
6+
Ethernet16 41,42,43,44 fortyGigE0/16 5
7+
Ethernet20 45,46,47,48 fortyGigE0/20 6

tests/1/port_config.ini

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# name lanes alias index
2+
Ethernet24 5,6,7,8 fortyGigE0/24 7
3+
Ethernet28 1,2,3,4 fortyGigE0/28 8
4+
Ethernet32 9,10,11,12 fortyGigE0/32 9
5+
Ethernet36 13,14,15,16 fortyGigE0/36 10
6+
Ethernet40 21,22,23,24 fortyGigE0/40 11
7+
Ethernet44 17,18,19,20 fortyGigE0/44 12
8+
Ethernet48 49,50,51,52 fortyGigE0/48 13

tests/platform_json/hwsku.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"interfaces": {
3+
"Ethernet0": {
4+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
5+
},
6+
"Ethernet4": {
7+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
8+
},
9+
"Ethernet8": {
10+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
11+
},
12+
"Ethernet12": {
13+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
14+
},
15+
"Ethernet16": {
16+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
17+
},
18+
"Ethernet20": {
19+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
20+
},
21+
"Ethernet24": {
22+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
23+
},
24+
"Ethernet28": {
25+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
26+
},
27+
"Ethernet32": {
28+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
29+
},
30+
"Ethernet36": {
31+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
32+
},
33+
"Ethernet40": {
34+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
35+
},
36+
"Ethernet44": {
37+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
38+
},
39+
"Ethernet48": {
40+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
41+
},
42+
"Ethernet52": {
43+
"default_brkout_mode": "1x200G[100G,50G,40G,25G,10G,1G]"
44+
}
45+
}
46+
}

tests/platform_json/platform.json

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"chassis": {
3+
"name": "",
4+
"components": [],
5+
"fans": [],
6+
"fan_drawers": [],
7+
"psus": [],
8+
"thermals": [],
9+
"sfps": []
10+
},
11+
"interfaces": {
12+
"Ethernet0": {
13+
"index": "1,1,1,1",
14+
"lanes": "29,30,31,32",
15+
"breakout_modes": {
16+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp1"],
17+
"2x100G[50G,25G,10G,1G]": ["etp1a", "etp1b"]
18+
}
19+
},
20+
"Ethernet4": {
21+
"index": "2,2,2,2",
22+
"lanes": "25,26,27,28",
23+
"breakout_modes": {
24+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp2"],
25+
"2x100G[50G,25G,10G,1G]": ["etp2a", "etp2b"]
26+
}
27+
},
28+
"Ethernet8": {
29+
"index": "3,3,3,3",
30+
"lanes": "37,38,39,40",
31+
"breakout_modes": {
32+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp3"],
33+
"2x100G[50G,25G,10G,1G]": ["etp3a", "etp3b"]
34+
}
35+
},
36+
"Ethernet12": {
37+
"index": "4,4,4,4",
38+
"lanes": "33,34,35,36",
39+
"breakout_modes": {
40+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp4"],
41+
"2x100G[50G,25G,10G,1G]": ["etp4a", "etp4b"]
42+
}
43+
},
44+
"Ethernet16": {
45+
"index": "5,5,5,5",
46+
"lanes": "41,42,43,44",
47+
"breakout_modes": {
48+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp5"],
49+
"2x100G[50G,25G,10G,1G]": ["etp5a", "etp5b"]
50+
}
51+
},
52+
"Ethernet20": {
53+
"index": "6,6,6,6",
54+
"lanes": "44,46,47,48",
55+
"breakout_modes": {
56+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp6"],
57+
"2x100G[50G,25G,10G,1G]": ["etp6a", "etp6b"]
58+
}
59+
},
60+
"Ethernet24": {
61+
"index": "7,7,7,7",
62+
"lanes": "5,6,7,8",
63+
"breakout_modes": {
64+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp7"],
65+
"2x100G[50G,25G,10G,1G]": ["etp7a", "etp7b"]
66+
}
67+
},
68+
"Ethernet28": {
69+
"index": "8,8,8,8",
70+
"lanes": "1,2,3,4",
71+
"breakout_modes": {
72+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp8"],
73+
"2x100G[50G,25G,10G,1G]": ["etp8a", "etp8b"]
74+
}
75+
},
76+
"Ethernet32": {
77+
"index": "9,9,9,9",
78+
"lanes": "9,10,11,12",
79+
"breakout_modes": {
80+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp9"],
81+
"2x100G[50G,25G,10G,1G]": ["etp9a", "etp9b"]
82+
}
83+
},
84+
"Ethernet36": {
85+
"index": "10,10,10,10",
86+
"lanes": "13,14,15,16",
87+
"breakout_modes": {
88+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp10"],
89+
"2x100G[50G,25G,10G,1G]": ["etp10a", "etp10b"]
90+
}
91+
},
92+
"Ethernet40": {
93+
"index": "11,11,11,11",
94+
"lanes": "21,22,23,24",
95+
"breakout_modes": {
96+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp11"],
97+
"2x100G[50G,25G,10G,1G]": ["etp11a", "etp11b"]
98+
}
99+
},
100+
"Ethernet44": {
101+
"index": "12,12,12,12",
102+
"lanes": "17,18,19,20",
103+
"breakout_modes": {
104+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp12"],
105+
"2x100G[50G,25G,10G,1G]": ["etp12a", "etp12b"]
106+
}
107+
},
108+
"Ethernet48": {
109+
"index": "13,13,13,13",
110+
"lanes": "49,50,51,51",
111+
"breakout_modes": {
112+
"1x200G[100G,50G,40G,25G,10G,1G]": ["etp13"],
113+
"2x100G[50G,25G,10G,1G]": ["etp13a", "etp13b"]
114+
}
115+
}
116+
}
117+
}

tests/port_config.ini

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# name lanes alias
2-
Ethernet0 29,30,31,32 fortyGigE0/0
3-
Ethernet4 25,26,27,28 fortyGigE0/4
4-
Ethernet8 37,38,39,40 fortyGigE0/8
5-
Ethernet12 33,34,35,36 fortyGigE0/12
6-
Ethernet16 41,42,43,44 fortyGigE0/16
7-
Ethernet20 45,46,47,48 fortyGigE0/20
8-
Ethernet24 5,6,7,8 fortyGigE0/24
9-
Ethernet28 1,2,3,4 fortyGigE0/28
10-
Ethernet32 9,10,11,12 fortyGigE0/32
11-
Ethernet36 13,14,15,16 fortyGigE0/36
12-
Ethernet40 21,22,23,24 fortyGigE0/40
13-
Ethernet44 17,18,19,20 fortyGigE0/44
14-
Ethernet48 49,50,51,52 fortyGigE0/48
1+
# name lanes alias index
2+
Ethernet0 29,30,31,32 fortyGigE0/0 1
3+
Ethernet4 25,26,27,28 fortyGigE0/4 2
4+
Ethernet8 37,38,39,40 fortyGigE0/8 3
5+
Ethernet12 33,34,35,36 fortyGigE0/12 4
6+
Ethernet16 41,42,43,44 fortyGigE0/16 5
7+
Ethernet20 45,46,47,48 fortyGigE0/20 6
8+
Ethernet24 5,6,7,8 fortyGigE0/24 7
9+
Ethernet28 1,2,3,4 fortyGigE0/28 8
10+
Ethernet32 9,10,11,12 fortyGigE0/32 9
11+
Ethernet36 13,14,15,16 fortyGigE0/36 10
12+
Ethernet40 21,22,23,24 fortyGigE0/40 11
13+
Ethernet44 17,18,19,20 fortyGigE0/44 12
14+
Ethernet48 49,50,51,52 fortyGigE0/48 13

0 commit comments

Comments
 (0)