Dynamically determine overlay network mtu

Not all clouds will provide us with MTUs of 1500. Instead of assuming a
1500 - 50 byte MTU to accomodate for vxlan overhead we list all
interface MTUs, filter by those that appear to be "real" interfaces (to
avoid those we ourselves may have created), take the smallest one and
subtract it by 50 to accomodate for vxlan overhead. You can still set an
explicitl bridge_mtu value if necessary.

Change-Id: If899a1bee3b4b69df8c2905a219b41e119d8f652
This commit is contained in:
Clark Boylan 2018-06-26 09:54:09 -07:00
parent 8ed7cf4c52
commit 258a0d6ec7
4 changed files with 43 additions and 5 deletions

View File

@ -34,9 +34,12 @@ inventory in order to work:
VXLAN Network Identifier offset (openvswitch key).
.. zuul:rolevar:: bridge_mtu
:default: 1450
:default: Smallest mtu less 50 bytes for vxlan overhead
Bridge interface MTU.
Bridge interface MTU. By default we determine this value by checking
all interfaces on host, taking the smallest MTU and subtracting by
50 for vxlan overhead. Can be overridden explicitly if this does not
work.
.. zuul:rolevar:: bridge_name
:default: br-infra

View File

@ -1,5 +1,4 @@
bridge_vni_offset: 1000000
bridge_mtu: 1450
bridge_name: br-infra
bridge_authorize_internal_traffic: false

View File

@ -52,3 +52,37 @@
when:
- bridge_configure_address | bool
- bridge_authorize_internal_traffic | bool
- when: bridge_mtu is not defined
block:
- name: Determine bridge mtu
shell: |
# Find all interfaces with a permanent mac address type.
# Permanent mac addrs imply "real" hardware and not interfaces we have
# created through this system. This makes our MTU determination mostly
# idempotent allowing us to create multiple overlays without
# perpetually smaller MTUs.
SMALLEST_MTU=""
for X in $(ls /sys/class/net) ; do
MAC_TYPE=$(cat "/sys/class/net/${X}/addr_assign_type")
if [ "$MAC_TYPE" -ne "0" ] ; then
# Type 0 is a permanent address implying a "real"
# interface. We ignore other interfaces as that is what we
# create here
continue
fi
MTU=$(cat "/sys/class/net/${X}/mtu")
if [ -z "$SMALLEST_MTU" ] || [ "$SMALLEST_MTU" -gt "$MTU" ] ; then
SMALLEST_MTU=$MTU
fi
done
# 50 byte overhead for vxlan
echo $(( SMALLEST_MTU - 50 ))
args:
executable: /bin/bash
environment:
PATH: '{{ ansible_env.PATH }}:/bin:/sbin:/usr/sbin'
register: mtu_output
- name: Set bridge_mtu
set_fact:
bridge_mtu: "{{ mtu_output.stdout }}"

View File

@ -1,8 +1,10 @@
- include: common.yaml
# Note (dmsimard)
# We explicitely declare a PATH environment variable because '/sbin' is not in
# PATH when using 'become: yes' on some distributions
- include: common.yaml
environment:
PATH: "{{ ansible_env.PATH }}:/sbin:/usr/sbin"
- include: switch.yaml
environment:
PATH: "{{ ansible_env.PATH }}:/sbin:/usr/sbin"