网络模型:

首先流表分类:
- table 0: 入流量的初步处理,其中patch-int的入流量交由table 2处理;VLXAN Port入流量交由table 4进一步处理
- table 2: 单播及广播包的处理,单播包交由table 20处理,广播包交由table 22处理
- table 3: 默认Drop流表
- table 4: 处理vxlan数据的规则,解封装,添加对应的local vlan;以及最后默认Drop的流表
- table 6: 默认Drop流表
- table 10: 能够mac学习的流表,避免广播。生成的流表默认添加在table 20。生成流表主要对应的是:目的mac地址 vlan actions: {移除vlan 添加vni} output:port
- table 20: 由table 10生成的流表,以及一条默认流表。默认流表主要将数据交由table 22处理
- table 22: 广播,针对每一个VPC对应一个流表。默认Drop流表
主要分析计算节点中的br-tun上流表:
/*表示vxlan mac vni vtep_ip学习,并在table20 生成流表,最后三个即为学习生成的了流表*/
cookie=0x9c16d3230eacb22f, duration=25119931.470s, table=10, n_packets=997309940, n_bytes=182330377247, idle_age=0, hard_age=65534, priority=1 actions=learn(table=20,hard_timeout=300,priority=1,cookie=0x9c16d3230eacb22f,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=0x9c16d3230eacb22f, duration=10808756.995s, table=20, n_packets=695825010, n_bytes=119220847588, hard_timeout=300, idle_age=0, hard_age=0, priority=1,vlan_tci=0x003c/0x0fff,dl_dst=fa:16:3e:58:08:42 actions=load:0->NXM_OF_VLAN_TCI[],load:0x275e->NXM_NX_TUN_ID[],output:16
cookie=0x9c16d3230eacb22f, duration=10709199.603s, table=20, n_packets=5940016, n_bytes=899587485, hard_timeout=300, idle_age=0, hard_age=0, priority=1,vlan_tci=0x003c/0x0fff,dl_dst=fa:16:3e:e7:35:91 actions=load:0->NXM_OF_VLAN_TCI[],load:0x275e->NXM_NX_TUN_ID[],output:15
cookie=0x9c16d3230eacb22f, duration=465.226s, table=20, n_packets=7, n_bytes=438, hard_timeout=300, idle_age=96, hard_age=96, priority=1,vlan_tci=0x0044/0x0fff,dl_dst=fa:16:3e:89:0a:1d actions=load:0->NXM_OF_VLAN_TCI[],load:0x277d->NXM_NX_TUN_ID[],output:17
跨主机vxlan通信的流表,此流表主要用于多播:
cookie=0x9c16d3230eacb22f, duration=16687019.087s, table=22, n_packets=186, n_bytes=52368, idle_age=65534, hard_age=65534, dl_vlan=56 actions=strip_vlan,set_tunnel:0x2718,output:35,output:33,output:34,output:31,output:32,output:29,output:30,output:19,output:18,output:2,output:4,output:3,output:6,output:5,output:43,output:15,output:14,output:37,output:36,output:39,output:38,output:28,output:27,output:26,output:25,output:24,output:23,output:22,output:21,output:20,output:13,output:42,output:9,output:10,output:11,output:12,output:7,output:8,output:16,output:17,output:40,output:41
入流量
入流量的第一个流表:
cookie=0x9c16d3230eacb22f, duration=5279135.558s, table=0, n_packets=209698, n_bytes=85617348, idle_age=118, hard_age=65534, priority=1,in_port=37 actions=resubmit(,4)
#port37 对应vxlan tunnel endpoint:
37(vxlan-0a820211): addr:02:35:65:34:22:f0
config: 0
state: 0
speed: 0 Mbps now, 0 Mbps max
此流表表示37进入的流量交由table 4处理:
查看table 4其中一个流表:
cookie=0x9c16d3230eacb22f, duration=11934762.520s, table=4, n_packets=989924192, n_bytes=178826727870, idle_age=0, hard_age=65534, priority=1,tun_id=0x275e actions=mod_vlan_vid:60,resubmit(,10)
表示vni: 0x275e的数据流,添加vlan 60,并交由table 10.
table 10的流表:
cookie=0x9c16d3230eacb22f, duration=25119931.470s, table=10, n_packets=997309940, n_bytes=182330377247, idle_age=0, hard_age=65534, priority=1 actions=learn(table=20,hard_timeout=300,priority=1,cookie=0x9c16d3230eacb22f,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
这是一个具有mac,vni,vtep学习能力的流表。匹配的数据包,首先会在table 20生成对应的一个流表,同时将数据包转发至port 1.
port 1:
# ovs-ofctl show br-tun
OFPT_FEATURES_REPLY (xid=0x2): dpid:0000eeaf154c8b47
n_tables:254, n_buffers:256
capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_dst mod_nw_src mod_nw_dst mod_nw_tos mod_tp_src mod_tp_dst
1(patch-int): addr:12:22:13:c6:38:14
config: 0
state: 0
speed: 0 Mbps now, 0 Mbps max
port 1将流量转发至br-int.br-int则具有mac转发表,数据包直接转发至虚拟机。
br-int的mac转发表如下:
# ovs-appctl fdb/show br-int
port VLAN MAC Age
75 68 fa:16:3e:ab:cb:db 56
2 68 fa:16:3e:89:0a:1d 56
65 60 fa:16:3e:aa:09:b1 4
2 60 fa:16:3e:e7:35:91 4
2 60 fa:16:3e:58:08:42 0
66 60 fa:16:3e:8a:d9:00 0
出流量
出流量分成两步,一个是多播包,单播包。
以上是br-tun的流表分析。实际中,还可能包括arp代理设置的流表,本环境中没有打开此配置,因此不存在此类流表。
流表部分说明:
单播包,交由表20处理:
cookie=0x9c16d3230eacb22f, duration=25119931.475s, table=2, n_packets=939579728, n_bytes=227583788849, idle_age=0, hard_age=65534, priority=0,dl_dst=00:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,20)
组播(包括广播),交由表22处理:
cookie=0x9c16d3230eacb22f, duration=25119931.474s, table=2, n_packets=129280, n_bytes=5526964, idle_age=65534, hard_age=65534, priority=0,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,22)
单播交由table 20处理,table 20包括学习到的流表,若匹配,则直接封装发送至对端的vtep,若未能匹配则交由table 22处理:
cookie=0x9c16d3230eacb22f, duration=465.226s, table=20, n_packets=7, n_bytes=438, hard_timeout=300, idle_age=96, hard_age=96, priority=1,vlan_tci=0x0044/0x0fff,dl_dst=fa:16:3e:89:0a:1d actions=load:0->NXM_OF_VLAN_TCI[],load:0x277d->NXM_NX_TUN_ID[],output:17
cookie=0x9c16d3230eacb22f, duration=25119931.469s, table=20, n_packets=13255, n_bytes=1530598, idle_age=465, hard_age=65534, priority=0 actions=resubmit(,22)
table 22:
cookie=0x9c16d3230eacb22f, duration=11934762.541s, table=22, n_packets=1125, n_bytes=275926, idle_age=6239, hard_age=65534, dl_vlan=60 actions=strip_vlan,set_tunnel:0x275e,output:35,output:33,output:34,output:31,output:32,output:29,output:30,output:19,output:18,output:2,output:4,output:3,output:6,output:5,output:43,output:15,output:14,output:37,output:36,output:39,output:38,output:28,output:27,output:26,output:25,output:24,output:23,output:22,output:21,output:20,output:13,output:42,output:9,output:10,output:11,output:12,output:7,output:8,output:16,output:17,output:40,output:41
table 22流表表示,剔除对应的vlan,并封装设置vni,广播至所有的vtep。
ovs流表学习选项说明:
-
table=20:修改 table 20。这是个 MAC 学习流表。
-
hard_timeout:该 flow 的过期时间。
-
NXM_OF_VLAN_TCI[0..11] :记录 vlan tag,所以学习结果中有 dl_vlan=1
-
NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[] :将 mac source address 记录,所以结果中有 dl_dst=fa:16:3e:7e:ab:cc
-
load:0->NXM_OF_VLAN_TCI[]:在发送出去的时候,vlan tag设为0,所以结果中有 actions=strip_vlan
-
load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[] :发出去的时候,设置 tunnul id,所以结果中有set_tunnel:0x3e9
-
output:NXM_OF_IN_PORT[]:指定发送给哪个port,由于是从 port2 进来的,因而结果中有output:2。
ovs常用命令
日志查看:
# ovsdb-tool show-log -m /etc/openvswitch/conf.db
端口抓包:
通过设置端口镜像来抓取没有具体设备的OVS端口,例如监听br-tun的patch-int端口
# ip link add name snooper0 type dummy
# ip link set dev snooper0 up
# ovs-vsctl add-port br-tun snooper0
# ovs-vsctl -- set Bridge br-tun mirrors=@m -- --id=@snooper0 get Port snooper0 -- --id=@patch-int get Port patch-int -- --id=@m create Mirror name=mymirror select-dst-port=@patch-int select-src-port=@patch-int output-port=@snooper0 select_all=1
#tcpdump -i snooper0
# ovs-vsctl clear Bridge br-tun mirrors
# ovs-vsctl del-port br-tun snooper0
# ip link delete dev snooper0
流表匹配
# ovs-appctl ofproto/trace br-tun dl_vlan=1
网友评论