openvswitch提供了强⼤且丰富的⼯具,其中ovs-ofctl是对流表操作的⼯具,包括流表的添加,修改,删除,显
⽰等操作。在⽇常使⽤中,我们通常是使⽤ovs-ofctl在本地宿主机上操作对应bridge的流表。
例如:
1. 我们需要向br-int桥的table 0添加⼀条入端⼝为tap1,匹配ip报文的流表,该流表的动作为跳转到table 10。
ovs-ofctl -O openflow13 add-flow br-int "table=0,priority=1000,in_port=tap1,ip actions=goto_table:10
2. 当我们需要显⽰br-int桥的流表时,需要在本地宿主机上使⽤下⾯的命令
ovs-ofctl -O openflow13 dump-flows br-int
ovs-ofctl不但可以在本地宿主机上操作该宿主机上bridge的流表,同时也可以操作远端宿主机上bridge的流表。当我们需要通过抓包分析openflow报文时,可以使⽤ovs-ofctl⼯具操作操作远端宿主机上bridge的流表,然后在⽹⼝抓取openflow报文。具体操作如下:
1. ⾸先在远端宿主机(管理⽹地址为16.5.70.174)的br-int桥上配置conroller,target类型为ptcp,开启监听端⼝6634
ovs-vsctl set-controller br-int ptcp:6634
此时,在该宿主机上执⾏ovs-vsctl show,可以看到如下输出
Bridge br-int
Controller "ptcp:6634"
datapath_type: netdev
Port br-int
Interface br-int
type: internal
2. 在另⼀台安装了openvswitch的宿主机上执⾏下⾯命令,为远端的br-int桥添加⼀条流表
ovs-ofctl -v -O openflow13 add-flow tcp:16.5.70.174:6634"table=0,priority=1000,in_port=tap1,ip actions=goto_table:10"