本文简单介绍一下OVN是如何通过external logical port来为外部主机提供DHCP服务。
1. 简介
Native OVN services for external logical ports
以下是摘自OVN官网,对external logical ports的介绍
To support OVN native services (like DHCP/IPv6 RA/DNS lookup) to the cloud resources which are external, OVN supports external logical ports.
Below are some of the use cases where external ports can be used.
- VMs connected to SR-IOV nics - Traffic from these VMs by passes the kernel stack and local ovn-controller do not bind these ports and cannot serve the native services.
- When CMS supports provisioning baremetal servers.
OVN will provide the native services if CMS has done the below configuration in the OVN Northbound Database.
A row is created in Logical_Switch_Port, configuring the addresses column and setting the type to external.
ha_chassis_group column is configured.
The HA chassis which belongs to the HA chassis group has the ovn-bridge-mappings configured and has proper L2 connectivity so that it can receive the DHCP and other related request packets from these external resources.
The Logical_Switch of this port has a localnet port.
Native OVN services are enabled by configuring the DHCP options like the way it is done for the normal logical ports.
It is recommended to use the same HA chassis group for all the external ports of a logical switch. Otherwise, the physical switch might see MAC flap issue when different chassis provide the native services. For example when supporting native DHCPv4 service, DHCPv4 server mac (configured in options:server_mac column in table DHCP_Options) originating from different ports can cause MAC flap issue. The MAC of the logical router IP(s) can also flap if the same HA chassis group is not set for all the external ports of a logical switch.
2. 配置流程
2.1 安装ovs
1 | yum install -y openvswitch |
2.2 安装/配置ovn
1 | yum install -y unbound-libs ovn ovn-host ovn-central |
2.3 创建br-int网桥,配置ovs
1 | ovs-vsctl add-br br-int |
2.4 配置external logical port
2.4.1 创建/配置 logical switch, logical switch port,dhcp option
1 | #创建net0的logical switch |
2.4.2 配置逻辑端口类型为external
1 | ovn-nbctl lsp-set-type port1 external |
2.4.3 创建路基路由,并将它与net0逻辑交换机连接
1 | ovn-nbctl lr-add lr0 |
2.4.4 创建localnet port。创建br-phys网桥,来绑定物理网卡
1 | # 创建br-phys网桥,绑定ens37物理网卡 |
2.4.5 创建ha_chassis_group,绑定port1关联到ha_chassis_group
1 | # 创建ha chassis group |
2.4.6 此时再次查看流表
1 | 已经有dhcp相关的流表信息 |
3 验证dhcp功能
登录到mac地址是00:0c:29:e7:ff:ac的虚拟机,执行dhclient ens33。可以看到准确的拿到了ip。
1 | [root@localhost ~]# dhclient ens33 |
4. 遇到的问题
- 重启ovn所在的虚拟机chassis的名字改了,改成了uuid。所以添加chassis到ha-chassis-group的时候一定要用uuid。
- 重启ovs,ovn-controller并不会自动下发流表,需要重启ovn-controller。
- ovn-nbctl ha-chassis-group-del-chassis命令不存在,在社区提了个patch,解了。https://github.com/ovn-org/ovn/commit/358d162c071cfb56ce9fd113ccc5e3b599022fe1
- ovs为网桥关联物理网卡的话,物理网卡不能有ip,不然网络会瘫痪。
参考文档
ovn简介:http://galsagie.github.io/2015/04/20/ovn-1/
ovn external logical port代相关代码和文档:
- ovn external logical port简介:https://man7.org/linux/man-pages/man7/ovn-architecture.7.html
- ovn external logical port的bug需求:https://bugzilla.redhat.com/show_bug.cgi?id=1666673
- ovn external logical portd的代码和测试用例:https://github.com/openvswitch/ovs/commit/96080083581275afaec8bc281d6a648aff7ef39e#diff-97d4cf929e4894ef95c4bfde3f896c34
- ovn dhcp的一个example :https://blog.oddbit.com/post/2019-12-19-ovn-and-dhcp/
ovn gateway出网方案:https://segmentfault.com/a/1190000020349044
ovn native dhcp support:https://numans.blog/2016/08/09/native-dhcp-support-in-ovn/
ovn Genevevs VXLAN: https://blog.russellbryant.net/2017/05/30/ovn-geneve-vs-vxlan-does-it-matter/
ovs配置常见问题:(ovs绑定物理网卡时,物理网卡不能配置ip):https://docs.openvswitch.org/en/latest/faq/issues/