ovs-ofctl show ovs-switch (ovs-switch代表bridge的名字,也就是虚拟的switch,下同)
2. 显示flow entries
ovs-ofctl dump-flows ovs-switch
3. 添加flow
ovs-ofctl add-flow ovs-switch "in_port=2,actions=output:8"
flow有很多syntax, 一半来说actions之前都是match的部分,常用的一般是
in_port: switch的端口
dl_src: 源mac地址
dl_dst:目的mac地址
dl_type:以太网协议类型 0x0806是arp packet 0x0800是ip packet
nw_src:源IP
nw_dst:目的ip
nw_proto:协议类型 ,注意和dl_type区分,同时也需要和dl_type一起使用,比如dl_type是ip(0x0800),那么nw_proto=1就表示icmp packet
tp_src: tcp udp源端口
tp_dst: tcp udp目的端口
|
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. |
actions:
output:port
controller(key=value) 送到controller作为packet-in 消息,括号内的key value pair可以是:
reason=reason reason 可以是action,no_match,invalid_ttl
id=controller-id 默认是0,特殊的controller会有一个16位的id
|
mod_dl_src:mac |
|
Sets the source Ethernet address to mac. |
|
mod_dl_dst:mac |
|
Sets the destination Ethernet address to mac. |
|
mod_nw_src:ip |
|
Sets the IPv4 source address to ip. |
|
mod_nw_dst:ip |
|
Sets the IPv4 destination address to ip. |
|
mod_tp_src:port |
|
Sets the TCP or UDP source port to port. |
|
mod_tp_dst:port |
|
Sets the TCP or UDP destination port to port. |
4. 删除所有flow
ovs-ofctl del-flows ovs-switch
操作示例
sudo ovs-vsctl show
sudo ovs-vsctl add-br mybridge
sudo ovs-vsctl del-br mybridge
sudo ovs-vsctl add-port mybridge port-name
sudo ovs-vsctl del-port mybridge port-name
sudo ovs-vsctl list Bridge/Port/Interface/...
sudo ovs-appctl fdb/show mybridge
sudo ovs-ofctl show mybridge
sudo ovs-ofctl dump-flows mybridge
sudo ovs-ofctl add-flow mybridge dl_src=02:a2:a2:a2:a2:a2,dl_dst=02:b2:b2:b2:b2:b2,in_port=2,dl_type=0x0800,nw_src=10.0.0.1,nw_dst=10.0.0.2,actions=output:6
sudo ovs-ofctl del-flows mybridge dl_src=02:a2:a2:a2:a2:a2,dl_dst=02:b2:b2:b2:b2:b2,in_port=2,dl_type=0x0800,nw_src=10.0.0.1,nw_dst=10.0.0.2
sudo ovs-ofctl add-flow dp0 in_port=2,actions=output:6
# This will delete all the flow entries in the flow table
sudo ovs-ofctl del-flows mybridge