OpenStack 網路總結之:理解GRE隧道的工作流程
文章背景
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的規則會被修改成下面的樣子:
- #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 print?- # ipnetns
- qdhcp-88b1609c-68e0-49ca-a658-f1edff54a264
- qrouter-2d214fde-293c-4d64-8062-797f80ae2d8f
以qdhcp開頭的記錄是私有網路的名稱空間,可以通過執行neutron net-list查到與之對應的網路記錄
以qrouter開頭的記錄是路由的名稱空間,可以通過執行neutron router-list 查到對應的路由記錄
可以通過使用ip netnsexec command 的方式在一個名稱空間內執行一些命令,例如想要檢視DHCP名稱空間的介面配置
[plain] view plain copy<div style="position: absolute; left: 489px; top: 6137px; width: 27px; height: 15px