飞羽小随笔

初体验:OVS的openflow协议

本章讲解了使用OpenVSwitch的openflow协议的一些记录。

初体验:OVS的openflow协议

全文概括

本章讲解了使用OpenVSwitch的openflow协议的一些命令,以后可能会用到,因此,在博客里做个记录。

openflow介绍

[collapse title="OpenVSwitch介绍" status="true"]

[/collapse]

[scode type="blue"]
如果想要看openvswitch的介绍或者ovs的编译步骤,请看以下文章:
[/scode]
[post cid="44" /]

命令汇总

  1. 列出br1网桥的接口
[root@localhost ~]# ovs-ofctl -O OpenFlow13 show br1
#列出br4网桥的接口
OFPT_FEATURES_REPLY (OF1.3) (xid=0x2): dpid:0000227f47f14b45
n_tables:254, n_buffers:256
capabilities: FLOW_STATS TABLE_STATS PORT_STATS GROUP_STATS QUEUE_STATS
OFPST_PORT_DESC reply (OF1.3) (xid=0x3):
 1(ca5ab26545b04_l): addr:da:ed:cd:c6:bf:0a
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 2(619496038daf4_l): addr:3a:0b:d6:59:99:4f
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 LOCAL(br1): addr:22:7f:47:f1:4b:45
     config:     PORT_DOWN
     state:      LINK_DOWN
     speed: 0 Mbps now, 0 Mbps max
OFPT_GET_CONFIG_REPLY (OF1.3) (xid=0x5): frags=normal miss_send_len=0
  1. 列出br1网桥的接口
[root@localhost ~]# ovs-ofctl dump-ports -O OpenFlow13 br1
#列出br1网桥的接口
OFPST_PORT reply (OF1.3) (xid=0x2): 3 ports
  port LOCAL: rx pkts=0, bytes=0, drop=1, errs=0, frame=0, over=0, crc=0
           tx pkts=0, bytes=0, drop=0, errs=0, coll=0
           duration=6401.851s
  port  1: rx pkts=551, bytes=1043382, drop=0, errs=0, frame=0, over=0, crc=0
           tx pkts=391, bytes=29298, drop=0, errs=0, coll=0
           duration=6392.311s
  port  2: rx pkts=383, bytes=28650, drop=0, errs=0, frame=0, over=0, crc=0
           tx pkts=394, bytes=702996, drop=0, errs=0, coll=0
           duration=6390.151s
  1. 列出br1网桥的某个接口的详细信息
[root@localhost ~]# ovs-ofctl dump-ports -O OpenFlow13 br1
OFPST_PORT reply (OF1.3) (xid=0x2): 3 ports
  port LOCAL: rx pkts=0, bytes=0, drop=1, errs=0, frame=0, over=0, crc=0
           tx pkts=0, bytes=0, drop=0, errs=0, coll=0
           duration=6401.851s
  port  1: rx pkts=551, bytes=1043382, drop=0, errs=0, frame=0, over=0, crc=0
           tx pkts=391, bytes=29298, drop=0, errs=0, coll=0
           duration=6392.311s
  port  2: rx pkts=383, bytes=28650, drop=0, errs=0, frame=0, over=0, crc=0
           tx pkts=394, bytes=702996, drop=0, errs=0, coll=0
           duration=6390.151s
[root@localhost ~]# ovs-ofctl dump-ports -O OpenFlow13 br1
OFPST_PORT reply (OF1.3) (xid=0x2): 3 ports
  port LOCAL: rx pkts=0, bytes=0, drop=1, errs=0, frame=0, over=0, crc=0
           tx pkts=0, bytes=0, drop=0, errs=0, coll=0
           duration=6434.883s
  port  1: rx pkts=551, bytes=1043382, drop=0, errs=0, frame=0, over=0, crc=0
           tx pkts=391, bytes=29298, drop=0, errs=0, coll=0
           duration=6425.343s
  port  2: rx pkts=383, bytes=28650, drop=0, errs=0, frame=0, over=0, crc=0
           tx pkts=394, bytes=702996, drop=0, errs=0, coll=0
           duration=6423.183s
  1. 查看 Open vSwitch 中的端口信息
[root@localhost ~]# ovs-ofctl show -O OpenFlow13 br1
OFPT_FEATURES_REPLY (OF1.3) (xid=0x2): dpid:0000227f47f14b45
n_tables:254, n_buffers:256
capabilities: FLOW_STATS TABLE_STATS PORT_STATS GROUP_STATS QUEUE_STATS
OFPST_PORT_DESC reply (OF1.3) (xid=0x3):
 1(ca5ab26545b04_l): addr:da:ed:cd:c6:bf:0a
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 2(619496038daf4_l): addr:3a:0b:d6:59:99:4f
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 LOCAL(br1): addr:22:7f:47:f1:4b:45
     config:     PORT_DOWN
     state:      LINK_DOWN
     speed: 0 Mbps now, 0 Mbps max
OFPT_GET_CONFIG_REPLY (OF1.3) (xid=0x5): frags=normal miss_send_len=0
  1. 获得网络接口的 OpenFlow 编号
[root@localhost ~]# ovs-vsctl get Interface 619496038daf4_l ofport
#获得网络接口的 OpenFlow 编号
2
  1. 查看网桥下的流表
[root@localhost ~]# ovs-ofctl dump-flows -O OpenFlow13 br1
#查看网桥下的流表
OFPST_FLOW reply (OF1.3) (xid=0x2):
 cookie=0x0, duration=6575.901s, table=0, n_packets=769, n_bytes=730998, priority=0 actions=NORMAL
  1. 添加流表
ovs-ofctl add-flow br1 in_port=1,actions=output:2
  1. 删除网桥中所有的流表
ovs-ofctl del-flows br1
  1. 删除根据匹配项删除网桥中的流表
ovs-ofctl del-flows br0 "in_port=1"
  1. 让端口发来的数据包全部丢弃
ovs-ofctl add-flow br1 priority=12,in_port=2,actions=drop

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »