OpenStack GRE 网络网络介绍

发布时间: 更新时间: 总字数:3240 阅读时间:7m 作者: IP上海 分享 网址

OpenStack的网络配置复杂多样,本文讲述的流程只符合以下场景: 1. 网络类型为GRE隧道; 2. 单独的网络控制节点;

流程介绍

下面是简单的流程图

下面是各个部分包含的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设备相关的

# 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的情况应该类似于

#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的规则大概如下:

#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

第一条规则

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

#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

有一条规则是

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与计算节点上的非常相似

# 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.

第二条规则

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.

下一条规则

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.

下一条规则

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服务

# 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的命令查看网络命名空间

# 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命名空间的接口配置

# ip netns execqdhcp-88b1609c-68e0-49ca-a658-f1edff54a264 ip addr
71: ns-f14c598d-98: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdiscpfifo_fast state UP qlen 1000
    link/ether fa:16:3e:10:2f:03 brdff:ff:ff:ff:ff:ff
    inet 10.1.0.3/24 brd 10.1.0.255 scopeglobal ns-f14c598d-98
    inet6 fe80::f816:3eff:fe10:2f03/64scope link
       valid_lft forever preferred_lftforever

接口ns-f14c598d-98的MAC地址是匹配隧道桥中flowrule中的MAC地址,这个接口通过tap设备连接到bt-int

Port "tapf14c598d-98"
     tag: 1
     Interface"tapf14c598d-98"

可以通过 ps - ef 输出的结果中查到与dnsmasq 关联的命名空间

# ps -fe | grep88b1609c-68e0-49ca-a658-f1edff54a264
nobody   23195     1  0Oct26 ?        00:00:00 dnsmasq--no-hosts --no-resolv --strict-order --bind-interfaces--interface=ns-f14c598d-98 --except-interface=lo--pid-file=/var/lib/quantum/dhcp/88b1609c-68e0-49ca-a658-f1edff54a264/pid--dhcp-hostsfile=/var/lib/quantum/dhcp/88b1609c-68e0-49ca-a658-f1edff54a264/host--dhcp-optsfile=/var/lib/quantum/dhcp/88b1609c-68e0-49ca-a658-f1edff54a264/opts--dhcp-script=/usr/bin/quantum-dhcp-agent-dnsmasq-lease-update --leasefile-ro--dhcp-range=tag0,10.1.0.0,static,120s --conf-file= --domain=openstacklocal
root     23196 23195  0 Oct26 ?        00:00:00 dnsmasq --no-hosts --no-resolv--strict-order --bind-interfaces --interface=ns-f14c598d-98--except-interface=lo--pid-file=/var/lib/quantum/dhcp/88b1609c-68e0-49ca-a658-f1edff54a264/pid--dhcp-hostsfile=/var/lib/quantum/dhcp/88b1609c-68e0-49ca-a658-f1edff54a264/host--dhcp-optsfile=/var/lib/quantum/dhcp/88b1609c-68e0-49ca-a658-f1edff54a264/opts--dhcp-script=/usr/bin/quantum-dhcp-agent-dnsmasq-lease-update --leasefile-ro--dhcp-range=tag0,10.1.0.0,static,120s --conf-file= --domain=openstacklocal
  • 网络节点:路由 (M,N)

Neutron的路由是一个包含路由表以及iptables规则的网络的命名空间,主要负责不同子网间的路由。回到ip netns 的执行结果

# ipnetns
qdhcp-88b1609c-68e0-49ca-a658-f1edff54a264
qrouter-2d214fde-293c-4d64-8062-797f80ae2d8f

通过执行ip netnsexec 命令可以发现与路由命名空间绑定的接口

# ip netns execqrouter-2d214fde-293c-4d64-8062-797f80ae2d8f ip addr
66: qg-d48b49e0-aa: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdiscpfifo_fast state UP qlen 1000
    link/ether fa:16:3e:5c:a2:ac brdff:ff:ff:ff:ff:ff
    inet 172.24.4.227/28 brd 172.24.4.239scope global qg-d48b49e0-aa
    inet 172.24.4.228/32 brd 172.24.4.228scope global qg-d48b49e0-aa
    inet6 fe80::f816:3eff:fe5c:a2ac/64scope link
       valid_lft forever preferred_lftforever
68: qr-c2d7dd02-56: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdiscpfifo_fast state UP qlen 1000
    link/ether fa:16:3e:ea:64:6e brdff:ff:ff:ff:ff:ff
    inet 10.1.0.1/24 brd 10.1.0.255 scopeglobal qr-c2d7dd02-56
    inet6 fe80::f816:3eff:feea:646e/64scope link
       valid_lft forever preferred_lftforever

从图中可以看出qg-d48b49e0-aa,以及 qr-c2d7dd02-56主要是用来连接br-int以及br-ex的

通过观察这个路由的路由表,可以看到有一个外部网络的默认gateway指向qg-d48b49e0-aa

# ip netns execqrouter-2d214fde-293c-4d64-8062-797f80ae2d8f ip route
172.24.4.224/28 dev qg-d48b49e0-aa  protokernel  scope link  src 172.24.4.227
10.1.0.0/24 dev qr-c2d7dd02-56  protokernel  scope link  src 10.1.0.1
default via 172.24.4.225 dev qg-d48b49e0-aa

在路由命名空间中的nat表格主要负责关联实例以及浮动IP,例如当把浮动IP172.24.4.228绑定到实例上后,NAT表看起来应该是下面的样子:

# ip netns execqrouter-2d214fde-293c-4d64-8062-797f80ae2d8f iptables -t nat -S
-P PREROUTING ACCEPT
-P POSTROUTING ACCEPT
-P OUTPUT ACCEPT
-N quantum-l3-agent-OUTPUT
-N quantum-l3-agent-POSTROUTING
-N quantum-l3-agent-PREROUTING
-N quantum-l3-agent-float-snat
-N quantum-l3-agent-snat
-N quantum-postrouting-bottom
-A PREROUTING -j quantum-l3-agent-PREROUTING
-A POSTROUTING -j quantum-l3-agent-POSTROUTING
-A POSTROUTING -j quantum-postrouting-bottom
-A OUTPUT -j quantum-l3-agent-OUTPUT
-Aquantum-l3-agent-OUTPUT -d 172.24.4.228/32 -j DNAT --to-destination 10.1.0.2
-A quantum-l3-agent-POSTROUTING ! -i qg-d48b49e0-aa ! -oqg-d48b49e0-aa -m conntrack ! --ctstate DNAT -j ACCEPT
-A quantum-l3-agent-PREROUTING -d 169.254.169.254/32 -p tcp -m tcp --dport 80-j REDIRECT --to-ports 9697
-Aquantum-l3-agent-PREROUTING -d 172.24.4.228/32 -j DNAT --to-destination10.1.0.2
-A quantum-l3-agent-float-snat -s 10.1.0.2/32 -j SNAT--to-source 172.24.4.228
-A quantum-l3-agent-snat -j quantum-l3-agent-float-snat
-A quantum-l3-agent-snat -s 10.1.0.0/24 -j SNAT --to-source 172.24.4.227
-A quantum-postrouting-bottom -j quantum-l3-agent-snat

主要使用SNAT以及DNAT的规则来映射浮动IP以及固定IP

-Aquantum-l3-agent-OUTPUT -d 172.24.4.228/32 -j DNAT --to-destination 10.1.0.2
-A quantum-l3-agent-PREROUTING -d 172.24.4.228/32 -j DNAT --to-destination10.1.0.2
-A quantum-l3-agent-float-snat -s 10.1.0.2/32 -j SNAT--to-source 172.24.4.228

下面的这条规则主要表示所有outbound的流量都会被NAT从私有网络转换成172.24.4.227,这条规则允许即使实例没有浮动Ip也可以有outbound的连接性

-Aquantum-l3-agent-snat -s 10.1.0.0/24 -j SNAT --to-source 172.24.4.227
  • 网络节点:外部流量 (K,L)

br-int通过qr设备借助Linux网络命名空间qrouter连通br-ex上的qg设备,将数据包交付到OVS网桥br-ex上.

接下来流量的走向主要依赖于本地的配置

NAT to host address

如果将public网络的gateway赋到br-ex上:

# ip addr add 172.24.4.225/28 devbr-ex

然后你可以创建forwarding以及NAT的规则,这些规则会引起外部流量从实例重新写到网络控制器的IP地址,然后发出去

#iptables -A FORWARD -d 172.24.4.224/28 -j ACCEPT
# iptables -A FORWARD -s 172.24.4.224/28 -j ACCEPT
# iptables -t nat -I POSTROUTING 1 -s 172.24.4.224/28 -j MASQUERADE

Direct network connection

如果你有一个对于公共网络而言作为gateway的外部路由,你可以在br-ex上添加一个接口。例如eth2是在同一个网络中,地址是172.24.4.225

#ovs-vsctl add-port br-ex eth2

参考

  1. https://www.rdoproject.org/networking/networking-in-too-much-detail/
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数