Skip to content
Documentation Background

SDN and OpenFlow

In a traditional network each router runs its own control plane and computes its own forwarding table. Software-defined networking (SDN) moves that logic out of the devices. Switches become simple, fast forwarders. A controller running on ordinary servers computes the rules and installs them. See Forwarding and routing for the data plane and control plane split this builds on.

You meet SDN daily without the name. Cloud virtual networks, Open vSwitch on hypervisors, Kubernetes CNI plugins such as Cilium, and data center fabrics all follow the same model: a central brain, programmable forwarders.


CharacteristicMeaning
Flow-based forwardingSwitches match on many header fields, not just the destination IP
Separate planesSwitches only forward. Control logic runs elsewhere
Control outside the switchControl software runs on remote servers, as a controller plus applications
ProgrammableRouting, access control, and load balancing are applications on top of the controller. Changing behavior means changing software, not hardware

A side effect is unbundling. Switches, controllers, and control applications can come from different vendors or open-source projects, much as PC hardware, operating systems, and applications did.


Traditional forwarding looks at one field, the destination IP, and picks an output port by longest-prefix match. Generalized forwarding replaces that table with a flow table. Each entry has:

PartMeaning
Match fieldsHeader values to compare against: ingress port, source and destination MAC, EtherType, VLAN ID, source and destination IP, IP protocol, ToS, and TCP or UDP ports. Wildcards and prefixes are allowed
PriorityIf a packet matches several entries, the highest priority wins
ActionsWhat to do with a match, in order
CountersPackets and bytes matched, and time since the last match
TimeoutsRemove the entry after a period of inactivity or a fixed lifetime

OpenFlow 1.0 defined 12 match values. Later versions define dozens more. Not every header field is matchable, because every extra field makes the hardware lookup harder. The table is usually held in TCAM, which can compare against over a million entries in one cycle.

Actions include:

  • Forward out one port, flood to all ports except the ingress, or send to a group.
  • Drop. An entry with no actions discards the packet.
  • Rewrite fields in the Ethernet, IP, or TCP/UDP headers before forwarding. This is how a switch can do NAT or change a VLAN tag.
  • Send to the controller for a decision.

One mechanism, then, covers forwarding, load balancing, firewalling, and NAT. They are all rules in the same table.

Open vSwitch (OVS) is a software switch with an OpenFlow table. It runs on most hypervisors, so you can try these rules on a Linux host. Port numbers are examples.

Terminal window
# Forwarding by source and destination: traffic from 10.10.0.0/16 to 10.20.0.0/16 uses port 2
sudo ovs-ofctl add-flow br0 "priority=100,ip,nw_src=10.10.0.0/16,nw_dst=10.20.0.0/16,actions=output:2"
# Load balancing by ingress port: two clients headed to the same prefix take different uplinks
sudo ovs-ofctl add-flow br0 "priority=100,in_port=3,ip,nw_dst=10.30.0.0/16,actions=output:1"
sudo ovs-ofctl add-flow br0 "priority=100,in_port=4,ip,nw_dst=10.30.0.0/16,actions=output:2"
# Firewalling: drop SSH to one server, and drop everything not otherwise allowed
sudo ovs-ofctl add-flow br0 "priority=200,tcp,nw_dst=10.20.0.10,tp_dst=22,actions=drop"
sudo ovs-ofctl add-flow br0 "priority=0,actions=drop"
# Rewrite: send traffic for a virtual IP to a real backend
sudo ovs-ofctl add-flow br0 "priority=150,ip,nw_dst=10.20.0.100,actions=mod_nw_dst:10.20.0.10,output:2"
# Inspect the table, including packet counters for each rule
sudo ovs-ofctl dump-flows br0

The load balancing rules show what destination-based forwarding cannot do. Both flows have the same destination prefix, so a router would send them out the same port. Adding the ingress port to the match lets the switch split them. The firewall works the same way: only traffic that matches a forward rule gets through, and a final priority-0 rule drops the rest.


A controller has three layers.

flowchart TD
    APPS["Control applications<br/>routing, access control, load balancing"]
    subgraph CTL["SDN controller"]
        NB["Northbound interface<br/>REST API, intents, event callbacks"]
        ST["State management<br/>topology, host and link status, flow tables, statistics"]
        SB["Communication layer<br/>southbound interface"]
        NB --> ST --> SB
    end
    SW["Switches and routers<br/>flow tables"]
    APPS <--> NB
    SB <-->|"OpenFlow, NETCONF, OVSDB"| SW
LayerJob
SouthboundTalks to the switches. OpenFlow is the best known protocol. NETCONF and OVSDB are others
State managementKeeps a current, network-wide view: topology, link and port status, installed flow rules, counters
NorthboundLets applications read that state, write rules, and subscribe to events. Usually a REST API. Some controllers also accept intents, high-level goals such as “host A may reach host B” that the controller turns into rules

The controller is logically centralized but physically distributed. Applications see one service, while in production it runs as a cluster of servers replicating the state. That gives fault tolerance and capacity without losing the single point of view. ONOS is an open-source controller built this way, with a distributed core, an intent framework, and several southbound protocols.

Large operators use the same pattern with intent-based management: operators declare the desired network state, and controllers continuously compare it with what devices report and fix the difference. Kubernetes controllers follow the same idea of reconciling desired and actual state.

OpenFlow runs over TCP, by default on port 6653.

DirectionMessagePurpose
Controller to switchConfigurationQuery or set switch parameters
Modify-state (flow-mod)Add, change, or delete flow entries and port settings
Read-stateFetch counters and statistics
Send-packet (packet-out)Make the switch emit a specific packet on a port
Switch to controllerpacket-inA packet matched no entry, or an entry says “ask the controller”
flow-removedAn entry timed out or was deleted
port-statusA port or link went up or down

Going deeper: SDN controller internals covers flow rule fields, multi-table pipelines, controller clustering, and intent reconciliation.

A controller can install rules two ways:

StyleHow it worksTrade-off
ReactiveThe first packet of a flow has no match and goes to the controller as packet-in. The controller decides, installs a rule, and later packets are forwarded by the switchTable stays small. First packet is slow, and a burst of new flows can overload the controller
ProactiveThe controller installs rules ahead of time, from topology and policyNo first-packet delay. Needs more table space and planning

Production networks mostly use proactive rules for the fabric and reactive handling for exceptions.

  1. A leaf switch loses a link to a spine and sends port-status to the controller.
  2. The controller’s state layer marks the link down and notifies the routing application, which subscribed to link events.
  3. The application recomputes shortest paths on the new topology.
  4. The controller sends flow-mod messages to every switch whose rules used the failed link, and traffic moves to the surviving paths.

In a traditional network the same event triggers OSPF flooding and a recalculation on every router. In SDN one computation runs in one place.

Per-router controlSDN
Control logicInside each routerOn the controller servers
Link between planesThe forwarding tableThe flow table
CommunicationRouter to router (OSPF, BGP)Switch to controller (OpenFlow)
TriggerProtocol timers and neighbor updatesEvents such as port-status and packet-in
RecomputationEach router runs its own algorithmThe controller computes and distributes the result

SDN does not replace routing protocols everywhere. Many data centers combine both: BGP or OSPF between devices for the underlay, and a controller for overlays, policy, and virtual networks. See Routing protocols.

SymptomLikely causeFix
First packets of a flow are slow, later ones fastReactive rules: each new flow waits for the controllerInstall rules proactively, or add controller capacity
Traffic stops when the controller restartsThe switch fails closed and has no rules without the controllerChoose the fail mode deliberately. In OVS: ovs-vsctl set-fail-mode br0 standalone (acts as a normal switch) or secure (keeps only installed rules)
A rule shows zero hitsA higher-priority rule matches first, or a missing protocol prerequisiteCheck ovs-ofctl dump-flows for overlapping priorities
New rules are rejectedHardware flow table is fullAggregate rules with wildcards, or move policy into software switches

Middleboxes and network function virtualization

Section titled “Middleboxes and network function virtualization”

A middlebox sits on the path between hosts and does more than forward packets. Three categories cover nearly all of them:

CategoryExamples
Address translationNAT, carrier-grade NAT
SecurityFirewalls, IDS and IPS, email security gateways
PerformanceCaches, load balancers, TCP splitters, compression

See Networking services for NAT and Firewalls for the security side.

Dedicated hardware appliances were costly and hard to scale, each with its own software and management tools. Network function virtualization (NFV) runs the same functions as software on commodity servers. The software stack is common, capacity scales by adding instances, and the functions can be chained and managed centrally.

Hardware applianceNFVCloud-managed service
Runs onProprietary hardwareCommodity servers, VMs, or containersProvider infrastructure
ScalingBuy bigger boxesAdd instancesOn demand
ManagementPer deviceCentral, software-drivenThe provider’s console and API
ExamplesHardware firewall or load balancerVirtual firewall, software load balancerCloud NAT gateway, managed load balancer, security groups

Middleboxes break the original design principle that the network core should be simple and that intelligence belongs on the end hosts. NAT rewrites transport ports, and firewalls and IDS read application data, all inside the network. Purists say this undermines end-to-end communication. Pragmatists answer that address shortage, security, and performance needs would not be met otherwise. See Design principles: narrow waist and end-to-end.

In Kubernetes, the same ideas appear as network policies (distributed firewalling), Services (load balancing and rewriting), and the networking model that CNI plugins implement.