天天看點

openstack neutron GRE模式GRE 模式

GRE 模式

openstack neutron GRE模式GRE 模式

在OpenStack中,所有網絡有關的邏輯管理均在Network節點中實作,例如DNS、DHCP以及路由等。Compute節點上隻需要對所部屬的虛拟機提供基本的網絡功能支援,包括隔離不同租戶的虛拟機和進行一些基本的安全政策管理(即security group)。

qbr

在 VM1 中,虛拟機的網卡實際上連接配接到了實體機的一個 TAP 裝置(即 A,常見名稱如 tap-XXX)上,A 則進一步通過VETH pair(A-B)連接配接到網橋 qbr-XXX 的端口 vnet0(端口 B)上,之後再通過 VETH pair(C-D)連到br-int網橋上。一般C的名字格式為 qvb-XXX,而 D 的名字格式為 qvo-XXX。注意它們的名稱除了字首外,後面的 id 都是一樣的,表示位于同一個虛拟機網絡到實體機網絡的連接配接上。

之是以 TAP 裝置 A 沒有直接連接配接到網橋br-int上,是因為 OpenStack 需要通過 iptables 實作 security group 的安全政策功能。目前 openvswitch 并不支援應用 iptables 規則的 Tap 裝置。

因為 qbr 的存在主要是為了輔助 iptables 來實作 security group功能,有時候也被稱為

安全網橋

br-int

一個典型的 br-int 的端口如下所示:

# ovs-vsctl show
Bridge br-int
    Port "qvo-XXX"
        tag: 1
        Interface "qvo-XXX"
    Port patch-tun
        Interface patch-tun
            type: patch
            options: {peer=patch-int}
    Port br-int
        Interface br-int
            type: internal
           

其中,

  • br-int 為内部端口。
  • patch-tun(即端口E,端口号為1)連接配接到 br-tun 上,實作到外部網絡的隧道。
  • qvo-XXX(即端口D,端口号為2)帶有 tag1,說明這個口是一個1号 vlan 的 access 端口。虛拟機發出的從該端口到達br-int的網包将被自動帶上vlan tag 1,而其他帶有 vlan tag 1 的網包則可以在去掉 vlan tag 後從該端口發出(即 vlan access 端口)。這個 vlan tag 是用來實作不同網絡互相隔離的,比如租戶建立一個網絡(neutron net-create),則會被配置設定一個唯一的 vlan tag。

br-int 在 GRE 模式中作為一個 NORMAL 交換機使用,是以有效規則隻有一條正常轉發。如果兩個在同一主機上的 vm 屬于同一個 tenant 的(同一個 vlan tag),則它們之間的通信隻需要經過 br-int 即可。

# ovs-ofctl dump-flows br-int
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=10727.864s, table=0, n_packets=198, n_bytes=17288, idle_age=13, priority=1 actions=NORMAL
           

br-tun

一個典型的 br-tun 上的端口類似:

Bridge br-tun
        Port patch-int
            Interface patch-int
                type: patch
                options: {peer=patch-tun}
        Port "gre-1"
            Interface "gre-1"
                type: gre
                options: {in_key=flow, local_ip="10.0.0.101", out_key=flow, remote_ip="10.0.0.100"}
        Port br-tun
            Interface br-tun
                type: internal
           

其中,

  • patch-int(即端口 F,端口号為1)是連接配接到 br-int 上的 veth pair 的端口
  • gre-1 端口(即端口 G,端口号為2)對應vm到外面的隧道。gre-1 端口是虛拟 gre 端口,當網包發送到這個端口的時候,會經過核心封包,然後從 10.0.0.101 發送到 10.0.0.100,即從本地的實體網卡(10.0.0.101)發出。

br-tun将帶有 vlan tag 的 vm 跟外部通信的流量轉換到對應的 gre 隧道,這上面要實作主要的轉換邏輯,規則要複雜,一般通過多張表來實作。

典型的轉發規則為:

# ovs-ofctl dump-flows br-tun
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=10970.064s, table=0, n_packets=189, n_bytes=16232, idle_age=16, priority=1,in_port=1 actions=resubmit(,1)
 cookie=0x0, duration=10906.954s, table=0, n_packets=29, n_bytes=5736, idle_age=16, priority=1,in_port=2 actions=resubmit(,2)
 cookie=0x0, duration=10969.922s, table=0, n_packets=3, n_bytes=230, idle_age=10962, priority=0 actions=drop
 cookie=0x0, duration=10969.777s, table=1, n_packets=26, n_bytes=5266, idle_age=16, priority=0,dl_dst=00:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,20)
 cookie=0x0, duration=10969.631s, table=1, n_packets=163, n_bytes=10966, idle_age=21, priority=0,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,21)
 cookie=0x0, duration=688.456s, table=2, n_packets=29, n_bytes=5736, idle_age=16, priority=1,tun_id=0x1 actions=mod_vlan_vid:1,resubmit(,10)
 cookie=0x0, duration=10969.488s, table=2, n_packets=0, n_bytes=0, idle_age=10969, priority=0 actions=drop
 cookie=0x0, duration=10969.343s, table=3, n_packets=0, n_bytes=0, idle_age=10969, priority=0 actions=drop
 cookie=0x0, duration=10969.2s, table=10, n_packets=29, n_bytes=5736, idle_age=16, priority=1 actions=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
 cookie=0x0, duration=682.603s, table=20, n_packets=26, n_bytes=5266, hard_timeout=300, idle_age=16, hard_age=16, priority=1,vlan_tci=0x0001/0x0fff,dl_dst=fa:16:3e:32:0d:db actions=load:0->NXM_OF_VLAN_TCI[],load:0x1->NXM_NX_TUN_ID[],output:2
 cookie=0x0, duration=10969.057s, table=20, n_packets=0, n_bytes=0, idle_age=10969, priority=0 actions=resubmit(,21)
 cookie=0x0, duration=688.6s, table=21, n_packets=161, n_bytes=10818, idle_age=21, priority=1,dl_vlan=1 actions=strip_vlan,set_tunnel:0x1,output:2
 cookie=0x0, duration=10968.912s, table=21, n_packets=2, n_bytes=148, idle_age=689, priority=0 actions=drop
           

表 0

其中,表 0 中有 3 條規則:從内部端口 1(即patch-int)來的,扔到表 1,從外部端口2(即 gre-1)來的,扔到表2。

cookie=0x0, duration=10970.064s, table=0, n_packets=189, n_bytes=16232, idle_age=16, priority=1,in_port=1 actions=resubmit(,1)
 cookie=0x0, duration=10906.954s, table=0, n_packets=29, n_bytes=5736, idle_age=16, priority=1,in_port=2 actions=resubmit(,2)
 cookie=0x0, duration=10969.922s, table=0, n_packets=3, n_bytes=230, idle_age=10962, priority=0 actions=drop
           

表 1

表 1 處理内部過來的網包,有 2 條規則:如果是單點傳播(00:00:00:00:00:00/01:00:00:00:00:00),則扔到表 20;如果是多點傳播等(01:00:00:00:00:00/01:00:00:00:00:00),則扔到表 21。

cookie=0x0, duration=10969.777s, table=1, n_packets=26, n_bytes=5266, idle_age=16, priority=0,dl_dst=00:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,20)
 cookie=0x0, duration=10969.631s, table=1, n_packets=163, n_bytes=10966, idle_age=21, priority=0,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,21)
           

表 2

表 2 處理外部過來的包。有 2 條規則:如果是 tunnel 1(合法的 tunnel id)的網包,則修改其 vlan id 為1,并扔到表 10 學習記錄來源;非 tunnel 1(非法的 tunnel id)的網包,則丢棄。

cookie=0x0, duration=688.456s, table=2, n_packets=29, n_bytes=5736, idle_age=16, priority=1,tun_id=0x1 actions=mod_vlan_vid:1,resubmit(,10)
 cookie=0x0, duration=10969.488s, table=2, n_packets=0, n_bytes=0, idle_age=10969, priority=0 actions=drop
           

表 3

表 3 隻有 1 條規則:丢棄。

表 10

表 10 負責學習。有一條規則,基于 learn 行動來建立反向(内部網包從 gre 端口發出去)的規則。learn 行動并非标準的 openflow 行動,是 openvswitch 自身的擴充行動,這個行動可以根據流内容動态來修改流表内容。

這條規則首先建立了一條新的流(該流對應 vm 從 br-tun 的 gre 端口發出的規則):其中 table=20 表示規則添加在表 20;NXM_OF_VLAN_TCI[0..11] 表示比對包自帶的v lan id;NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[] 表示 L2 目标位址需要比對目前包的 L2 源位址;load:0->NXM_OF_VLAN_TCI[],去掉vlan,load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[],添加 tunnel 号為原始 tunnel 号;output:NXM_OF_IN_PORT[],發出端口為原始包抵達的端口。

向表 20 添加完規則後,最後将比對的目前網包從端口 1(即 patch-int)發出。

cookie=0x0, duration=10969.2s, table=10, n_packets=29, n_bytes=5736, idle_age=16, priority=1 actions=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
           

表 20

表 20 中有兩條規則,其中第一條即表 10 中規則利用 learn 行動建立的内部向外部發包的流表項,第 2 條送出其他流到表 21。

cookie=0x0, duration=682.603s, table=20, n_packets=26, n_bytes=5266, hard_timeout=300, idle_age=16, hard_age=16, priority=1,vlan_tci=0x0001/0x0fff,dl_dst=fa:16:3e:32:0d:db actions=load:0->NXM_OF_VLAN_TCI[],load:0x1->NXM_NX_TUN_ID[],output:2
 cookie=0x0, duration=10969.057s, table=20, n_packets=0, n_bytes=0, idle_age=10969, priority=0 actions=resubmit(,21)
           

表21有2條規則,第一條是比對所有目标vlan為1的網包,去掉vlan,然後從端口2(gre 端口)發出。第二條是丢棄。

cookie=0x0, duration=688.6s, table=21, n_packets=161, n_bytes=10818, idle_age=21, priority=1,dl_vlan=1 actions=strip_vlan,set_tunnel:0x1,output:2
 cookie=0x0, duration=10968.912s, table=21, n_packets=2, n_bytes=148, idle_age=689, priority=0 actions=drop
           

這些規則所組成的整體轉發邏輯如下圖所示。

openstack neutron GRE模式GRE 模式

繼續閱讀