Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve: buffer configuration infrastructure #1403

Merged
merged 6 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions files/build_templates/buffers_config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
{%- macro set_default_topology() %}
{%- if default_topo is defined %}
{{ default_topo }}
{%- else %}
def
{%- endif %}
{%- endmacro %}

{# Determine device topology and filename postfix #}
{%- if DEVICE_METADATA is defined %}
{%- set switch_role = DEVICE_METADATA['localhost']['type'] %}
{%- if switch_role.lower() == 'torrouter' %}
{%- set filename_postfix = 't0' %}
{%- elif switch_role.lower() == 'leafrouter' %}
{%- set filename_postfix = 't1' %}
{%- else %}
{%- set filename_postfix = set_default_topology() %}
{%- endif %}
{%- else %}
{%- set filename_postfix = set_default_topology() %}
{%- set switch_role = '' %}
{%- endif %}

{# Import default values from device HWSKU folder #}
{%- import 'buffers_defaults_%s.j2' % filename_postfix as defs %}

{%- set default_cable = defs.default_cable %}
{%- set default_speed = defs.default_speed %}

{# Port configuration to cable length look-up table #}
{# Each record describes mapping of DUT (DUT port) role and neighbor role to cable length #}
{# Roles described in the minigraph #}
{%- set ports2cable = {
'torrouter_server' : '5m',
'leafrouter_torrouter' : '40m',
'spinerouter_leafrouter' : '300m'
}
-%}

{%- macro cable_length(port_name) %}
{%- set cable_len = [] %}
{%- for local_port in DEVICE_NEIGHBOR %}
{%- if local_port == port_name %}
{%- if DEVICE_NEIGHBOR_METADATA[DEVICE_NEIGHBOR[local_port].name] %}
{%- set neighbor = DEVICE_NEIGHBOR_METADATA[DEVICE_NEIGHBOR[local_port].name] %}
{%- set neighbor_role = neighbor.type %}
{%- set roles1 = switch_role + '_' + neighbor_role %}
{%- set roles2 = neighbor_role + '_' + switch_role %}
{%- set roles1 = roles1 | lower %}
{%- set roles2 = roles2 | lower %}
{%- if roles1 in ports2cable %}
{%- if cable_len.append(ports2cable[roles1]) %}{% endif %}
{%- elif roles2 in ports2cable %}
{%- if cable_len.append(ports2cable[roles2]) %}{% endif %}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- if cable_len %}
{{ cable_len.0 }}
{%- else %}
{%- if switch_role.lower() == 'torrouter' %}
{%- for local_port in VLAN_MEMBER %}
{%- set vlan_port = local_port.split("|") %}
{%- if vlan_port[1] == port_name %}
{%- set roles3 = switch_role + '_' + 'server' %}
{%- set roles3 = roles3 | lower %}
{%- if roles3 in ports2cable %}
{%- if cable_len.append(ports2cable[roles3]) %}{% endif %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- if cable_len %}
{{ cable_len.0 }}
{%- else %}
{{ default_cable }}
{%- endif %}
{%- else %}
{{ default_cable }}
{%- endif %}
{%- endif %}
{%- endmacro %}

{%- set PORT_ALL = [] %}
{%- set PORT_10G = [] %}
{%- set PORT_25G = [] %}
{%- set PORT_40G = [] %}
{%- set PORT_50G = [] %}
{%- set PORT_100G = [] %}

{%- if PORT is not defined %}
{%- if defs.generate_port_lists(PORT_10G, PORT_25G, PORT_40G, PORT_50G, PORT_100G) %} {% endif %}
{%- else %}
{# Determine the default speed set according to the default speed #}
{%- if default_speed == '10G' %}
{%- set default_set = PORT_10G %}
{%- elif default_speed == '25G' %}
{%- set default_set = PORT_25G %}
{%- elif default_speed == '40G' %}
{%- set default_set = PORT_40G %}
{%- elif default_speed == '50G' %}
{%- set default_set = PORT_50G %}
{%- elif default_speed == '100G' %}
{%- set default_set = PORT_100G %}
{%- else %}
{%- set default_set = PORT_50G %}
{%- endif %}

{# Distribute ports to speed sets #}
{%- for port in PORT %}
{%- if 'speed' in PORT[port] %}
{%- set speed = PORT[port]['speed'] %}
{%- if speed == '100000' %}
{%- if PORT_100G.append(port) %}{%- endif %}
{%- elif speed == '50000' %}
{%- if PORT_50G.append(port) %}{%- endif %}
{%- elif speed == '40000' %}
{%- if PORT_40G.append(port) %}{%- endif %}
{%- elif speed == '25000' %}
{%- if PORT_25G.append(port) %}{%- endif %}
{%- elif speed == '10000' %}
{%- if PORT_10G.append(port) %}{%- endif %}
{%- else %}
{%- if default_set.append(port) %}{%- endif %}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look into the possibility of looking up speed information from port_config.ini

{%- endif %}
{%- else %}
{%- if default_set.append(port) %}{%- endif %}
{%- endif %}
{%- endfor %}
{%- endif %}

{# Put all ports in PORT_ALL #}
{%- for port in PORT_10G + PORT_25G + PORT_40G + PORT_50G + PORT_100G %}
{%- if PORT_ALL.append(port) %}{%- endif %}
{%- endfor %}

{%- set port_names_list_all = [] %}
{%- for port in PORT_ALL %}
{%- if port_names_list_all.append(port) %}{%- endif %}
{%- endfor %}
{%- set port_names_all = port_names_list_all | join(',') %}

{
"CABLE_LENGTH": {
"AZURE": {
{% for port in PORT %}
{%- set cable = cable_length(port) %}
"{{ port }}": "{{ cable }}"{%- if not loop.last %},{% endif %}

{% endfor %}
}
},
{% set bufs = defs.generate_buffer_pool_and_profiles() %}
{{ bufs }}
"BUFFER_PG": {
{% for port in PORT_10G %}
"{{ port }}|3-4": {
"profile" : "[BUFFER_PROFILE|ingress_lossless_profile_10g]"
},
{% endfor %}
{% for port in PORT_25G %}
"{{ port }}|3-4": {
"profile" : "[BUFFER_PROFILE|ingress_lossless_profile_25g]"
},
{% endfor %}
{% for port in PORT_40G %}
"{{ port }}|3-4": {
"profile" : "[BUFFER_PROFILE|ingress_lossless_profile_40g]"
},
{% endfor %}
{% for port in PORT_50G %}
"{{ port }}|3-4": {
"profile" : "[BUFFER_PROFILE|ingress_lossless_profile_50g]"
},
{% endfor %}
{% for port in PORT_100G %}
"{{ port }}|3-4": {
"profile" : "[BUFFER_PROFILE|ingress_lossless_profile_100g]"
},
{% endfor %}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove default configuration for pg 3-4

{% if port_names_all|length > 0 %}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove or duplicate below

"{{ port_names_all }}|0-1": {
"profile" : "[BUFFER_PROFILE|ingress_lossy_profile]"
}
{% endif %}
},
"BUFFER_QUEUE": {
"{{ port_names_all }}|3-4": {
"profile" : "[BUFFER_PROFILE|egress_lossless_profile]"
},
"{{ port_names_all }}|0-1": {
"profile" : "[BUFFER_PROFILE|egress_lossy_profile]"
}
}
}
3 changes: 3 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable hostcfgd.service
sudo cp $IMAGE_CONFIGS/hostcfgd/hostcfgd $FILESYSTEM_ROOT/usr/bin/
sudo cp $IMAGE_CONFIGS/hostcfgd/*.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/

# Copy the buffer configuration template
sudo cp $BUILD_TEMPLATES/buffers_config.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/

# Copy hostname configuration scripts
sudo cp $IMAGE_CONFIGS/hostname/hostname-config.service $FILESYSTEM_ROOT/etc/systemd/system/
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable hostname-config.service
Expand Down