OpenStack 网络总结之:理解GRE隧道的工作流程
Posted 张某人ER
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenStack 网络总结之:理解GRE隧道的工作流程相关的知识,希望对你有一定的参考价值。
原文地址:http://blog.csdn.net/eric_sunah/article/details/38982063
源文档 <http://openstack.redhat.com/Networking_in_too_much_detail>
文章背景
Openstack的网络配置复杂多样,本文讲述的流程只符合以下场景:
- 网络类型为GRE隧道
- 单独的网络控制节点;
流程介绍
下面是简单的流程图
下面是各个部分包含的PORT
下面章节的名称中会包含图中关键点的编号
计算节点:实例网络 (A,B,C)
所有发出的数据包都是从实例的eth0开始的,它连接到tap设备,tap设备连接到Linux的网桥设备qbr。从图中可以看出tap设备没有直接连接到集成网桥br-int,而是通过qbr中转了一下,这时为什么了?主要是因为OVS的网桥br-int没有设置iptables规则的功能,但OpenStack又想要(或必须)提供安全组服务,那么就借助了Linux Bridge的功能。虽说OVS的br-int网桥和LinuxBridge都是二层桥,但是为了功能相互弥补,就同时出现了。
通过在计算节点上查看防火墙的规则,可以发现很多规则都是和tap设备相关的
[plain] view plain copy print ?
- # iptables -S | greptap7c7ae61e-05
- -A quantum-openvswi-FORWARD -m physdev --physdev-out tap7c7ae61e-05--physdev-is-bridged -j quantum-openvswi-sg-chain
- -A quantum-openvswi-FORWARD -m physdev --physdev-in tap7c7ae61e-05--physdev-is-bridged -j quantum-openvswi-sg-chain
- -A quantum-openvswi-INPUT -m physdev --physdev-in tap7c7ae61e-05--physdev-is-bridged -j quantum-openvswi-o7c7ae61e-0
- -A quantum-openvswi-sg-chain -m physdev --physdev-out tap7c7ae61e-05--physdev-is-bridged -j quantum-openvswi-i7c7ae61e-0
- -A quantum-openvswi-sg-chain -m physdev --physdev-in tap7c7ae61e-05--physdev-is-bridged -j quantum-openvswi-o7c7ae61e-0
quantum-openvswi-sg-chain是由neutron-managed security groups产生的,quantum-openvswi-o7c7ae61e-0主要用来控制实例发出的outbound消息规则
,quantum-openvswi-i7c7ae61e-0chain 主要用来控制从外部到实例的inbound消息 规则
计算节点: 集成网桥br-int (D,E)
集成网桥(br-int)负责执行从实例接受或发出的流量中vlan 标示的拆封工作,此时结算节点上br-int的情况应该类似于
[plain] view plain copy print ?
- #ovs-vsctl show
- Bridge br-int
- Port"qvo7c7ae61e-05"
- tag: 1
- Interface "qvo7c7ae61e-05"
- Port patch-tun
- Interface patch-tun
- type: patch
- options:peer=patch-int
- Port br-int
- Interface br-int
- type: internal
接口qvo7c7ae61e-05与qvb7c7ae61e-05是一对接口,它们负责将Linux网桥的流量传输到br-int上,qvo上的tag:1是一个接入端口,这个端口被挂到了VLAN1上,从实例发出的流量会被赋上VLAN ID 1的标示,发往该实例的流量也先被拆掉VLAN 1的标示,每个不同的网络会被赋予不同的VLAN ID.
接口 patch-tun把br-int连接到隧道桥( br-tun)上.
计算节点: 隧道桥 br-tun(F,G)
隧道桥主要负责把br-int中带有vlan标示的流量转换到GRE隧道中,实际的转换工作主要是由br-tun中OpenFlow规则来完成的,在创建实例之前openflow的规则大概如下:
[plain] view plain copy print ?
- #ovs-ofctl dump-flows br-tun
- NXST_FLOW reply (xid=0x4):
- cookie=0x0, duration=871.283s, table=0,n_packets=4, n_bytes=300, idle_age=862, priority=1 actions=drop
目前只有一条规则,这条规则会让br-tun丢掉所有的流量,当你在计算节点上启动一个实例后,openflow的规则会被修改成下面的样子:
[plain] view plain copy print ?
- #ovs-ofctl dump-flows br-run
- NXST_FLOW reply (xid=0x4):
- cookie=0x0, duration=422.158s, table=0,n_packets=2, n_bytes=120, idle_age=55,priority=3,tun_id=0x2,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=mod_vlan_vid:1,output:1
- cookie=0x0, duration=421.948s, table=0,n_packets=64, n_bytes=8337, idle_age=31,priority=3,tun_id=0x2,dl_dst=fa:16:3e:dd:c1:62 actions=mod_vlan_vid:1,NORMAL
- cookie=0x0, duration=422.357s, table=0,n_packets=82, n_bytes=10443, idle_age=31, priority=4,in_port=1,dl_vlan=1actions=set_tunnel:0x2,NORMAL
- cookie=0x0, duration=1502.657s, table=0,n_packets=8, n_bytes=596, idle_age=423, priority=1 actions=drop
通常,这些规则负责映射br-int使用的VLAN ID 1,以及GRE 隧道使用的tunnel id2
第一条规则
[plain] view plain copy print ?
- cookie=0x0, duration=422.158s, table=0,n_packets=2, n_bytes=120, idle_age=55,priority=3,tun_id=0x2,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00actions=mod_vlan_vid:1,output:1
匹配的条件为tunnel id2 (tun_id=0x2), VLAN ID 1 (actions=mod_vlan_vid:1),以及从端口1发出的流量
通过使用ovs-ofctlshow br-tun 可以看出端口1是patch-int
[plain] view plain copy print ?
- #ovs-ofctl show br-tun
- OFPT_FEATURES_REPLY (xid=0x2): dpid:0000068df4e44a49
- n_tables:254, n_buffers:256
- capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATSARP_MATCH_IP
- actions: OUTPUT SET_VLAN_VID SET_VLAN_PCP STRIP_VLAN SET_DL_SRC SET_DL_DSTSET_NW_SRC SET_NW_DST SET_NW_TOS SET_TP_SRC SET_TP_DST ENQUEUE
- 1(patch-int):addr:46:3d:59:17:df:62
- config: 0
- state: 0
- speed: 0 Mbps now, 0 Mbps max
- 2(gre-2):addr:a2:5f:a1:92:29:02
- config: 0
- state: 0
- speed: 0 Mbps now, 0 Mbpsmax
- LOCAL(br-tun):addr:06:8d:f4:e4:4a:49
- config: 0
- state: 0
- speed: 0 Mbps now, 0 Mbpsmax
- OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0
有一条规则是
[plain] view plain copy print ?
- cookie=0x0, duration=422.357s, table=0,n_packets=82, n_bytes=10443, idle_age=31, priority=4,in_port=1,dl_vlan=1actions=set_tunnel:0x2,NORMAL
匹配的条件是(in_port=1) , VLAN ID 1 (dl_vlan=1) ,如果匹配就在发出GRE隧道之前,设置 tunnel id 为 2 (actions=set_tunnel:0x2) .
网络节点:隧道桥(br-tun) (H,I)
当流量通过连接到br-tun的GRE隧道到达网络节点,该节点上隧道桥的flowtable与计算节点上的非常相似
[plain] view plain copy print ?- # ovs-ofctl dump-flowsbr-tun
- NXST_FLOW reply (xid=0x4):
- cookie=0x0, duration=1239.229s, table=0,n_packets=23, n_bytes=4246, idle_age=15,priority=3,tun_id=0x2,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=mod_vlan_vid:1,output:1
- cookie=0x0, duration=524.477s, table=0,n_packets=15, n_bytes=3498, idle_age=10,priority=3,tun_id=0x2,dl_dst=fa:16:3e:83:69:cc actions=mod_vlan_vid:1,NORMAL
- cookie=0x0, duration=1239.157s, table=0,n_packets=50, n_bytes=4565, idle_age=148,priority=3,tun_id=0x2,dl_dst=fa:16:3e:aa:99:3c actions=mod_vlan_vid:1,NORMAL
- cookie=0x0, duration=1239.304s, table=0,n_packets=76, n_bytes=9419, idle_age=10, priority=4,in_port=1,dl_vlan=1actions=set_tunnel:0x2,NORMAL
- cookie=0x0, duration=1527.016s, table=0,n_packets=12, n_bytes=880, idle_age=527, priority=1 actions=drop
和在计算节点上一样,第一条规则映射tunnel ID 2 上的多路广播流量到VLAN 1
As on thecompute host, the first rule maps multicast traffic on tunnel ID 2 to VLAN 1.
第二条规则
[plain] view plain copy print ?
- cookie=0x0, duration=524.477s, table=0,n_packets=15, n_bytes=3498, idle_age=10,priority=3,tun_id=0x2,dl_dst=fa:16:3e:83:69:cc actions=mod_vlan_vid:1,NORMAL
流量在隧道上转向fa:16:3e:83:69:cc,这是一个运行在网络命令空间的dnsmasq 进程
...matchestraffic on the tunnel destined for the DHCP server at fa:16:3e:83:69:cc. Thisis a dnsmasq process running inside a network namespace, the details of whichwe will examine shortly.
下一条规则
[plain] view plain copy print ?
- cookie=0x0, duration=1239.157s, table=0,n_packets=50, n_bytes=4565, idle_age=148,priority=3,tun_id=0x2,dl_dst=fa:16:3e:aa:99:3c actions=mod_vlan_vid:1,NORMAL
匹配的流量在tunnel ID2,转向fa:16:3e:aa:99:3c上的router,这个router在另外一个网络命名空间
...matchestraffic on tunnel ID 2 destined for the router at fa:16:3e:aa:99:3c, which isan interface in another network namespace.
下一条规则
[plain] view plain copy print ?
- cookie=0x0, duration=1239.304s, table=0,n_packets=76, n_bytes=9419, idle_age=10, priority=4,in_port=1,dl_vlan=1actions=set_tunnel:0x2,NORMAL
将tunnel id 设置为2
网络节点:整合桥br-int(IJ)
该桥负责将实例连接到网络服务上,例如路由或者是DHCP服务
[plain] view plain copy print ?
- # ovs-vsctl show
- Bridge br-int
- Port patch-tun
- Interface patch-tun
- type: patch
- options:peer=patch-int
- Port"tapf14c598d-98"
- tag: 1
- Interface"tapf14c598d-98"
- Port br-int
- Interface br-int
- type: internal
- Port"tapc2d7dd02-56"
- tag: 1
- Interface"tapc2d7dd02-56"
Br-int通过使用patch接口patch-tun连接到br-tun
Network host: DHCP server (O,P)
每一个启动DHCP的网络都会有一个DHCP服务运行在网络节点上,DHCP服务是一个运行在网络命名空间的dnsmasq实例(网络命名空间(network namespace)是一个Linux kernel设备,该设备允许创建一个独立于宿主机的网络栈(栈中可以包含接口,路由表,防火墙规则等))
可以通过ip netns的命令查看网络命名空间
[plain] view plain copy 防火墙基础之安全策略和GRE隧道
OpenStack 部署总结之:在CentOS 6.5上使用RDO单机安装icehouse(Ml2+GRE)