ovs流表高级特性(一)

表 1. 流表常用字段

对于 add−flow,add−flows 和 mod−flows 这三个命令,还需要指定要执行的动作:actions=[target][,target...]

一个流规则中可能有多个动作,按照指定的先后顺序执行。

 

 

 

常见的操作有:

    • output:port: 输出数据包到指定的端口。port 是指端口的 OpenFlow 端口编号
    • mod_vlan_vid: 修改数据包中的 VLAN tag
    • strip_vlan: 移除数据包中的 VLAN tag
    • mod_dl_src/ mod_dl_dest: 修改源或者目标的 MAC 地址信息
    • mod_nw_src/mod_nw_dst: 修改源或者目标的 IPv4 地址信息
    • resubmit:port: 替换流表的 in_port 字段,并重新进行匹配
    • load:value−>dst[start..end]: 写数据到指定的字段

 

ip

Same as dl_type=0x0800.

icmp

Same as dl_type=0x0800,nw_proto=1.

tcp

Same as dl_type=0x0800,nw_proto=6.

udp

Same as dl_type=0x0800,nw_proto=17.

arp

Same as dl_type=0x0806.

rarp

Same as dl_type=0x8035.

 

 1、添加一条flow:屏蔽 STP 协议的广播数据包

[root@kunpeng82 devuser]# ovs-ofctl add-flow vswitch1 "table=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, actions=drop"
[root@kunpeng82 devuser]# ovs-appctl ofproto/trace br0 in_port=1,dl_dst=01:80:c2:00:00:05
br0: unknown bridge
ovs-appctl: ovs-vswitchd: server returned an error
[root@kunpeng82 devuser]# ovs-appctl ofproto/trace vswitch1 in_port=1,dl_dst=01:80:c2:00:00:05
Flow: in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=01:80:c2:00:00:05,dl_type=0x0000

bridge("vswitch1")
------------------
 0. dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0, priority 32768
    drop

Final flow: unchanged
Megaflow: recirc_id=0,eth,in_port=1,dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0,dl_type=0x0000
Datapath actions: drop
[root@kunpeng82 devuser]# ovs-appctl ofproto/trace vswitch1 in_port=1,dl_dst=01:80:c2:00:00:15
Flow: in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=01:80:c2:00:00:15,dl_type=0x0000

bridge("vswitch1")
------------------
 0. priority 0
    NORMAL
     >>>> received packet on unknown port 1 <<<<
     >> no input bundle, dropping

Final flow: unchanged
Megaflow: recirc_id=0,eth,in_port=1,vlan_tci=0x0000/0x1fff,dl_src=00:00:00:00:00:00,dl_dst=01:80:c2:00:00:15,dl_type=0x0000
Datapath actions: drop

 

2、再添加一条flow:

ovs-ofctl add-flow  vswitch1 "table=0, priority=0, actions=resubmit(,1)"

添加之后talbe不存在actions=normal的flow:cookie=0x0, duration=177867.865s, table=0, n_packets=153445, n_bytes=16182100, priority=0 actions=NORMAL

[root@kunpeng82 devuser]# ovs-ofctl dump-flows vswitch1
cookie=0x0, duration=1424.340s, table=0, n_packets=0, n_bytes=0, dl_dst=01:80:c2:00:00:00/ff:ff:ff:ff:ff:f0 actions=drop
cookie=0x0, duration=552.220s, table=0, n_packets=6, n_bytes=420, priority=0 actions=resubmit(,1)

 
[root@kunpeng82 devuser]# ovs-appctl ofproto/trace vswitch1 in_port=1,dl_dst=01:80:c2:00:00:15
Flow: in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=01:80:c2:00:00:15,dl_type=0x0000

bridge("vswitch1")
------------------
 0. priority 0
    resubmit(,1)
 1. No match.
    drop

Final flow: unchanged
Megaflow: recirc_id=0,eth,in_port=1,dl_dst=01:80:c2:00:00:10/ff:ff:ff:ff:ff:f0,dl_type=0x0000
Datapath actions: drop
[root@kunpeng82 devuser]# 

 

posted on 2020-04-07 14:03  tycoon3  阅读(4749)  评论(0编辑  收藏  举报

导航