# Open vSwitch design and command usage
###### tags: `ovs` `network`
### Open vSwitch overview

### Open vSwitch basic commands
```
# show switch and ports
ovs-vsctl show
# list ports not include local port
ovs-vsctl list-ports <vswitch name>
# list interfaces not include local interface
ovs-vsctl list-ifaces <vswitch name>
# show ovs mac table
ovs-appctl fdb/show <vswitch name>
# show summary of datapath
ovs-appctl dpif/show
# set port as vlan trunk with tag 10,20,30
ovs-vsctl set port <port name> trunks=10,20,30
# show interfaces details
ovs-vsctl list interface
ovs-vsctl list interface <interface name>
# show port details
ovs-vsctl list port
ovs-vsctl list port <port name>
# create internal port
ovs-vsctl add-port <vswitch name> <port name> -- set interface <port name> type=internal
# set/unset port with tag 9
ovs-vsctl set port <port name> tag=9
ovs-vsctl clear port <port name> tag
# create patch port between br1 and br2 vswitch
ovs-vsctl add-port br1 patch-ovs-1 -- set Interface patch-ovs-1 type=patch options:peer=patch-ovs-2
ovs-vsctl add-port br2 patch-ovs-2 -- set Interface patch-ovs-2 type=patch options:peer=patch-ovs-1
```
```
# set/unset controller
ovs-vsctl set-controller <vswitch name> tcp:<ip address>:<port number>
ovs-vsctl del-controller <vswitch name>
# show vswitch ports info (port number, mac, etc....)
ovs-ofctl show <vswitch name>
# get vswitch openflow rules
ovs-ofctl dump-flows <vswitch name>
# get vswitch ports statistics
ovs-ofctl dump-ports <vswitch name>
# get queue stats
ovs-ofctl queue-stats <vswitch name> [<port name> [queue name] ]
# add flow rule
ovs-ofctl add-flow <vswitch name> <flow rule>
ovs-ofctl add-flow <vswitch name> <file name>
# del flow rule
ovs-ofctl del-flows <vswitch name>
ovs-ofctl del-flows <vswitch name> <flow rule>
# mod flow rule
ovs-ofctl mod-flows <vswitch name>
ovs-ofctl mod-flows <vswitch name> <flow rule>
# add datapath
ovs-dpctl add-dp <datapath> [<interface name> ...]
# del datapath
ovs-dpctl del-dp <datapath>
# dump datapath
ovs-dpctl dump-dps
# show basic info of datapaths
ovs-dpctl show
ovs-dpctl show -s -v
ovs-dpctl show <datapath>
# dump flows in a datapath
ovs-dpctl dump-flows <datapath>
# del all flows from a datapath
ovs-dpctl del-flows <datapath>
# show ovsdb info
ovsdb-client list-dbs
ovsdb-client list-tables
# Add VXLAN port (VTEP)
ovs-vsctl add-port br-int "vxlan-192.168.2.6"
ovs-vsctl set interface 'vxlan-192.168.2.6' type=vxlan
ovs-vsctl set interface 'vxlan-192.168.2.6' options="{key=flow, local_ip="192.168.2.5",remote_ip=192.168.2.6}"
# Add flow to controller
ovs-ofctl add-flow <vswitch_name> action=normal,controller
```
```
# show tables info
ovs-vsctl -- --columns=name,qos find Port qos!=[]
ovs-vsctl -- --columns=_uuid,queue find QoS
ovs-vsctl -- --columns=_uuid,other_config find Queue
ovs-vsctl -f table -- --columns=_uuid,qos,name find Port
ovs-vsctl -f table -- --columns=_uuid,ingress_policing_rate find Interface
ovs-vsctl -f table -- --columns=_uuid,other_config find Queue
ovs-vsctl -f table -- --columns=_uuid,queues,other_config find QoS
# set interface transmit limit
ovs-vsctl set interface <interface name> ingress_policing_rate=<bit value> ingress_policing_burst=<burst limit value>
# clear interface transmit limit
ovs-vsctl set interface <interface name> ingress_policing_rate=0 ingress_policing_burst=0
# set port receive limit
ovs-vsctl -- set Port <port name> qos=@newqos -- --id=@newqos create QoS type=linux-htb other-config:max-rate=<value in bit> queues=0=@q0 -- --id=@q0 create Queue other-config:min-rate=<value in bit> other-config:max-rate=<value in bit>
Example:
root@python:~# ovs-vsctl -- set Port test qos=@newqos -- --id=@newqos create QoS type=linux-hub other-config:max-rate=100000 queues=0=@q0 -- --id=@q0 create Queue other-config:min-rate=100000 other-config:max-rate=100000
b16222c8-e813-4382-a5dc-74cd1d556bc0
6fc5cf6c-5e41-4a7d-8494-2a6bbd284493
* two UUIDs are related to QoS and Queue tables.
* you need use them to clear this setting
# clear port receive limit
root@python:~# ovs-vsctl -- --columns=name,qos find Port qos!=[]
name : test
qos : b16222c8-e813-4382-a5dc-74cd1d556bc0
root@python:~# ovs-vsctl -- --columns=_uuid,other_config find Queue
_uuid : 6fc5cf6c-5e41-4a7d-8494-2a6bbd284493
other_config : {max-rate="100000", min-rate="100000"}
root@python:~# ovs-vsctl list qos
_uuid : b16222c8-e813-4382-a5dc-74cd1d556bc0
external_ids : {}
other_config : {max-rate="100000"}
queues : {0=6fc5cf6c-5e41-4a7d-8494-2a6bbd284493}
type : linux-hub
root@python:~# ovs-vsctl list queue
_uuid : 6fc5cf6c-5e41-4a7d-8494-2a6bbd284493
dscp : []
external_ids : {}
other_config : {max-rate="100000", min-rate="100000"}
root@python:~# ovs-vsctl list port test
_uuid : 1e2ffec3-e2f8-4463-8d79-e96233746c5a
bond_active_slave : []
bond_downdelay : 0
bond_fake_iface : false
bond_mode : []
bond_updelay : 0
external_ids : {}
fake_bridge : false
interfaces : [0d1ae7a8-e105-4891-a1c5-035307a88f01]
lacp : []
mac : []
name : test
other_config : {}
qos : b16222c8-e813-4382-a5dc-74cd1d556bc0
rstp_statistics : {}
rstp_status : {}
statistics : {}
status : {}
tag : []
trunks : []
vlan_mode : []
root@python:~# ovs-vsctl clear Port test qos
root@python:~# ovs-vsctl list port test
_uuid : 1e2ffec3-e2f8-4463-8d79-e96233746c5a
bond_active_slave : []
bond_downdelay : 0
bond_fake_iface : false
bond_mode : []
bond_updelay : 0
external_ids : {}
fake_bridge : false
interfaces : [0d1ae7a8-e105-4891-a1c5-035307a88f01]
lacp : []
mac : []
name : test
other_config : {}
qos : []
rstp_statistics : {}
rstp_status : {}
statistics : {}
status : {}
tag : []
trunks : []
vlan_mode : []
* or use follow command to remove qos binded to the port
(ovs-vsctl -- remove Port test qos b16222c8-e813-4382-a5dc-74cd1d556bc0)
root@python:~# ovs-vsctl -- destroy qos b16222c8-e813-4382-a5dc-74cd1d556bc0
root@python:~# ovs-vsctl -- destroy queue 6fc5cf6c-5e41-4a7d-8494-2a6bbd284493
```