openvswitch常用命令之ovs-ofctl、ovs-appctl

    技术2025-06-19  8

    1. 查看ovs的ofport端口号

    # ovs-ofctl show ns-vswitch OFPT_FEATURES_REPLY (xid=0x2): dpid:0000820552ee2c4e n_tables:254, n_buffers:0 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_dst mod_nw_src mod_nw_dst mod_nw_tos mod_tp_src mod_tp_dst 15(veth121): addr:56:0b:f8:55:e4:a3 config: 0 state: 0 current: 10GB-FD COPPER speed: 10000 Mbps now, 0 Mbps max 16(veth122): addr:3e:06:31:85:92:01 config: 0 state: 0 current: 10GB-FD COPPER speed: 10000 Mbps now, 0 Mbps max LOCAL(ns-vswitch): addr:82:05:52:ee:2c:4e config: PORT_DOWN state: LINK_DOWN speed: 0 Mbps now, 0 Mbps max OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0

    2. 查看namespace内的端口MAC地址

    # ovs-appctl fdb/show ns-vswitch port VLAN MAC Age 15 100 46:0a:51:d8:0a:d3 0 16 100 36:50:ea:2f:91:49 0

    3. 查看bridge流表

    # ovs-ofctl dump-flows ns-vswitch cookie=0x0, duration=7.555s, table=0, n_packets=0, n_bytes=0, priority=10,tcp,in_port=veth121,tp_src=8000 actions=drop cookie=0x0, duration=4.619s, table=0, n_packets=0, n_bytes=0, priority=10,in_port=veth121 actions=NORMAL cookie=0x0, duration=7668.945s, table=0, n_packets=599, n_bytes=37923, priority=0 actions=NORMAL # ovs-ofctl dump-flows ns-vswitch tp_src=8000 cookie=0x0, duration=34.575s, table=0, n_packets=0, n_bytes=0, priority=10,tcp,in_port=veth121,tp_src=8000 actions=drop

    4. 创建、修改、删除流表

    只能修改匹配流表的动作 mod-flows SWITCH FLOW : modify actions of matching FLOWs

    # ovs-ofctl add-flow ns-vswitch tcp,tp_dst=8000,actions=drop # ovs-ofctl dump-flows ns-vswitch cookie=0x0, duration=1.849s, table=0, n_packets=0, n_bytes=0, tcp,tp_dst=8000 actions=drop cookie=0x0, duration=347.259s, table=0, n_packets=160, n_bytes=10701, priority=0 actions=NORMAL # ovs-ofctl mod-flows ns-vswitch tp_dst=8000,action=NORMAL # ovs-ofctl dump-flows ns-vswitch cookie=0x0, duration=1.849s, table=0, n_packets=0, n_bytes=0, tcp,tp_dst=8000 actions=NORMAL cookie=0x0, duration=347.259s, table=0, n_packets=160, n_bytes=10701, priority=0 actions=NORMAL # ovs-ofctl del-flows ns-vswitch tp_dst=8000

    5. 其他命令

    # ovs-vsctl list-br # ovs-vsctl list-ports vswitch0 # ovs-vsctl list qos # ovs-vsctl list queue # ovs-vsctl --find Interface name="vnet0" # ovs-vsctl --find Bridge name="vswitch0" # ovs-vsctl --find Port name="vnet0" # ovsdb-client list-dbs # ovsdb-client dump
    Processed: 0.009, SQL: 9