openvSwitch 基础命令行

创建ovs(虚拟交换机) br0

ovs-vsctl add-br br0

创建一根线first_br<->first_if

ip link add first_br type veth peer name first_if

启动线的两个接口

ip link set first_br up
ip link set first_if up

将接口first_br接入虚拟交换机br0

ovs-vsctl add-port br0 first_br

列出网桥的基本信息

ovs-vsctl list Bridge

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
root@controller-VirtualBox:~# ovs-vsctl list Bridge
_uuid : 2a47c03f-4060-4b90-ac24-131dbe051446
auto_attach : []
controller : []
datapath_id : "00003ec0472a904b"
datapath_type : ""
datapath_version : "<unknown>"
external_ids : {}
fail_mode : []
flood_vlans : []
flow_tables : {}
ipfix : []
mcast_snooping_enable: false
mirrors : []
name : "br0"
netflow : []
other_config : {}
ports : [7cb41bb3-ae24-473d-b93a-df5786fb177c, f83add01-bac5-4c63-859c-068a2cd2535d]
protocols : []
rstp_enable : false
rstp_status : {}
sflow : []
status : {}
stp_enable : false

将first_br划分到vlan100中

ovs-vsctl set Port first_br tag=100

查看接口是否加入到vlan100中

1
2
3
4
5
6
7
8
9
10
11
root@controller-VirtualBox:~# ovs-vsctl show
29c5cc05-2a31-4f14-a304-3a697698f96a
Bridge "br0"
Port "br0"
Interface "br0"
type: internal
Port first_br
tag: 100
Interface first_br
ovs_version: "2.5.2"
root@controller-VirtualBox

将接口移出vlan

ovs-vsctl clear port first_br tag

将first_br加入trunks中,并且标记tag110

ovs-vsctl add Port first_br trunks 110,120

将trunks信息去除110 tag,剩余120 tag

ovs-vsctl remove Port first_br trunks 110

一次性完全把接口first_br清出trunk

ovs-vsctl clear Port first_br trunks

查看数据库Open_vSwitch内容

ovsdb-client get-schema Open_vSwitch

查看ovs所有数据库内容,并格式化输出

ovsdb-client dump

列出当前ovs工作数据库

ovsdb-client list-dbs

1
2
root@controller-VirtualBox:~# ovsdb-client list-dbs
Open_vSwitch

列出当前ovs工作数据库中的表格

ovsdb-client list-tables Open_vSwitch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
root@controller-VirtualBox:~# ovsdb-client list-tables Open_vSwitch
Table
-------------------------
Controller
Bridge
Queue
IPFIX
NetFlow
Open_vSwitch
QoS
Port
sFlow
SSL
Flow_Sample_Collector_Set
Mirror
Flow_Table
Interface
AutoAttach
Manager

列出Open_vSwitch中表格Port所有类型和范围信息

ovsdb-client list-columns Open_vSwitch Port

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
oot@controller-VirtualBox:~# ovsdb-client list-columns Open_vSwitch Port
Column Type
----------------- -----------------------------------------------------------------------------------------------------
bond_downdelay "integer"
name "string"
statistics {"key":"string","max":"unlimited","min":0,"value":"integer"}
fake_bridge "boolean"
mac {"key":"string","min":0}
trunks {"key":{"maxInteger":4095,"minInteger":0,"type":"integer"},"max":4096,"min":0}
_uuid "uuid"
tag {"key":{"maxInteger":4095,"minInteger":0,"type":"integer"},"min":0}
rstp_status {"key":"string","max":"unlimited","min":0,"value":"string"}
_version "uuid"
bond_updelay "integer"
bond_active_slave {"key":"string","min":0}
external_ids {"key":"string","max":"unlimited","min":0,"value":"string"}
other_config {"key":"string","max":"unlimited","min":0,"value":"string"}
status {"key":"string","max":"unlimited","min":0,"value":"string"}
qos {"key":{"refTable":"QoS","type":"uuid"},"min":0}
bond_mode {"key":{"enum":["set",["active-backup","balance-slb","balance-tcp"]],"type":"string"},"min":0}
bond_fake_iface "boolean"
interfaces {"key":{"refTable":"Interface","type":"uuid"},"max":"unlimited"}
vlan_mode {"key":{"enum":["set",["access","native-tagged","native-untagged","trunk"]],"type":"string"},"min":0}
rstp_statistics {"key":"string","max":"unlimited","min":0,"value":"integer"}
lacp {"key":{"enum":["set",["active","off","passive"]],"type":"string"},"min":0}

列出Port表格的数据信息

ovsdb-client dump Port

查看ovs 接口信息详情

ovs-vsctl list Port

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
root@controller-VirtualBox:~# ovs-vsctl list Port
_uuid : f83add01-bac5-4c63-859c-068a2cd2535d
bond_active_slave : []
bond_downdelay : 0
bond_fake_iface : false
bond_mode : []
bond_updelay : 0
external_ids : {}
fake_bridge : false
interfaces : [31edb9df-45bc-45ba-90b9-d9e78211ecc6]
lacp : []
mac : []
name : first_br
other_config : {}
qos : []
rstp_statistics : {}
rstp_status : {}
statistics : {}
status : {}
tag : []
trunks : [120]
vlan_mode : []

_uuid : 7cb41bb3-ae24-473d-b93a-df5786fb177c
bond_active_slave : []
bond_downdelay : 0
bond_fake_iface : false
bond_mode : []
bond_updelay : 0
external_ids : {}
fake_bridge : false
interfaces : [0f86bf9b-c702-481c-b1e6-0919f1d06c2a]
lacp : []
mac : []
name : "br0"
other_config : {}
qos : []
rstp_statistics : {}
rstp_status : {}
statistics : {}
status : {}
tag : []
trunks : []
vlan_mode : []

查看ovs交换机学习到的MAC表项

1
2
3
4
5
6
root@compute:~# ovs-appctl fdb/show br-int
port VLAN MAC Age
3 2 fa:16:3e:1f:95:2c 0
2 1 fa:16:3e:f3:31:f5 0
6 1 fa:16:3e:2c:c3:0d 0
4 2 fa:16:3e:3c:d2:56 0

此命令可运用在normal转发时ovs交换机上,如果ovs交换机没有进行normal转发,请通过openflow表项探究流量转发路径。