您的位置:首页 > 理论基础 > 计算机网络

OpenStack 网络实现:VXLAN 模式

2015-11-10 17:09 543 查看
VXLAN模式下,网络的架构跟GRE模式类似,所不同的是,不同节点之间通过VXLAN隧道互通,即虚拟化层是采用的VXLAN协议。

基本结构如下图所示。



其中,节点网络配置如下所示,注意数据网络接口需要IP地址,因为是隧道协议需要底下的三层转发支持。

控制节点

eth0:9.186.100.77/24作为管理网络(同时也是公共网络)。

eth1:10.0.100.77/24作为数据网络接口。

计算节点

eth0:9.186.100.88/24作为管理网络(同时也是公共网络)。

eth1:10.0.100.88/24作为数据网络接口。

计算节点

计算节点上运行着虚拟机。如果不启用DVR特性,则所有的网络相关的服务,都在网络节点上进行。即计算节点上的网络只需要实现二层转发即可。

br-int

集成网桥br-int规则比较简单,作为一个正常的二层交换机使用。无论下面虚拟化层是哪种技术实现,集成网桥是看不到的,只知道根据vlan和mac进行转发。

所连接接口除了从安全网桥过来的qvo-xxx(每个虚拟机会有一个),就是一个往外的patch-tun接口,连接到br-tun网桥。

其中,qvo-xxx接口上会为每个网络分配一个内部vlan号,比如这里是同一个网络启动了两台虚机,所以tag都为1。

[Bashshell]纯文本查看复制代码

01
Bridge
br-int
02
fail_mode:
secure
03
Port
br-int
04
Interface
br-int
05
type
:
internal
06
Port
"qvoc4493802-43"
07
tag:
1
08
Interface
"qvoc4493802-43"
09
Portpatch-tun
10
Interfacepatch-tun
11
type
:
patch
12
options:
{peer=patch-int}
13
Port
"qvof47c62b0-db"
14
tag:
1
15
Interface
"qvof47c62b0-db"
转发规则表0中是对所有包进行NORMAL,表23中是所有包直接丢弃(是否后面将安全组规则在这里实现?)。

[Bashshell]纯文本查看复制代码

1
$
sudo

ovs-ofctldump-flowsbr-int
2
NXST_FLOW
reply(xid=0x4):
3
cookie=0x0,
duration=52889.682s,table=0,n_packets=161,n_bytes=39290,idle_age=13,priority=1actions=NORMAL
4
cookie=0x0,
duration=52889.451s,table=23,n_packets=0,n_bytes=0,idle_age=52889,priority=0actions=drop
br-tun

br-tun作为虚拟化层网桥,规则就要复杂一些。要将内部过来的网包进行合理甄别,内部带着正确vlantag过来的,从正确的tunnel扔出去;外面带着正确tunnel号过来的,要改到对应的内部vlantag扔到里面。

[Bashshell]纯文本查看复制代码

01
Bridge
br-tun
02
fail_mode:
secure
03
Port
"vxlan-0a00644d"
04
Interface
"vxlan-0a00644d"
05
type
:
vxlan
06
options:
{df_default=
"true"
,
in_key=flow,local_ip=
"10.0.100.88"
,
out_key=flow,remote_ip=
"10.0.100.77"
}
07
Portpatch-int
08
Interfacepatch-int
09
type
:
patch
10
options:
{peer=patch-tun}
11
Portbr-tun
12
Interfacebr-tun
13
type
:
internal
其中,端口br-tun是内部端口,vxlan-0a00644d这样的端口是向其它节点发包时候的VXLAN隧道端点,patch-int端口通过一条管道连接到br-int上的patch-tun端口。

正常情况下,虚拟机的流量经过br-int转发,经过patch-tun端口,抵达patch-int端口,从而到达br-tun网桥,该网桥根据自身规则将合适的网包经过VXLAN隧道送出去。

[Bashshell]纯文本查看复制代码

01
$
sudo


ovs-ofctldump-flowsbr-tun
02
NXST_FLOW
reply(xid=0x4):
03
cookie=0x0,
duration=329.194s,table=0,n_packets=31,n_bytes=2906,idle_age=29,priority=1,in_port=1actions=resubmit(,2)
04
cookie=0x0,
duration=325.847s,table=0,n_packets=14,n_bytes=1591,idle_age=33,priority=1,in_port=2actions=resubmit(,4)
05
cookie=0x0,
duration=328.954s,table=0,n_packets=6,n_bytes=480,idle_age=321,priority=0actions=drop
06
cookie=0x0,
duration=328.712s,table=2,n_packets=9,n_bytes=694,idle_age=33,priority=0,dl_dst=00:00:00:00:00:00/01:00:00:00:00:00actions=resubmit(,20)
07
cookie=0x0,
duration=328.465s,table=2,n_packets=22,n_bytes=2212,idle_age=29,priority=0,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00actions=resubmit(,22)
08
cookie=0x0,
duration=328.223s,table=3,n_packets=0,n_bytes=0,idle_age=328,priority=0actions=drop
09
cookie=0x0,
duration=50.703s,table=4,n_packets=12,n_bytes=1451,idle_age=33,priority=1,tun_id=0x3e9actions=mod_vlan_vid:1,resubmit(,10)
10
cookie=0x0,
duration=327.979s,table=4,n_packets=2,n_bytes=140,idle_age=94,priority=0actions=drop
11
cookie=0x0,
duration=327.742s,table=10,n_packets=12,n_bytes=1451,idle_age=33,priority=1actions=learn(table=20,hard_timeout=300,priority=1,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:0->NXM_OF_VLAN_TCI[],load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[],output:NXM_OF_IN_PORT[]),output:1
12
cookie=0x0,
duration=38.551s,table=20,n_packets=9,n_bytes=694,hard_timeout=300,idle_age=33,hard_age=33,priority=1,vlan_tci=0x0001/0x0fff,dl_dst=fa:16:3e:83:95:faactions=load:0->NXM_OF_VLAN_TCI[],load:0x3e9->NXM_NX_TUN_ID[],output:2
13
cookie=0x0,
duration=327.504s,table=20,n_packets=0,n_bytes=0,idle_age=327,priority=0actions=resubmit(,22)
14
cookie=0x0,
duration=50.94s,table=22,n_packets=11,n_bytes=1334,idle_age=29,dl_vlan=1actions=strip_vlan,set_tunnel:0x3e9,output:2
15
cookie=0x0,
duration=327.261s,table=22,n_packets=10,n_bytes=808,idle_age=51,priority=0actions=drop
这些规则组成如下图所示的转发逻辑。



表0

先看table0中的规则

[Bashshell]纯文本查看复制代码

1
cookie=0x0,
duration=329.194s,table=0,n_packets=31,n_bytes=2906,idle_age=29,priority=1,in_port=1actions=resubmit(,2)
2
cookie=0x0,
duration=325.847s,table=0,n_packets=14,n_bytes=1591,idle_age=33,priority=1,in_port=2actions=resubmit(,4)
3
cookie=0x0,
duration=328.954s,table=0,n_packets=6,n_bytes=480,idle_age=321,priority=0actions=drop
从1端口(patch-int)进来的网包,扔给表2处理,从2端口(vxlan-0a00644d)进来的网包,扔给表4处理。即一个处理来自内部vm的,一个处理来自外面的vxlan隧道的。
表2

对于内部包,表2中规则为

[Bashshell]纯文本查看复制代码

1
cookie=0x0,
duration=53316.397s,table=2,n_packets=0,n_bytes=0,idle_age=53316,priority=0,dl_dst=00:00:00:00:00:00/01:00:00:00:00:00actions=resubmit(,20)
2
cookie=0x0,
duration=53316.162s,table=2,n_packets=161,n_bytes=39562,idle_age=422,priority=0,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00actions=resubmit(,22)
即里面过来的单播包,扔给表20处理;多播和广播包,扔给表22处理。
表3

丢弃所有包。

[Bashshell]纯文本查看复制代码

1
cookie=0x0,
duration=328.223s,table=3,n_packets=0,n_bytes=0,idle_age=328,priority=0actions=drop
表4

对于外部来的数据,表4中规则为

[Bashshell]纯文本查看复制代码

1
cookie=0x0,
duration=50.703s,table=4,n_packets=12,n_bytes=1451,idle_age=33,priority=1,tun_id=0x3e9actions=mod_vlan_vid:1,resubmit(,10)
2
cookie=0x0,
duration=327.979s,table=4,n_packets=2,n_bytes=140,idle_age=94,priority=0actions=drop
匹配给定的tunnel号,添加对应的vlan号,扔给表10去学习一下后扔到br-int网桥。
表10

[Bashshell]纯文本查看复制代码

1
cookie=0x0,
duration=327.742s,table=10,n_packets=12,n_bytes=1451,idle_age=33,priority=1actions=learn(table=20,hard_timeout=300,priority=1,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:0->NXM_OF_VLAN_TCI[],load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[],output:NXM_OF_IN_PORT[]),output:1
主要作用是学习外部(从tunnel)进来的包,往表20中添加对返程包的正常转发规则,并且从patch-int扔给br-int。

使用了openvswitch的learn动作。该动作能根据处理的流来动态修改其它表中的规则。

具体来看learn规则。

table=20说明是修改表20中的规则,后面是添加的规则内容;

NXM_OF_VLAN_TCI[0..11],匹配跟当前流同样的VLAN头,其中NXM是NiciraExtensibleMatch的缩写;

NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],包的目的mac跟当前流的源mac匹配;

load:0->NXM_OF_VLAN_TCI[],将vlan号改为0;

load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[],将tunnel号修改为当前的tunnel号;

output:NXM_OF_IN_PORT[],从当前入口发出。

表20

[Bashshell]纯文本查看复制代码

1
cookie=0x0,
duration=38.551s,table=20,n_packets=9,n_bytes=694,hard_timeout=300,idle_age=33,hard_age=33,priority=1,vlan_tci=0x0001/0x0fff,dl_dst=fa:16:3e:83:95:faactions=load:0->NXM_OF_VLAN_TCI[],load:0x3e9->NXM_NX_TUN_ID[],output:2
2
cookie=0x0,
duration=327.504s,table=20,n_packets=0,n_bytes=0,idle_age=327,priority=0actions=resubmit(,22)
其中,第一条规则就是表10学习来的结果。对于vlan号为1,目标mac是fa:16:3e:83:95:fa(之前,我们从虚拟机内ping10.0.0.1,这个mac作为源mac从tunnel来过)的网包,去掉vlan号,添加当时的vxlan号,并从tunnel发出。

对于没学习到规则的网包,则扔给表22处理。
表22

[Bashshell]纯文本查看复制代码

1
cookie=0x0,
duration=50.94s,table=22,n_packets=11,n_bytes=1334,idle_age=29,dl_vlan=1actions=strip_vlan,set_tunnel:0x3e9,output:2
2
cookie=0x0,
duration=327.261s,table=22,n_packets=10,n_bytes=808,idle_age=51,priority=0actions=drop
表22检查如果vlan号正确,则去掉vlan头后从tunnel扔出去
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: