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 3 commits
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]"
}
}
}
19 changes: 14 additions & 5 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ set -x -e
BUILD_TEMPLATES=files/build_templates
IMAGE_CONFIGS=files/image_config

# Define target fold macro
FILESYSTEM_ROOT_USR="$FILESYSTEM_ROOT/usr"
FILESYSTEM_ROOT_USR_SHARE="$FILESYSTEM_ROOT_USR/share"
FILESYSTEM_ROOT_USR_SHARE_SONIC="$FILESYSTEM_ROOT_USR_SHARE/sonic"
FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES="$FILESYSTEM_ROOT_USR_SHARE_SONIC/templates"

clean_sys() {
sudo umount $FILESYSTEM_ROOT/sys/fs/cgroup/* \
$FILESYSTEM_ROOT/sys/fs/cgroup \
Expand All @@ -52,7 +58,7 @@ sudo cp $IMAGE_CONFIGS/environment/motd $FILESYSTEM_ROOT/etc/

# Create all needed directories
sudo mkdir -p $FILESYSTEM_ROOT/etc/sonic/
sudo mkdir -p $FILESYSTEM_ROOT/usr/share/sonic/templates/
sudo mkdir -p $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/

# Install dependencies for SONiC config engine
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install \
Expand Down Expand Up @@ -110,13 +116,13 @@ sudo cp -f $IMAGE_CONFIGS/cron.d/* $FILESYSTEM_ROOT/etc/cron.d/
sudo cp $IMAGE_CONFIGS/ntp/ntp-config.service $FILESYSTEM_ROOT/etc/systemd/system/
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable ntp-config.service
sudo cp $IMAGE_CONFIGS/ntp/ntp-config.sh $FILESYSTEM_ROOT/usr/bin/
sudo cp $IMAGE_CONFIGS/ntp/ntp.conf.j2 $FILESYSTEM_ROOT/usr/share/sonic/templates/
sudo cp $IMAGE_CONFIGS/ntp/ntp.conf.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/

# Copy rsyslog configuration files and templates
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.service $FILESYSTEM_ROOT/etc/systemd/system/
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable rsyslog-config.service
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.sh $FILESYSTEM_ROOT/usr/bin/
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.conf.j2 $FILESYSTEM_ROOT/usr/share/sonic/templates/
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.conf.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.d/* $FILESYSTEM_ROOT/etc/rsyslog.d/

# Copy logrotate.d configuration files
Expand All @@ -129,7 +135,7 @@ sudo cp -f $IMAGE_CONFIGS/systemd/journald.conf $FILESYSTEM_ROOT/etc/systemd/
sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config.service $FILESYSTEM_ROOT/etc/systemd/system/
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable interfaces-config.service
sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config.sh $FILESYSTEM_ROOT/usr/bin/
sudo cp $IMAGE_CONFIGS/interfaces/*.j2 $FILESYSTEM_ROOT/usr/share/sonic/templates/
sudo cp $IMAGE_CONFIGS/interfaces/*.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/

# Copy initial interfaces configuration file, will be overwritten on first boot
sudo cp $IMAGE_CONFIGS/interfaces/init_interfaces $FILESYSTEM_ROOT/etc/network
Expand All @@ -138,7 +144,10 @@ sudo cp $IMAGE_CONFIGS/interfaces/init_interfaces $FILESYSTEM_ROOT/etc/network
sudo cp $IMAGE_CONFIGS/hostcfgd/hostcfgd.service $FILESYSTEM_ROOT/etc/systemd/system/
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/
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/
Expand Down
5 changes: 4 additions & 1 deletion src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ def main():

if args.template != None:
template_file = os.path.abspath(args.template)
env = jinja2.Environment(loader=jinja2.FileSystemLoader('/'), trim_blocks=True)
paths = ['/', '/usr/share/sonic/templates', os.path.dirname(template_file)]
loader = jinja2.FileSystemLoader(paths)

env = jinja2.Environment(loader=loader, trim_blocks=True)
env.filters['ipv4'] = is_ipv4
env.filters['ipv6'] = is_ipv6
env.filters['unique_name'] = unique_name
Expand Down