Skip to content

Commit e555ea9

Browse files
[SKU creator] fix wrong speed in case breakout of 2x50 (sonic-net#1380)
**- What I did** I fixed the port split feature of SKU creator tool. **- How I did it** When trying to use port split feature of SKU creator tool to split a port in port_config.ini and config_db.json. It was not working, I fixed. **- How to verify it** With this fix, we should be able to split and unsplit a port in port_config.ini and config_db.json **- Previous command output (if the output of a command-line utility has changed)** No changes to CLI commands **- New command output (if the output of a command-line utility has changed)** No changes to CLI commands
1 parent 4a78c01 commit e555ea9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+17928
-737
lines changed

scripts/sonic_sku_create.py

+72-28
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"1x1": { "lanes":4, "speed":1000, "step":4, "bko":0, "name": "etp" },
5757
"4x10": { "lanes":4, "speed":10000, "step":1, "bko":1, "name": "etp" },
5858
"4x25": { "lanes":4, "speed":25000, "step":1, "bko":1, "name": "etp" },
59-
"2x50": { "lanes":4, "speed":25000, "step":2, "bko":1, "name": "etp" },
59+
"2x50": { "lanes":4, "speed":50000, "step":2, "bko":1, "name": "etp" },
6060
}
6161

6262
bko_dict_8 = {
@@ -218,7 +218,7 @@ def check_json_lanes_with_bko(self, data, port_idx):
218218
return entry
219219
return None
220220

221-
def write_json_lanes_to_ini_file(self, data, port_idx, port_split, f_out):
221+
def write_json_lanes_to_pi_list(self, data, port_idx, port_split, pi_list):
222222
# Function to write line of port_config.ini corresponding to a port
223223
step = self.bko_dict[port_split]["step"]
224224
for i in range(0,self.base_lanes,step):
@@ -227,18 +227,14 @@ def write_json_lanes_to_ini_file(self, data, port_idx, port_split, f_out):
227227
curr_speed = curr_port_dict.get("speed")
228228
curr_alias = curr_port_dict.get("alias")
229229
curr_lanes = curr_port_dict.get("lanes")
230-
curr_index = port_idx/self.base_lanes
231-
out_str = "{:15s} {:20s} {:11s} {:9s} {:10s}\n".format(curr_port_str,curr_lanes,curr_alias,str(curr_index),str(curr_speed))
232-
if self.print_mode == True:
233-
print(out_str)
234-
else:
235-
f_out.write(out_str)
236-
if self.verbose and (self.print_mode == False):
237-
print(out_str)
230+
curr_index = int(port_idx/self.base_lanes) + 1
231+
curr_port_info = [curr_port_str, curr_lanes, curr_alias, curr_index, curr_speed]
232+
pi_list.append(curr_port_info)
238233
return
239234

240235
def json_file_parser(self, json_file):
241236
# Function to generate SKU file from config_db.json file by extracting port related information from the config_db.json file
237+
pi_list = []
242238
with open(json_file) as f:
243239
data = json.load(f,object_pairs_hook=OrderedDict)
244240
meta_dict = data['DEVICE_METADATA']['localhost']
@@ -254,6 +250,9 @@ def json_file_parser(self, json_file):
254250
f_out = open(new_file, 'w')
255251
header_str = "#name lanes alias index speed\n"
256252
f_out.write(header_str)
253+
254+
# data['PORT'] is already an OrderedDict, we can not sort it, so we create
255+
# pi_list - list of port info items and then sort it
257256
for key, value in data['PORT'].items():
258257
pattern = '^Ethernet([0-9]{1,})'
259258
m = re.match(pattern,key)
@@ -265,16 +264,40 @@ def json_file_parser(self, json_file):
265264
if port_idx%self.base_lanes == 0:
266265
result = self.check_json_lanes_with_bko(data, port_idx)
267266
if result != None:
268-
self.write_json_lanes_to_ini_file(data,port_idx,result,f_out)
267+
self.write_json_lanes_to_pi_list(data, port_idx, result, pi_list)
269268
else:
270269
continue
270+
271+
pi_list.sort(key=lambda x: (int(re.search(('^Ethernet([0-9]{1,})'),x[0]).group(1)))) # sort the list with interface name
272+
273+
for port_info in pi_list:
274+
out_str = "{:15s} {:20s} {:11s} {:9s} {:10s}\n".format(port_info[0],port_info[1],port_info[2],str(port_info[3]),str(port_info[4]))
275+
if self.print_mode == True:
276+
print(out_str)
277+
else:
278+
f_out.write(out_str)
279+
if self.verbose and (self.print_mode == False):
280+
print(out_str)
271281
f_out.close()
272282
self.port_config_split_analyze(self.ini_file)
273283
self.form_port_config_dict_from_ini(self.ini_file)
274284
self.platform_specific()
275285
shutil.copy(new_file,self.ini_file)
276286
return
277287

288+
def parse_platform_from_config_db_file(self, config_file):
289+
with open(config_file) as f:
290+
data = json.load(f,object_pairs_hook=OrderedDict)
291+
meta_dict = data['DEVICE_METADATA']['localhost']
292+
platform = meta_dict.get("platform")
293+
pattern = '^x86_64-mlnx_msn([0-9]{1,}[a-zA-Z]?)-r0'
294+
m = re.match(pattern,platform)
295+
if m is None:
296+
print("Platform Name ", platform, " is not valid, Exiting...", file=sys.stderr)
297+
exit(1)
298+
self.platform = platform
299+
300+
278301
def port_config_split_analyze(self, ini_file):
279302
#Internal function to populate fpp_split tuple with from a port information
280303
new_file = ini_file + ".new"
@@ -398,16 +421,16 @@ def break_in_ini(self, ini_file, port_name, port_split):
398421

399422
#find split partition
400423
for i in range(0,base_lanes,step):
401-
port_str = "Ethernet{:d}".format(line_port_index + i/step)
402-
lanes_str = "{:d}".format(lane_index + i/step)
424+
port_str = "Ethernet{:d}".format(line_port_index + i)
425+
lanes_str = "{:d}".format(lane_index + i)
403426
if step > 1:
404427
for j in range(1,step):
405-
lanes_str += ",{:d}".format(lane_index + j)
428+
lanes_str += ",{:d}".format(lane_index + i + j)
406429
if bko == 0:
407430
alias_str = "etp{:d}".format(alias_index)
408431
else:
409-
alias_str = "etp{:d}{:s}".format(alias_index,alias_arr[i/step])
410-
index_str = "{:d}".format(alias_index-1)
432+
alias_str = "etp{:d}{:s}".format(alias_index,alias_arr[int(i/step)])
433+
index_str = "{:d}".format(alias_index)
411434
lanes_str_result = lanes_str_result + ":" + lanes_str
412435
out_str = "{:15s} {:20s} {:11s} {:9s} {:10s}\n".format(port_str,lanes_str,alias_str,index_str,str(speed))
413436
f_out.write(out_str)
@@ -446,7 +469,6 @@ def break_in_cfg(self, cfg_file, port_name, port_split, lanes_str_result):
446469

447470
for port_index in range (port_idx,port_idx+self.base_lanes):
448471
port_str = "Ethernet" + str(port_index)
449-
print("Port String ",port_str)
450472

451473
if data['PORT'].get(port_str) != None:
452474
port_instance = data['PORT'].get(port_str)
@@ -467,15 +489,14 @@ def break_in_cfg(self, cfg_file, port_name, port_split, lanes_str_result):
467489
bko = self.bko_dict[port_split]["bko"]
468490

469491
for i in range(0,self.base_lanes,step):
470-
port_str = "Ethernet{:d}".format(port_idx + i/step)
492+
port_str = "Ethernet{:d}".format(port_idx + i)
471493
lanes_str = lanes_arr[j]
472494
j += 1
473495

474496
if bko == 0:
475-
alias_str = "etp{:d}".format((port_idx/self.base_lanes)+1)
497+
alias_str = "etp{:d}".format(int(port_idx/self.base_lanes)+1)
476498
else:
477-
alias_str = "etp{:d}{:s}".format((port_idx/self.base_lanes)+1,alias_arr[i/step])
478-
print("i= ",i," alias_str= ",alias_str)
499+
alias_str = "etp{:d}{:s}".format(int(port_idx/self.base_lanes)+1,alias_arr[int(i/step)])
479500
port_inst["lanes"] = lanes_str
480501
port_inst["alias"] = alias_str
481502
port_inst["speed"] = speed*1000
@@ -487,6 +508,7 @@ def break_in_cfg(self, cfg_file, port_name, port_split, lanes_str_result):
487508

488509
with open(new_file, 'w') as outfile:
489510
json.dump(data, outfile, indent=4, sort_keys=True)
511+
shutil.copy(new_file,cfg_file)
490512

491513
print("--------------------------------------------------------")
492514

@@ -555,16 +577,16 @@ def set_lanes(self):
555577
m = re.match(pattern,self.default_lanes_per_port[fp-1])
556578
if (splt == 1):
557579
self.portconfig_dict[idx_arr[0]][lanes_index] = m.group(1)+","+m.group(2)+","+m.group(3)+","+m.group(4)
558-
self.portconfig_dict[idx_arr[0]][index_index] = str(fp-1)
580+
self.portconfig_dict[idx_arr[0]][index_index] = str(fp)
559581
self.portconfig_dict[idx_arr[0]][name_index] = "Ethernet"+str((fp-1)*4)
560582
if (self.verbose):
561583
print("set_lanes -> FP: ",fp, "Split: ",splt)
562584
print("PortConfig_dict ",idx_arr[0],":", self.portconfig_dict[idx_arr[0]])
563585
elif (splt == 2):
564586
self.portconfig_dict[idx_arr[0]][lanes_index] = m.group(1)+","+m.group(2)
565587
self.portconfig_dict[idx_arr[1]][lanes_index] = m.group(3)+","+m.group(4)
566-
self.portconfig_dict[idx_arr[0]][index_index] = str(fp-1)
567-
self.portconfig_dict[idx_arr[1]][index_index] = str(fp-1)
588+
self.portconfig_dict[idx_arr[0]][index_index] = str(fp)
589+
self.portconfig_dict[idx_arr[1]][index_index] = str(fp)
568590
self.portconfig_dict[idx_arr[0]][name_index] = "Ethernet"+str((fp-1)*4)
569591
self.portconfig_dict[idx_arr[1]][name_index] = "Ethernet"+str((fp-1)*4+2)
570592
if (self.verbose):
@@ -576,10 +598,10 @@ def set_lanes(self):
576598
self.portconfig_dict[idx_arr[1]][lanes_index] = m.group(2)
577599
self.portconfig_dict[idx_arr[2]][lanes_index] = m.group(3)
578600
self.portconfig_dict[idx_arr[3]][lanes_index] = m.group(4)
579-
self.portconfig_dict[idx_arr[0]][index_index] = str(fp-1)
580-
self.portconfig_dict[idx_arr[1]][index_index] = str(fp-1)
581-
self.portconfig_dict[idx_arr[2]][index_index] = str(fp-1)
582-
self.portconfig_dict[idx_arr[3]][index_index] = str(fp-1)
601+
self.portconfig_dict[idx_arr[0]][index_index] = str(fp)
602+
self.portconfig_dict[idx_arr[1]][index_index] = str(fp)
603+
self.portconfig_dict[idx_arr[2]][index_index] = str(fp)
604+
self.portconfig_dict[idx_arr[3]][index_index] = str(fp)
583605
self.portconfig_dict[idx_arr[0]][name_index] = "Ethernet"+str((fp-1)*4)
584606
self.portconfig_dict[idx_arr[1]][name_index] = "Ethernet"+str((fp-1)*4+1)
585607
self.portconfig_dict[idx_arr[2]][name_index] = "Ethernet"+str((fp-1)*4+2)
@@ -700,6 +722,7 @@ def main(argv):
700722
parser.add_argument('-p', '--print', action='store_true', help='Print port_config.ini without creating a new SKU', default=False)
701723
parser.add_argument('--verbose', action='store_true', help='Verbose output', default=False)
702724
parser.add_argument('-d', '--default_sku_path', action='store',nargs=1, help='Specify Default SKU path', default=None)
725+
parser.add_argument('-q', '--port_split_path', action='store',nargs=1, help='Specify Port split path', default=None)
703726
parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0')
704727

705728
args = parser.parse_args()
@@ -736,6 +759,8 @@ def main(argv):
736759
elif args.minigraph_file:
737760
sku.minigraph_parser(args.minigraph_file)
738761
elif args.json_file:
762+
if sku.platform is None:
763+
sku.parse_platform_from_config_db_file(args.json_file[0])
739764
if sku.platform in platform_4:
740765
sku.base_lanes = 4
741766
sku.bko_dict = bko_dict_4
@@ -751,6 +776,25 @@ def main(argv):
751776
sku.json_file_parser(args.json_file[0])
752777
return
753778
elif args.port_split:
779+
if args.port_split_path:
780+
sku.ini_file = args.port_split_path[0] + "/port_config.ini"
781+
sku.cfg_file = args.port_split_path[0] + "/config_db.json"
782+
sku.parse_platform_from_config_db_file(sku.cfg_file)
783+
else:
784+
try:
785+
sku_name = subprocess.check_output("show platform summary | grep HwSKU ",shell=True).rstrip().split()[1]
786+
except KeyError:
787+
print("Couldn't find HwSku info in Platform summary", file=sys.stderr)
788+
exit(1)
789+
sku.ini_file = sku.default_sku_path + "/" + sku_name + "/port_config.ini"
790+
sku.cfg_file = "/etc/sonic/config_db.json"
791+
792+
if sku.platform in platform_4:
793+
sku.base_lanes = 4
794+
sku.bko_dict = bko_dict_4
795+
else:
796+
sku.base_lanes = 8
797+
sku.bko_dict = bko_dict_8
754798
sku.break_a_port(args.port_split[0], args.port_split[1])
755799
return
756800

tests/sku_create_input/ACS-MSN2700/buffers_defaults_t0.j2 tests/sku_create_input/2700_files/ACS-MSN2700/buffers_defaults_t0.j2

+36-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{% set default_cable = '5m' %}
2-
{% set ingress_lossless_pool_size = '4194304' %}
3-
{% set ingress_lossy_pool_size = '7340032' %}
4-
{% set egress_lossless_pool_size = '16777152' %}
5-
{% set egress_lossy_pool_size = '7340032' %}
2+
{% set ingress_lossless_pool_size = '4580864' %}
3+
{% set ingress_lossy_pool_size = '4580864' %}
4+
{% set egress_lossless_pool_size = '13945824' %}
5+
{% set egress_lossy_pool_size = '4580864' %}
66

77
{%- macro generate_port_lists(PORT_ALL) %}
88
{# Generate list of ports #}
@@ -14,12 +14,16 @@
1414
{%- macro generate_buffer_pool_and_profiles() %}
1515
"BUFFER_POOL": {
1616
"ingress_lossless_pool": {
17+
{%- if dynamic_mode is not defined %}
1718
"size": "{{ ingress_lossless_pool_size }}",
19+
{%- endif %}
1820
"type": "ingress",
1921
"mode": "dynamic"
2022
},
2123
"ingress_lossy_pool": {
24+
{%- if dynamic_mode is not defined %}
2225
"size": "{{ ingress_lossy_pool_size }}",
26+
{%- endif %}
2327
"type": "ingress",
2428
"mode": "dynamic"
2529
},
@@ -29,7 +33,9 @@
2933
"mode": "dynamic"
3034
},
3135
"egress_lossy_pool": {
36+
{%- if dynamic_mode is not defined %}
3237
"size": "{{ egress_lossy_pool_size }}",
38+
{%- endif %}
3339
"type": "egress",
3440
"mode": "dynamic"
3541
}
@@ -38,7 +44,7 @@
3844
"ingress_lossless_profile": {
3945
"pool":"[BUFFER_POOL|ingress_lossless_pool]",
4046
"size":"0",
41-
"dynamic_th":"0"
47+
"dynamic_th":"7"
4248
},
4349
"ingress_lossy_profile": {
4450
"pool":"[BUFFER_POOL|ingress_lossy_pool]",
@@ -52,8 +58,8 @@
5258
},
5359
"egress_lossy_profile": {
5460
"pool":"[BUFFER_POOL|egress_lossy_pool]",
55-
"size":"4096",
56-
"dynamic_th":"3"
61+
"size":"9216",
62+
"dynamic_th":"7"
5763
},
5864
"q_lossy_profile": {
5965
"pool":"[BUFFER_POOL|egress_lossy_pool]",
@@ -65,25 +71,41 @@
6571

6672
{%- macro generate_profile_lists(port_names) %}
6773
"BUFFER_PORT_INGRESS_PROFILE_LIST": {
68-
"{{ port_names }}": {
74+
{% for port in port_names.split(',') %}
75+
"{{ port }}": {
6976
"profile_list" : "[BUFFER_PROFILE|ingress_lossless_profile],[BUFFER_PROFILE|ingress_lossy_profile]"
70-
}
77+
}{% if not loop.last %},{% endif %}
78+
79+
{% endfor %}
7180
},
7281
"BUFFER_PORT_EGRESS_PROFILE_LIST": {
73-
"{{ port_names }}": {
82+
{% for port in port_names.split(',') %}
83+
"{{ port }}": {
7484
"profile_list" : "[BUFFER_PROFILE|egress_lossless_profile],[BUFFER_PROFILE|egress_lossy_profile]"
75-
}
85+
}{% if not loop.last %},{% endif %}
86+
87+
{% endfor %}
7688
}
7789
{%- endmacro %}
7890

7991
{%- macro generate_queue_buffers(port_names) %}
8092
"BUFFER_QUEUE": {
81-
"{{ port_names }}|3-4": {
93+
{% for port in port_names.split(',') %}
94+
"{{ port }}|3-4": {
8295
"profile" : "[BUFFER_PROFILE|egress_lossless_profile]"
8396
},
84-
"{{ port_names }}|0-1": {
97+
{% endfor %}
98+
{% for port in port_names.split(',') %}
99+
"{{ port }}|0-2": {
85100
"profile" : "[BUFFER_PROFILE|q_lossy_profile]"
86-
}
101+
},
102+
{% endfor %}
103+
{% for port in port_names.split(',') %}
104+
"{{ port }}|5-6": {
105+
"profile" : "[BUFFER_PROFILE|q_lossy_profile]"
106+
}{% if not loop.last %},{% endif %}
107+
108+
{% endfor %}
87109
}
88110
{%- endmacro %}
89111

0 commit comments

Comments
 (0)