mininet中默认使用ovs作为虚拟交换机,因此在mininet中同样可以使用ovs指令对交换机进行控制。
在mininet的CLI中,使用sh便可以输入ovs指令
1、查看网桥和端口
ovs-vsctl show
2、添加/删除网桥
ovs-vsctl add-br br0
ovs-vsctl del-br br0
3、添加/删除端口
ovs-vsctl add-port br0 eth1
ovs-vsctl del-port br0 eth1
4、设置/清除网桥的openflow协议版本
ovs-vsctl set bridge br0 protocols=OpenFlow13
ovs-vsctl clear bridge br0 protocols
5、查看某网桥当前流表
ovs-ofctl dump-flows br0
ovs-ofctl -O OpenFlow13 dump-flows br0
ovs-appctl bridge/dump-flows br0
6、设置/删除控制器
ovs-vsctl set-controller br0 tcp:1.2.3.4:6633
ovs-vsctl del-controller br0
7、查看控制器列表
ovs-vsctl list controller
8、设置fail模式,支持standalone或者secure
standalone(default):清除所有控制器下发的流表,ovs自己接管
secure:按照原来流表继续转发
ovs-vsctl del-fail-mode br0
ovs-vsctl set-fail-mode br0 secure
ovs-vsctl get-fail-mode br0
9、查看接口id等
ovs-appctl dpif/show
10、查看接口统计
ovs-ofctl dump-ports br0
##
1、添加流表
ovs-ofctl add-flow br0 in_port=1,actions=output:2
2、删除所有流表
ovs-ofctl del-flows br0
3、按匹配项来删除流表
ovs-ofctl del-flows br0 "in_port=1"
1、匹配vlan tag,范围为0-4095
ovs-ofctl add-flow br0 priority=401,in_port=1,dl_vlan=777,actions=output:2
2、匹配vlan pcp,范围为0-7
ovs-ofctl add-flow br0 priority=401,in_port=1,dl_vlan_pcp=7,actions=output:2
3、匹配源/目的MAC
ovs-ofctl add-flow br0 in_port=1,dl_src=00:00:00:00:00:01/00:00:00:00:00:01,actions=output:2
ovs-ofctl add-flow br0 in_port=1,dl_dst=00:00:00:00:00:01/00:00:00:00:00:01,actions=output:2
4、匹配以太网类型,范围为0-65535
ovs-ofctl add-flow br0 in_port=1,dl_type=0x0806,actions=output:2
5、匹配源/目的IP
条件:指定dl_type=0x0800,或者ip/tcp
ovs-ofctl add-flow br0 ip,in_port=1,nw_src=10.10.0.0/16,actions=output:2
ovs-ofctl add-flow br0 ip,in_port=1,nw_dst=10.20.0.0/16,actions=output:2
6、匹配协议号,范围为0-255
条件:指定dl_type=0x0800或者ip
# ICMP
ovs-ofctl add-flow br0 ip,in_port=1,nw_proto=1,actions=output:2
7、匹配IP ToS/DSCP,tos范围为0-255,DSCP范围为0-63
ovs-ofctl add-flow br0 ip,in_port=1,nw_tos=68,actions=output:2
ovs-ofctl add-flow br0 ip,in_port=1,ip_dscp=62,actions=output:2
8、匹配IP ecn位,范围为0-3
ovs-ofctl add-flow br0 ip,in_port=1,ip_ecn=2,actions=output:2
9、匹配IP TTL,范围为0-255
ovs-ofctl add-flow br0 ip,in_port=1,nw_ttl=128,actions=output:2
10、匹配tcp/udp,源/目的端口,范围为0-65535
# 匹配源tcp端口179
ovs-ofctl add-flow br0 tcp,tcp_src=179/0xfff0,actions=output:2
# 匹配目的tcp端口179
ovs-ofctl add-flow br0 tcp,tcp_dst=179/0xfff0,actions=output:2
# 匹配源udp端口1234
ovs-ofctl add-flow br0 udp,udp_src=1234/0xfff0,actions=output:2
# 匹配目的udp端口1234
ovs-ofctl add-flow br0 udp,udp_dst=1234/0xfff0,actions=output:2
11、匹配tcp flags
ovs-ofctl add-flow br0 tcp,tcp_flags=ack,actions=output:2
12、匹配icmp code,范围为0-255
ovs-ofctl add-flow br0 icmp,icmp_code=2,actions=output:2
13、匹配vlan TCI
ovs-ofctl add-flow br0 in_port=1,vlan_tci=0xf123,actions=output:2
下次更新