Dynamically determine overlay MTU

Some clouds we run on no longer have MTUs of 1500 on their interfaces
and are smaller. We dynamically determine the MTU we should use on the
overlay networks. List all "real" interfaces with a permament mac addr
then use the smallest MTU less 50 bytes for vxlan overhead.

We only consider "real" interfaces so that we can run this multiple
times for separate overlays without perpetually decreasing the MTU due
to finding the lower MTU we just configured.

Change-Id: If163bf211570e690e255cc3ef6888d9e0cba19b5
This commit is contained in:
Clark Boylan 2018-06-26 09:22:29 -07:00
parent 63e5e1dd96
commit f93a3171ff
4 changed files with 76 additions and 2 deletions

View File

@ -1,3 +1,6 @@
ovs_starting_offset: 1
ovs_vni_offset: 1000000
ovs_bridge_mtu: 1450
# This value can be set to override the dynamic determinication
# of this value.
# ovs_bridge_mtu: 1450

View File

@ -26,6 +26,40 @@
openvswitch_bridge:
bridge: "{{ bridge_name }}"
- when: ovs_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 ovs_bridge_mtu
set_fact:
ovs_bridge_mtu: "{{ mtu_output.stdout }}"
- name: Set MTU on subnode bridge
command: ip link set mtu {{ ovs_bridge_mtu }} dev {{ bridge_name }}

View File

@ -1,2 +1,5 @@
ovs_starting_offset: 1
ovs_bridge_mtu: 1450
# This value can be set to override the dynamic determinication
# of this value.
# ovs_bridge_mtu: 1450

View File

@ -2,6 +2,40 @@
openvswitch_bridge:
bridge: "{{ bridge_name }}"
- when: ovs_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 ovs_bridge_mtu
set_fact:
ovs_bridge_mtu: "{{ mtu_output.stdout }}"
- name: Set bridge MTU
command: ip link set mtu {{ ovs_bridge_mtu }} dev {{ bridge_name }}