OpenStack Neutron新功能VLAN-aware-VMs介绍

发布时间: 更新时间: 总字数:2441 阅读时间:5m 作者:IP:上海 网址

VLAN aware VMs有时也叫做VM trunk ports,主要是让虚拟机收发的vlan tagged报文, 能够被虚拟网络所识别和处理。

VLAN aware VMs 应用场景

该功能的主要使用场景有:

  1. 有些应用程序, 需要连接很多 neutron 网络。传统的方法是虚拟机上连接很多 neutron 网络, 但是这样做显然不好维护, 并不实用。比较好的办法是在虚拟机上使用 1 个 VIF 网卡接口,创建多个 VLAN 接口, 并通过收发不同 VLAN 报文来区分不同网络。

  2. 云计算网络中的负载较为动态, 有时需要动态的增删虚拟机上的网络接口。通过增删 vlan 相对来说更加简单和快捷。

  3. 通过配置 VLAN, 可以不用增删 VIF, 把 VM 从一个网络挪到另一个网络

  4. 一个 VM 可能跑多个容器, 通过给容器分配 VLAN 来连接到不同的 neutron 网络, 比给每个容器分配一个 VM 的 VIF, 更加有效和更好的可扩展性。

  5. 有些老的应用程序以及部分 NFV, 要求能够通过 VLAN 来连接网络, 本功能能够满足这个需求。

VLAN aware VMs 配置和使用方法

需要在网络节点的 neutron.conf 里配置 service_plugins 为: “trunk”。

text
service_plugins=...., trunk

我们将要创建一个虚拟机 trunk-vm1, 虚拟机上希望有 3 个网络接口: eth0, VLAN 接口: eth0.1, VLAN 接口: eth0.2。 其中:

nova 创建虚拟机时创建的 eth0, 主要用来收发 VLANuntagged 报文, 所属 net0 网络(子网为:10.0.4.0/24)。 对应的 neutron port 被称为 parent_port, 取名为: trunkparent。

手动在 VM 里创建的 VLAN 接口: eth0.1, 用来收发 VLAN tag=1 的报文, 所属 net1 网络(子网为: 10.0.5.0/24)。对应的 neutron port 被称为 subport, 取名为: subport1。

手动在 VM 里创建的 VLAN 接口: eth0.2, 用来收发 VLAN tag=2 的报文, 所属 net2 网络(子网为: 10.0.6.0/24)。对应的 neutron port 被称为 subport, 取名为: subport2。

  1. 创建网络 net0, net1, net2, 以及对应的子网: subnet0 (10.0.4.0/24),subnet1 (10.0.5.0/24), subnet2 (10.0.6.0/24)
bash
# OpenStack network create net0
# openstack network create net1
# openstack network create net2
# openstack subnet create --network net0 --subnet-range 10.0.4.0/24 subnet0
# openstack subnet create --network net1 --subnet-range 10.0.5.0/24 subnet1
# openstack subnet create --network net2 --subnet-range 10.0.6.0/24 subnet2
  1. 在 net0 上创建 trunkparentport, 在 net1 上创建 subport1, 在 net2 上创建 subport2
bash
# openstack port create --network net0 trunkparent
# openstack port create --network net1 subport1
# openstack port create --network net2 subport2
  1. 创建 mytrunk, 并设置 parent-port 为: trunkparent。subport 1 的 vlan_id=1。 subport2 的 vlan_id=2。
bash
# openstack network trunk create --parent-port trunkparent \
 --subport port=subport1,segmentation-type=vlan,segmentation-id=1 \
 --subport port=subport2,segmentation-type=vlan,segmentation-id=2 mytrunk

+-----------------+-----------------------------------------------------------------------------------------------+
| Field           | Value                                                                                         |
+-----------------+-----------------------------------------------------------------------------------------------+
| admin_state_up  | UP                                                                                            |
| created_at      | 2016-11-15T01:58:13Z                                                                          |
| description     |                                                                                               |
| id              | a5f0be95-67bd-4dea-b321-b4cad753b91d                                                          |
| name            | mytrunk                                                                                       |
| port_id         | b7d4c968-afb2-4709-9f64-0e7853209673                                                          |
| revision_number | 1                                                                                             |
| status          | DOWN                                                                                          |
| sub_ports       | port_id='c7dd9ac2-730a-4476-b93f-08a6f31367d4', segmentation_id='1', segmentation_type='vlan' |
|                 | port_id='3ba8b2d5-fe03-4d2a-bcd7-abeee2121739', segmentation_id='2', segmentation_type='vlan' |
| tenant_id       | f332909670c841abb78c2e30e8c50c68                                                              |
| updated_at      | 2016-11-15T01:58:13Z                                                                          |
+-----------------+-----------------------------------------------------------------------------------------------+
  1. 检查当前创建的 trunk 以及相关 subport 信息
bash
# openstack network trunk list
+--------------------------------------+---------+--------------------------------------+-------------+
| ID                                   | Name    | Parent Port                          | Description |
+--------------------------------------+---------+--------------------------------------+-------------+
| a5f0be95-67bd-4dea-b321-b4cad753b91d | mytrunk | b7d4c968-afb2-4709-9f64-0e7853209673 |             |
+--------------------------------------+---------+--------------------------------------+-------------+

# openstack network trunk show mytrunk
+-----------------+-----------------------------------------------------------------------------------------------+
| Field           | Value                                                                                         |
+-----------------+-----------------------------------------------------------------------------------------------+
| admin_state_up  | UP                                                                                            |
| created_at      | 2016-11-15T01:58:13Z                                                                          |
| description     |                                                                                               |
| id              | a5f0be95-67bd-4dea-b321-b4cad753b91d                                                          |
| name            | mytrunk                                                                                       |
| port_id         | b7d4c968-afb2-4709-9f64-0e7853209673                                                          |
| revision_number | 1                                                                                             |
| status          | DOWN                                                                                          |
| sub_ports       | port_id='c7dd9ac2-730a-4476-b93f-08a6f31367d4', segmentation_id='1', segmentation_type='vlan' |
|                 | port_id='3ba8b2d5-fe03-4d2a-bcd7-abeee2121739', segmentation_id='2', segmentation_type='vlan' |
| tenant_id       | f332909670c841abb78c2e30e8c50c68                                                              |
| updated_at      | 2016-11-15T01:58:13Z                                                                          |
+-----------------+-----------------------------------------------------------------------------------------------+
  1. 查询 subport1 的 mac 地址 (mac 地址为: fa:16:3e:cc:b9:27), 以及 subport2 的 mac 地址(mac 地址为: fa:16:3e:25:d2:c9)
bash
# openstack port show subport1
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| id                    | c7dd9ac2-730a-4476-b93f-08a6f31367d4 |
| mac_address           | fa:16:3e:cc:b9:27                    |
| name                  | subport1                             |
...
+-----------------------+--------------------------------------+

# openstack port show subport2
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| id                    | 3ba8b2d5-fe03-4d2a-bcd7-abeee2121739 |
| mac_address           | fa:16:3e:25:d2:c9                    |
| name                  | subport2                             |
...
+-----------------------+--------------------------------------+
  1. 创建虚拟机, 网卡设置为 parent_port:trunkparent
bash
# openstack server create --image 5c43aefd-7256-4fd8-b641-72a5a0945666 --flavor 3--nic port-id=trunkparent trunk-vm1

虚拟机创建成功后, parent_port 会绑定成功, 底层 trunk 设备也会被创建。

  1. 虚拟机中配置 vlan 接口, 并根据 subport1/subport2 的 mac 地址, 配置 VLAN 接口。

subport1 的 vlan id 为 1, mac 地址为: fa:16:3e:cc:b9:27

subport2 的 vlan id 为 2, mac 地址为: fa:16:3e:25:d2:c9

text
VM# sudo ip link add link eth0 eth0.1 address fa:16:3e:cc:b9:27 broadcast ff:ff:ff:ff:ff:ff type vlan id 1
VM# sudo ip link add link eth0 eth0.2 address fa:16:3e:25:d2:c9 broadcast ff:ff:ff:ff:ff:ff type vlan id 2

VM# sudo ip link set eth0.1 up
VM# sudo ip link set eth0.2 up
  1. 通过执行对接口 eth0.1 和 eth0.2 上执行 dhclient, 可以使 eth0.1, eth0.2 得到对应虚拟网络的 ip 地址。
text
VM# sudo dhclient eth0.1
VM# sudo dhclient eth0.2

虚拟机内执行 dhclient 获取 VLAN 子接口 IP 地址输出结果

  1. VM 中通过 eth0.1 ping dhcp 端口来验证 vlan tags。
text
VM# ping -I eth0.1 10.0.5.2

虚拟机通过 eth0.1 子接口验证 VLAN 标签连通性 ping 输出

qvo 上抓包, 能够抓到报文带 vlan id=1:

bash
# tcpdump -en -i qvob7d4c968-af
tcpdump: WARNING: qvob7d4c968-af: no IPv4 address assigned
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on qvob7d4c968-af, link-type EN10MB (Ethernet), capture size 65535 bytes
17:38:56.411075 fa:16:3e:cc:b9:27 > fa:16:3e:cc:4b:83, ethertype 802.1Q (0x8100), length 102: vlan 1, p 0, ethertype IPv4, 10.0.5.7 > 10.0.5.2: ICMP echo request, id 15784, seq 180, length 64
17:38:56.411123 fa:16:3e:cc:4b:83 > fa:16:3e:cc:b9:27, ethertype 802.1Q (0x8100), length 102: vlan 1, p 0, ethertype IPv4, 10.0.5.2 > 10.0.5.7: ICMP echo reply, id 15784, seq 180, length 64
17:38:57.413020 fa:16:3e:cc:b9:27 > fa:16:3e:cc:4b:83, ethertype 802.1Q (0x8100), length 102: vlan 1, p 0, ethertype IPv4, 10.0.5.7 > 10.0.5.2: ICMP echo request, id 15784, seq 181, length 64

VLAN aware VMs 底层原理

在使用 VLAN aware VMs 之前, 传统 Openstack VM vif 和 neutron 端口, 网络之间的关系如下,虚拟机(openstack instance)通过 eth0/eth1/eth2 这类 vNIC 虚拟网卡和计算节点上的 port 相联, port 再添加到不同虚拟网络中去进行 2 层互联。

传统 OpenStack VM vif 与 Neutron 端口和网络拓扑关系

传统 Openstack VM vif 和 neutron 端口、网络之间的关系

在使用了 vlan-aware-vms 功能后, 虚拟机中的网络接口将会配成 vlan 接口方式, 并通过 1 个 vNIC 连接到计算节点的 parent_port 上, parent_port 将把不同 tagged 的报文发送给不同的 vlan subport, 并和虚拟网络相连接。其中 parent_port 可用来收发 untagged VLAN 报文, 而 subports(child_ports)用来收发 VLAN tagged 的报文。 如下图, 这样可以省去在 VM 上添加多个网络端口的动作:

使用 VLAN aware VMs 特性后的 VM vif 与 Trunk 子端口拓扑关系

使用了 vlan-aware-vms 功能后, VM vif 和 neutron 端口、网络之间的关系

目前, openstack newton 中实现了 ovs 和 linuxbridge 两种 trunk 的驱动实现方式, 我们看一下 OVS 的驱动实现原理, linuxbridge 实现方式类似。

OVS trunk 驱动实现原理:

在使用 trunk 之前, 我们的 ovs 2 层网络和报文走向是这样子的(左图):

text
VM中eth0 -> tap -> qbr -> qvb-> qvo -> br-int -> br-tun ...

在使用 trunk 之后, qvo(trunkport)挂到了新的 ovs bridge:tbr- 上, 我们的 ovs 2 层网络和报文走向变成了这样子(右图)。

eth0(trunk port, 不带 vlan tag), 通过 tbr-上的 ovs port: tpt (不设置 vlan tag), 和 tpi (为 patch-port 对)相连, tpi 最终连接到了 br-int 上。

eth0.1(subport, 带 vlan:1), 通过 tbr-上的 ovs port: spt (配置 vlan tag: 1), 和 spi (为 patch-port 对)相连, spi 最终连接到了 br-int 上。

eth0.2 同上。

其中 ovs bridge: tbr-XXX 中下的流表为: 匹配所有报文,action=NORMAL, 即传统的 2 层 bridge 模式。

qvo 等 ovs port 默认为 trunk port(可收发带 vlan 报文, 并且出去后不剥掉 vlan tag), 而 tpt/tpi 为 access port(一般进来和出去为 untagged 报文, 进到网桥/交换机后按照端口上的 tag 配置进行 vlan 划分和处理)。

缩写解释:

yaml
tbr: trunk bridge
tpt: trunk port trunk-end (即和trunk bridge连接的端口)
tpi: trunk port integration-end(即和br-int连接的端口)
spt: subport trunk-end (即和trunk bridge连接的端口)
spi: subport integration end (即和br-int连接的端口)

使用 OVS Trunk 驱动前后的底层网桥拓扑与报文走向对比

使用 ovs trunk 前后, 底层设备和报文走向

Linux trunk 驱动实现原理:

通过 VM 的 tap 口上创建 vlan 子接口实现。

例如: parent_port 为 tap9965461c-91, subport1 为: tapca4c78e2-66@tap9965461c-91,subport2 为: tapbf54d831-fe@tap9965461c-91。

bash
# ip -d link show | grep 9965 -C 6
39: tap9965461c-91: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 65486 qdisc pfifo_fast master brq7412a74a-7b state UNKNOWN mode DEFAULT group default qlen 500
    link/ether fe:16:3e:90:7a:ca brd ff:ff:ff:ff:ff:ff promiscuity 2
    tun
40: tapbf54d831-fe@tap9965461c-91: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 65486 qdisc noqueue state UP mode DEFAULT group default
    link/ether fa:16:3e:d5:55:a5 brd ff:ff:ff:ff:ff:ff promiscuity 0
    vlan protocol 802.1Q id 2 <REORDER_HDR>
41: tapca4c78e2-66@tap9965461c-91: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 65486 qdisc noqueue state UP mode DEFAULT group default
    link/ether fa:16:3e:b5:5b:a1 brd ff:ff:ff:ff:ff:ff promiscuity 0
    vlan protocol 802.1Q id 1 <REORDER_HDR>

parent_port 所属网络为 net0 (uuid: 7412a74a-7b04-4c45-9491-b8929cf1fcf4), 则其对应的 linux bridge 为: brq7412a74a-7b

bash
# brctl show brq7412a74a-7b
bridge name                bridge id           STP enabled              interfaces
brq7412a74a-7b      8000.5a63a569d91c                 no              tap8f6a9f8b-8d
                                                                    tap9965461c-91
                                                                          vxlan-100

使用 Linux Bridge Trunk 驱动的底层设备与报文走向图

使用 linuxbridge trunk 前后, 底层设备和报文走向

代码:

trunk 驱动支持 ovs 和 linux bridge, 代码主要在 neutron/services/trunk 目录下:

Neutron Trunk 插件驱动代码目录结构与实现模块

trunk 驱动

CLI 命令行和 API 接口

Neutron Trunk CLI 命令行与 REST API 接口汇总图