Skip to content

Commit ca78d18

Browse files
zhixzhuyanjundeng
authored andcommitted
Buffer and qos j2 file modularization (sonic-net#21102)
Buffer and qos j2 file modularization
1 parent 866acb6 commit ca78d18

File tree

2 files changed

+53
-20
lines changed

2 files changed

+53
-20
lines changed

files/build_templates/buffers_config.j2

+30-18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def
1313
{%- set filename_postfix = 't0' %}
1414
{%- elif 'leafrouter' in switch_role.lower() and 'mgmt' not in switch_role.lower()%}
1515
{%- set filename_postfix = 't1' %}
16+
{%- elif 'spinerouter' in switch_role.lower() and 'mgmt' not in switch_role.lower()%}
17+
{%- set filename_postfix = 't2' %}
1618
{%- else %}
1719
{%- set filename_postfix = set_default_topology() %}
1820
{%- endif %}
@@ -26,10 +28,12 @@ def
2628
{%- set voq_chassis = true %}
2729
{%- endif -%}
2830

29-
{# Import default values from device HWSKU folder #}
30-
{%- import 'buffers_defaults_%s.j2' % filename_postfix as defs with context %}
31-
32-
{%- set default_cable = defs.default_cable -%}
31+
{# Allow includer to pre-package defs without needing an import #}
32+
{%- if defs is not defined -%}
33+
{# Import default values from device HWSKU folder #}
34+
{%- import 'buffers_defaults_%s.j2' % filename_postfix as defs with context %}
35+
{%- set default_cable = defs.default_cable -%}
36+
{%- endif -%}
3337

3438
{# Port configuration to cable length look-up table #}
3539
{# Each record describes mapping of DUT (DUT port) role and neighbor role to cable length #}
@@ -48,6 +52,7 @@ def
4852
-%}
4953
{%- endif %}
5054

55+
{%- if cable_length is not defined %}
5156
{%- macro cable_length(port_name) %}
5257
{%- set cable_len = [] %}
5358
{%- for local_port in DEVICE_NEIGHBOR %}
@@ -84,7 +89,12 @@ def
8489
{%- elif cable_len -%}
8590
{{ cable_len.0 }}
8691
{%- else %}
87-
{%- if 'torrouter' in switch_role.lower() and 'mgmt' not in switch_role.lower()%}
92+
{%- if port_name.startswith('Ethernet-BP') %}
93+
{%- if 'internal' not in ports2cable %}
94+
{%- set _ = ports2cable.update({'internal': '5m'}) %}
95+
{%- endif -%}
96+
{%- set _ = cable_len.append(ports2cable['internal']) %}
97+
{%- elif 'torrouter' in switch_role.lower() and 'mgmt' not in switch_role.lower()%}
8898
{%- for local_port in VLAN_MEMBER %}
8999
{%- if local_port[1] == port_name %}
90100
{%- set roles3 = switch_role + '_' + 'server' %}
@@ -95,23 +105,15 @@ def
95105
{%- endif %}
96106
{%- endif %}
97107
{%- endfor %}
98-
{%- if cable_len -%}
99-
{{ cable_len.0 }}
100-
{%- else -%}
101-
{{ default_cable }}
102-
{%- endif %}
108+
{%- endif %}
109+
{%- if cable_len -%}
110+
{{ cable_len.0 }}
103111
{%- else -%}
104-
{%- if port_name.startswith('Ethernet-BP') %}
105-
{%- if 'internal' not in ports2cable %}
106-
{%- set _ = ports2cable.update({'internal': '5m'}) %}
107-
{%- endif -%}
108-
{{ ports2cable['internal'] }}
109-
{%- else -%}
110-
{{ default_cable }}
111-
{%- endif %}
112+
{{ default_cable }}
112113
{%- endif %}
113114
{%- endif %}
114115
{%- endmacro %}
116+
{%- endif %}
115117

116118
{%- set PORT_ALL = [] %}
117119
{%- set PORT_BP = [] %}
@@ -195,7 +197,16 @@ def
195197
{%- if port_names_list_inactive.append(port) %}{%- endif %}
196198
{%- endfor %}
197199
{%- set port_names_inactive = port_names_list_inactive | join(',') %}
200+
198201
{
202+
{% if (defs.generate_cable_length_config is defined) %}
203+
{%- set port_names_list_all = [] %}
204+
{%- for port in PORT_ALL %}
205+
{%- if port_names_list_all.append(port) %}{%- endif %}
206+
{%- endfor %}
207+
{%- set port_names_all = port_names_list_all | join(',') %}
208+
{{- defs.generate_cable_length_config(port_names_all) }}
209+
{% else %}
199210
"CABLE_LENGTH": {
200211
"AZURE": {
201212
{% for port in PORT_ALL %}
@@ -205,6 +216,7 @@ def
205216
{% endfor %}
206217
}
207218
},
219+
{% endif %}
208220

209221
{% if defs.generate_buffer_pool_and_profiles is defined %}
210222
{{ defs.generate_buffer_pool_and_profiles() }}

files/build_templates/qos_config.j2

+23-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@
8282
{% endif %}
8383
{%- endfor %}
8484

85+
{%- set LOSSLESS_TC = [] %}
86+
{%- if generate_lossless_tc_list is defined %}
87+
{{- generate_lossless_tc_list(LOSSLESS_TC) }}
88+
{%- else %}
89+
{%- set LOSSLESS_TC = ['3','4'] %}
90+
{%- endif %}
91+
8592
{%- set pfc_to_pg_map_supported_asics = ['mellanox', 'barefoot'] -%}
8693
{%- set backend_device_types = ['BackEndToRRouter', 'BackEndLeafRouter'] -%}
8794
{%- set apollo_resource_types = ['DL-NPU-Apollo'] -%}
@@ -125,6 +132,9 @@
125132
}
126133
},
127134
{% endif %}
135+
{% if (generate_pfc_to_queue_map is defined) %}
136+
{{- generate_pfc_to_queue_map() }}
137+
{% else %}
128138
"MAP_PFC_PRIORITY_TO_QUEUE": {
129139
"AZURE": {
130140
"0": "0",
@@ -137,6 +147,7 @@
137147
"7": "7"
138148
}
139149
},
150+
{% endif %}
140151
{% if (generate_tc_to_queue_map is defined) and tunnel_qos_remap_enable %}
141152
{{- generate_tc_to_queue_map() }}
142153
{% elif (generate_tc_to_queue_map_per_sku is defined) %}
@@ -252,6 +263,9 @@
252263
{% if (generate_tc_to_dscp_map is defined) and tunnel_qos_remap_enable %}
253264
{{- generate_tc_to_dscp_map() }}
254265
{% endif %}
266+
{% if (generate_scheduler_config is defined) %}
267+
{{- generate_scheduler_config() }}
268+
{% else %}
255269
{% if 'resource_type' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['resource_type'] in apollo_resource_types %}
256270
"SCHEDULER": {
257271
"scheduler.0": {
@@ -304,6 +318,7 @@
304318
}
305319
},
306320
{% endif %}
321+
{% endif %}
307322
{% if asic_type in pfc_to_pg_map_supported_asics %}
308323
"PFC_PRIORITY_TO_PRIORITY_GROUP_MAP": {
309324
{% if port_names_list_extra_queues|length > 0 %}
@@ -320,6 +335,9 @@
320335
}
321336
},
322337
{% endif %}
338+
{% if (generate_port_qos_map is defined) %}
339+
{{- generate_port_qos_map(port_names_active) }}
340+
{% else %}
323341
"PORT_QOS_MAP": {
324342
{% if generate_global_dscp_to_tc_map is defined %}
325343
{{- generate_global_dscp_to_tc_map() }}
@@ -364,9 +382,9 @@
364382
{% if port in port_names_list_extra_queues %}
365383
"pfc_enable" : "2,3,4,6",
366384
{% else %}
367-
"pfc_enable" : "3,4",
385+
"pfc_enable" : "{{ LOSSLESS_TC|join(',') }}",
368386
{% endif %}
369-
"pfcwd_sw_enable" : "3,4",
387+
"pfcwd_sw_enable" : "{{ LOSSLESS_TC|join(',') }}",
370388
{% endif %}
371389
{% if port not in PORT_DPC %}
372390
"tc_to_pg_map" : "AZURE",
@@ -378,6 +396,7 @@
378396

379397
{% endfor %}
380398
},
399+
{% endif %}
381400
{% if generate_wred_profiles is defined %}
382401
{{- generate_wred_profiles() }}
383402
{% else %}
@@ -446,6 +465,8 @@
446465
{%- if not loop.last -%},{% endif %}
447466
{% endfor %}
448467
}
468+
{% elif generate_queue_config is defined %}
469+
{{- generate_queue_config(port_names_active) }}
449470
{% else %}
450471
"QUEUE": {
451472
{% if 'type' in DEVICE_METADATA['localhost'] and

0 commit comments

Comments
 (0)