使用 Linux Bridge 搭建 VXLAN Overlay 网络

前言

使用 Linux Bridge 搭建 VXLAN 网络不是件很难的事,但是目前确实有一些小坑,这里记录一下。

本文会介绍:

  • 如何使用 Linux Bridge 搭建一个 VXLAN Overlay 网络
  • 如何用 Namespace 模拟虚拟机验证通信
  • Linux VXLAN DOVE Extension 带来的新参数

本文不会介绍:

  • VXLAN 是什么
  • 现代 VXLAN 协议的发展与控制平面的演化

命令

没有多大难度,直接介绍使用的命令。

iptables -D INPUT -j REJECT --reject-with icmp-host-prohibited
# 在我的环境里总会有默认的两条 reject 规则,好烦,先干掉

ip link add vxlan21 type vxlan id 100 dev eth0
# 先添加 vxaln 接口,这个是比较简洁的版本(dev eth0 可以去掉),你可以依照喜好添加一些参数,比如:
# local 10.0.121.180,指定一个本地地址,linux 下的 VXLAN 接口可以不指定 IP 地址、网卡,也可以指定,看需要设置;
# group 239.1.1.1 使用组播模式,239.1.1.1 即为组播地址;
# dstport 4789 指定 vxlan 端口,如果不写的或者写 dspport 0 的话系统会自动使用 8472——根据 IANA 的[标准][1]现在应该使用 4789,包括 VMware NSX 6.2.3 开始也默认从 8472 该到了 4789;
# srcport 32768 61000 可以指定源端口的范围;
# 此外还有一些 DOVE Extension 带来的参数,放在后面介绍

ip link set vxlan21 up
# 将接口 UP,系统会起一个 UDP Socket 监听相应端口

brctl addbr lb-int
ip link set dev lb-int up
brctl addif vxlan21
brctl addif lb-int vxlan21
bridge fdb append to 00:00:00:00:00:00 dev vxlan21 dst 10.0.56.18
# 配置一个对端 VTEP

ip link add veth20 type veth peer name veth02
ip link set veth02 up
brctl addif lb-int veth02
ip netns add veth2
# 创建 namespace 和 veth 设备模拟虚拟机

ip link set dev veth20 netns veth2
ip netns exec veth2 ip a add dev veth20 192.168.0.12/24
ip netns exec veth1 ip link set veth20 up
ip netns exec veth2 ping 192.168.0.11
# 如果你在另一台 hypervisor(VTEP)做好了相应操作模拟了 192.168.0.11 地址,此时应该已经可以通讯了

DOVE Extension

DOVE 的全称是 Distributed Overlay Virtual Ethernet,是从 Linux 3.8 开始引入到内核,目的是方便为 Linux VXLAN 接入控制平面,提升效率。

引入 DOVE 后目前在创建 VXLAN 设备时可以添加下面几个参数:

  • l3miss,在 drivers.net.vxlan.vxlan_xmit 中,如果 VXLAN 设备开启了 Proxy,会尝试进行 ARP 压缩(drivers.net.vxlan.arp_reduce,尽量将 ARP 广播范围压缩到本地),如果此时查找不到这个 IP 对应的 ARP 记录的话,就会触发 l3miss,发送一条消息(netlink)到 userspace,这时 agent (userspace 程序,例如 docker overlay)可以直接添加一条 Neighbor 信息,以替代广播;
  • l2miss,VTEP 的 FDB 不存在目的 MAC 所对应的 VTEP IP 时,触发 l2miss,通过 netlink 发送一条消息到 userspace 替代复制到所有 VTEP;
  • proxy,在上面 l3miss 中说过了,用于做 ARP 本地压缩;
  • leraning,学习远端虚拟机的 MAC 地址,就是 VXLAN 的 flood and learn;
  • ageing,上面学习到本地 FDB 的虚拟机的 MAC 的超时时间;
  • maxaddress,FDB 表的最大条目数;
  • rsc,也就是 L3 switching,直接 switch 到目的地址,不需要经过路由(作者本人没有测试过,如果你做了测试欢迎交流)。

当然了,我说的都是错的,我建议你还是直接看代码。

如果觉得看 vxlan.c 比较困难的话,可以看 DOVE 的 Patch:http://lists.openwall.net/netdev/2012/11/15/96。

Reference

  1. Rami Cohen, et al: Distributed Overlay Virtual Ethernet (DOVE) integration with Openstack,
    IP/IEEE International Symposium on Integrated Network Management (IM 2013), 29-
    -May-2013, pp 1088-1089

  2. Etsuji Nakai: How VXLAN works on Linux, https://www.slideshare.net/enakai/how-vxlan-works-on-linux

  3. Joe Julian: How to configure linux vxlans with multiple unicast endpoints, https://joejulian.name/blog/how-to-configure-linux-vxlansith-multiple-unicast-endpoints/

  4. Thomas Richter: Software Defined Networking using VXLAN, LinuxCon Edinburgh 21-Oct-2013

  5. 刘世民: Neutron 理解(14):Neutron ML2 + Linux bridge + VxLAN 组网, http://www.cnblogs.com/sammyliu/p/4985907.html

2 thoughts on “使用 Linux Bridge 搭建 VXLAN Overlay 网络

Leave a Reply to Cord Cancel reply

Your email address will not be published. Required fields are marked *