Open vSwitch
Practical study notes on Open vSwitch (OVS): what it is, how it implements SDN data and control planes, important commands/syntax, worked configuration and packet-trace examples, common exam mistakes and quick checks.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Open vSwitch (OVS) is a widely used software switch that implements packet forwarding and virtual networking inside servers and hypervisors. Engineers use OVS when building Software-Defined Networking (SDN) systems, overlay tunnels (VXLAN/GRE/Geneve), and cloud-networking stacks (for example with OpenStack) because it connects virtual machines and containers to physical networks with programmability via OpenFlow and an OVS database (OVSDB).
Key ideas
Control plane vs Data plane: the control plane makes forwarding decisions (for OVS, this is typically an external SDN controller speaking OpenFlow, or ovs-vswitchd config via OVSDB). The data plane forwards packets in the fast path using the datapath; actual throughput depends on hardware, kernel/userspace path, and offloads.
OpenFlow: a protocol that defines messages between switches and controllers to manage flow tables. OVS implements an OpenFlow-compatible pipeline: packets are matched against flow table entries and actions applied.
Flow table and pipeline processing: OVS supports multiple flow tables in a pipeline. A packet enters table 0 and is matched using fields (Ethernet src/dst, VLAN, IP src/dst, TCP/UDP ports, tunnel metadata, etc.). Each flow entry has a match, priority, counters, and actions (output, set-field, push/pop VLAN, tunnel key set, goto-table). If no flow matches, behavior is defined by the table-miss flow entry (e.g., drop or send to controller). If no table-miss entry is installed, OVS sends a packet-in to the controller by default. NORMAL L2 processing occurs only if explicitly specified via the NORMAL action.
OVSDB (OVS Database): a JSON-based database that stores configuration (bridges, ports, QoS rules). The OVS daemon ovsdb-server serves this database; ovs-vsctl is the CLI that modifies it. OVSDB is separate from runtime OpenFlow flows.
Bridges and ports: in OVS a bridge is a virtual switch instance. Ports attach to bridges; ports can be physical NICs, virtual interfaces (veth, tap), or special tunnel ports (VXLAN, GRE, Geneve). A common logical bridge name used in OpenStack is br-int (integration bridge) — this is a conventional name, not required by OVS.
Tunnels and overlays: OVS can create overlay tunnels such as VXLAN, GRE, and Geneve. Tunnels encapsulate L2/L3 traffic so VMs on different hosts appear on the same virtual network.
Integration with Linux networking: OVS interfaces connect with Linux networking stack. For performance, OVS supports DPDK (Data Plane Development Kit) userspace fast datapath; DPDK requires dedicated NIC binding and additional configuration.
What to draw in an exam diagram: draw two server boxes (Server A, Server B). Inside each, draw a box labeled OVS bridge (br-int). Attach a VM interface (tap0) to br-int on each server. Draw a VXLAN tunnel between bridges with label "VXLAN UDP port 4789". Also draw an external controller connected to both OVS bridges (label controller, port 6653). Show packet path: VM -> tap -> bridge -> flow table 0 match -> tunnel encapsulation -> physical NIC -> remote host -> decapsulation -> VM.
Assumptions usually stated in answers: OVS version supports OpenFlow 1.3+; Linux kernel module is available and loaded; controller reachable over TCP/IP; if DPDK mentioned, assume NICs are bound to DPDK driver. Also specify fail_mode (secure vs standalone) when discussing controller dependence, and remember ovs-ofctl defaults to OpenFlow 1.0 unless -O is set or the bridge protocols are configured.
Formulas
For this programming/topic, remember these commands and syntax lines (each on its own line):
ovs-vsctl add-br BRIDGE — create bridge named BRIDGE.
ovs-vsctl add-port BRIDGE PORT — add an interface PORT to BRIDGE.
ovs-vsctl set-controller BRIDGE tcp:CONTROLLER_IP:PORT — configure external OpenFlow controller. (Common controller TCP port is 6653.)
ovs-ofctl add-flow BRIDGE "PRIORITY,match,actions" — add OpenFlow flow entry to BRIDGE. Example match fields: in_port, dl_src, dl_dst, dl_type, nw_src, nw_dst, tp_src, tp_dst, tun_id.
ovs-ofctl dump-flows BRIDGE — show flow table entries and counters.
ovs-vsctl show — display bridges, ports and their configuration stored in OVSDB.
ovs-appctl dpctl/show — show kernel datapath ports and statistics (useful for debugging datapath state).
ovs-vsctl add-port BRIDGE VXLAN_PORT -- set interface VXLAN_PORT type=vxlan options:remote_ip=IP options:key=<flow|N> options:dst_port=4789 — create VXLAN port. Replace N with numeric key or use key=flow for using tunnel_key that can be set by flows.
Notes on syntax: match strings in ovs-ofctl follow OpenFlow style; fields and actions are comma-separated inside quotes. When using OpenFlow 1.3+ fields (for example, tun_id) add -O OpenFlow13 to ovs-ofctl commands, or configure the bridge protocols to include OpenFlow13 so the tool and switch negotiate the correct version.
Worked examples
Example 1 — Simple L2 forwarding between two ports on the same OVS bridge
Problem: Two VM tap interfaces tap1 and tap2 are on the same host attached to OVS bridge br0. Configure OVS so any packet from tap1 is forwarded to tap2 and vice versa, using flows (no controller packet-in).
Steps and commands:
- Create bridge and add ports:
ovs-vsctl add-br br0ovs-vsctl add-port br0 tap1ovs-vsctl add-port br0 tap2
- Add bidirectional flow rules (priority 100):
ovs-ofctl add-flow br0 "priority=100,in_port=1,actions=output:2"ovs-ofctl add-flow br0 "priority=100,in_port=2,actions=output:1"(Note: in_port numbers can be found byovs-ofctl show br0— here we assume tap1 is port 1 and tap2 is port 2.)
- Verify:
ovs-ofctl dump-flows br0should show two entries with packet and byte counters.
Packet trace for a packet from tap1 to tap2:
- Packet enters datapath on port 1.
- Table 0 match: find flow with in_port=1, highest priority 100.
- Action: output:2 — packet forwarded to port 2. Counters incremented.
Final answer (expected): ping between VMs succeeds with no packet-in to controller. If counters remain zero, check in_port mapping.
Example 2 — Setting up a VXLAN tunnel between two hosts using OVS
Problem: Connect brA on Host A and brB on Host B using a VXLAN tunnel so VMs on both hosts are in the same L2 segment.
Assumptions: Host A IP 10.0.0.1, Host B IP 10.0.0.2. Bridge names brA and brB.
Commands on Host A:
ovs-vsctl add-br brAovs-vsctl add-port brA vxlan0 -- set interface vxlan0 type=vxlan options:remote_ip=10.0.0.2 options:local_ip=10.0.0.1 options:key=flow options:dst_port=4789- Attach VM interface tapA to brA:
ovs-vsctl add-port brA tapA
Commands on Host B (mirror):
ovs-vsctl add-br brBovs-vsctl add-port brB vxlan0 -- set interface vxlan0 type=vxlan options:remote_ip=10.0.0.1 options:local_ip=10.0.0.2 options:key=flow options:dst_port=4789ovs-vsctl add-port brB tapB
Flow examples to forward VM MACs over the tunnel:
- Option 1 (key=flow): You must set the VNI (tun_id) in flows. Install on each host (replace <tap_port> with the in_port number for the tap interface, as shown by
ovs-ofctl show):- Host A:
ovs-ofctl -O OpenFlow13 add-flow brA "in_port=<tap_port>,actions=set_field:100->tun_id,output:vxlan0" - Host A:
ovs-ofctl -O OpenFlow13 add-flow brA "in_port=vxlan0,actions=output:<tap_port>" - Host B:
ovs-ofctl -O OpenFlow13 add-flow brB "in_port=<tap_port>,actions=set_field:100->tun_id,output:vxlan0" - Host B:
ovs-ofctl -O OpenFlow13 add-flow brB "in_port=vxlan0,actions=output:<tap_port>"
- Host A:
- Option 2 (fixed VNI at port): Create the VXLAN ports with a fixed key (for example,
options:key=100on both hosts instead ofkey=flow) and then use a learning switch flow on each bridge:ovs-ofctl add-flow brA "priority=0,actions=normal"ovs-ofctl add-flow brB "priority=0,actions=normal"
Packet flow explanation:
- VM on Host A sends L2 frame to Host B VM MAC.
- OVS matches flow that sets tunnel key (VNI) and outputs to vxlan0.
- Kernel/OVS writes outer UDP/IP headers with destination 10.0.0.2 and UDP port 4789.
- Packet traverses physical network to Host B, decaps, and delivers inside brB to tapB.
Expected verification: Use tcpdump -i vxlan0 on each host to see encapsulated packets (or capture on the physical NIC if the vxlan device does not show traffic due to offloading), and use ovs-ofctl dump-flows brA to see counters.
Common mistakes
Forgetting to set controller or OpenFlow version; some features require OpenFlow 1.3+ (match on tun_id, registers, etc.).
Expecting kernel datapath performance without kernel module loaded or without DPDK when required. DPDK requires NICs to be rebound and cannot share the NIC with the host unless specifically configured.
Not setting key=flow for VXLAN when flows are supposed to program the VNI (tunnel key). Without key=flow, each VXLAN port uses a fixed VNI. Also, NORMAL does not set tun_id; with key=flow you must set tun_id in a flow before outputting to the VXLAN port.
Using
ovs-vsctl add-portwith wrong interface type syntax (misspelling options:remote_ip etc.).
For your exam
Types of questions:
- Definitions and short notes: define OVS, OVSDB, datapath, userspace vs kernel datapath, DPDK, VXLAN.
- Diagram and explanation: draw OVS bridging two VMs and a VXLAN tunnel to another host; label flow table, controller, datapath.
- Commands/syntax: write commands to create bridge, add port, add-flow and show flows.
- Algorithmic/trace question: trace packet through OVS pipeline showing table matching, actions, counters.
- Practical configuration: step-by-step setup for VXLAN or simple L2 forwarding.
What full-marks answers must include:
- Precise definitions of bolded terms (OVS, datapath, controller, flow table, OVSDB).
- Correct commands or correct flow-match syntax.
- Clear diagram labels and a correct packet path description (including encapsulation for tunnels).
- Mention assumptions (OpenFlow version, kernel module presence, controller reachable).
Quick check
- What command shows OpenFlow flow entries on bridge br0?
- If you want flows to set VXLAN VNI dynamically per-packet, which VXLAN option do you use when adding the port?
- Name two differences between OVS kernel datapath and userspace DPDK datapath.
Answers: ovs-ofctl dump-flows br0; options:key=flow when creating the vxlan port; kernel datapath integrates with Linux kernel and is generally simpler to deploy, DPDK datapath runs in userspace with higher throughput and requires NICs bound to DPDK drivers and extra configuration.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?