The idea: split deciding from forwarding

Every network box does two jobs. The data plane moves packets: look at the header, pick an output port, send. The control plane decides where packets should go: it learns addresses, runs routing protocols and fills the tables the data plane reads. In a classic switch or router both jobs live in the same box, and every box decides for itself.

Left, a traditional network: three boxes, each with its own control plane on top of its own data plane, talking to each other with routing protocols. Right, SDN: one controller holds the control plane for the whole network and sends rules over OpenFlow to three switches that hold only a flow table.
Traditional: every box decides for itself. SDN: one controller decides, the switches only look rules up.

Software-defined networking (SDN) takes the control plane out of the boxes and puts it in one program, the controller. The switch keeps only the data plane: a flow table of rules. OpenFlow is the protocol between the two. The controller uses it to add and remove rules; the switch uses it to ask what to do with a packet it has no rule for. On the canvas the controller is c0 at the top and the switch is s1 in the middle, with four hosts on its four ports.

The first packet of a flow

A new switch knows nothing. Its table holds one rule, the table-miss entry: priority 0, matches anything, action "send to the controller". So the first packet of every flow takes a detour (Demo: first packet misses, next ones match):

  1. The packet matches only the table-miss entry. The switch sends its headers up in a PACKET_IN message and keeps the packet waiting.
  2. The controller's program looks at the headers and decides. It sends a FLOW_MOD: a new rule for this kind of packet.
  3. It also sends a PACKET_OUT: what to do with the packet that is waiting.
  4. The second packet of the flow matches the new rule in the switch. The controller never sees it.
Time runs down between host h1, switch s1, controller c0 and host h3. Packet 1 from h1 misses in s1, goes up as PACKET_IN, the controller sends FLOW_MOD and PACKET_OUT down, and the packet reaches h3. Packets 2 and 3 match the rule in s1 and go straight to h3 without touching the controller.
Only the first packet of a flow visits the controller. After the FLOW_MOD, the switch handles the flow alone.

This is called reactive flow setup. The detour costs time (a round trip to the controller), so the first packet is slow and the rest are fast. A controller can also install rules before any traffic arrives; that is proactive setup, and the firewall's drop rule on this page is installed that way.

Look at the counters after the first demo. Three packets were sent, but the new rule shows n_packets 2 and the table-miss entry shows 1. The first packet was sent by the PACKET_OUT, not by the rule.

Match + actions: one switch, four jobs

A rule has two halves. The match names header fields and the values they must have: in_port, eth_dst, ipv4_src, ipv4_dst, tcp_dst and many more. A field that is not named matches anything. The actions say what to do: send out a port, rewrite a field, lower the TTL, or nothing at all, which means drop.

The switch has no idea what kind of device it is. The rules decide that:

controller appmatchactionsthe switch behaves as
L2 switcheth_dst=…:03output:3an Ethernet switch: forward by destination MAC
routeripv4_dst=10.0.2.3dec_ttl, set eth_dst=…:03, output:3a router: forward by destination IP, lower the TTL, rewrite the MAC
firewalltcp_dst=22 at priority 200none (drop)a packet filter: ssh is blocked, the rest is switched
load balanceripv4_src=10.0.1.1, ipv4_dst=10.0.2.100, tcp_dst=80set ipv4_dst=10.0.2.3, output:3a load balancer: one virtual IP, clients spread over h3 and h4

In Demo: the same switch as a router the packet arrives with TTL 64 and leaves with TTL 63 and h3's MAC. In Demo: load balancer spreads two clients both clients send to 10.0.2.100; the controller picks h3 for h1 and h4 for h2, and after four packets each server has received 2.

Priority, counters and idle timeout

More than one rule can match a packet. Then the rule with the highest priority wins, and only that rule runs. In Demo: firewall rule wins by priority an ssh packet to h3 matches two rules: eth_dst=…:03 at priority 10 says forward, tcp_dst=22 at priority 200 says drop. It is dropped. The table-miss entry works the same way: it matches everything, but at priority 0 it only wins when nothing else fits.

Every rule has counters. n_packets goes up each time the rule wins. The controller can read them to see how much traffic each flow carries.

A rule can also carry an idle timeout. Each match restarts the timer. If no packet matches for that long, the switch removes the rule and tells the controller with a FLOW_REMOVED message that includes the final counters. On this page reactive rules have idle_timeout=10. In Demo: idle timeout removes a rule the rule is used at t = 5 s, runs out at t = 15 s with n_packets=1, and the next packet misses again. Timeouts keep the table small: a flow that ended does not hold a row for ever. (There is also a hard_timeout that removes a rule after a fixed time, used or not.)

When the controller is unreachable

The controller is one program on one machine, and the switch needs it for every new flow. What if the connection is lost? In fail-secure mode the switch changes only one thing: packets meant for the controller are dropped. Rules already in the table keep forwarding. But their timeouts keep running, and nobody installs them again.

Demo: controller unreachable shows all three effects. The known flow h1 → h3 still works. The new flow h2 → h4 misses and is dropped. Ten seconds later the h1 → h3 rule has timed out, and that flow is dropped too. When the controller comes back, the next packet misses, asks, and the flow works again. Final count: 5 packets sent, 3 delivered, 2 dropped.

The other choice is fail-standalone: the switch falls back to acting as a plain learning switch until the controller returns. Real networks also run several controllers, so that losing one is not the end.

See also hub, switch and router for the classic boxes, and the stateful firewall, which remembers connections, something a plain flow table does not do.

What the page leaves out

The controller here already knows where every host is. A real one learns that from the PACKET_INs, floods packets for unknown addresses, and answers or forwards ARP. Only one direction of each flow is shown; replies need their own rules, and a load balancer must also rewrite the reply's source back to the virtual IP and the request's destination MAC. Real switches have several flow tables chained with goto_table, group tables, meters, hard_timeout, byte counters and wildcard masks such as 10.0.2.0/24. The channel's own messages (HELLO, FEATURES_REQUEST, ECHO) and its TLS are skipped, and so are buffer ids, several controllers with roles, and the rule that overlapping matches at the same priority are undefined.

On the mind map

Open the Networking mind mapNetworkingLayers & links: frames on one local networkLayers & linksIP & routing: packets hop between networksIP & routingCore services: address, name and timeCore servicesTCP, UDP & sockets: end to end between two portsTCP, UDP & socketsHTTP & TLS: what a browser does per requestHTTP & TLSAPIs & push: how apps talk to serversAPIs & pushProxies & edge: boxes in the middle of the pathProxies & edgeContainers: virtual networks from Linux partsContainersReal-time media: voice and video over UDPReal-time mediaSecurity at the edge: filter traffic at the borderSecurity at the edgeRouter forwardingRouter forwardinglongest prefix match picks the next hopVRRP / HSRP failoverVRRP / HSRP failoverBackup takes over the gateway in 3.6 sSDN and OpenFlowcontroller writes rules, switch looks upTracerouteTracerouteTTL 1, 2, 3: each hop sends Time ExceededNATNATmaps private IP:port to one public IPIPv4 vs IPv6IPv4 vs IPv632 vs 128 bits; SLAAC, no NAT neededAnycast and BGPAnycast and BGPsame prefix announced from many sitesOSPF and BGP policyOSPF and BGP policyPolicy first, then path, then IGP costDistance vector vs link stateDistance vector vs link stateRIP shares distances; OSPF floods the mapSubnets and CIDRSubnets and CIDR/24 = mask: same subnet? ARP, else routerVLSM PlanningVLSM PlanningLargest first: no gaps, one summary routeRouter queues and AQMRouter queues and AQMFull buffers add delay; drop earlyDelay, loss, throughputDelay, loss, throughputSlowest link sets pace; full buffer dropsOpen the Networking mind mapNetworkingpackets hop between networksIP & routingRouter forwardingRouter forwardinglongest prefix match picks the next hopVRRP / HSRP failoverVRRP / HSRP failoverBackup takes over the gateway in 3.6 sSDN and OpenFlowcontroller writes rules, switch looks upTracerouteTracerouteTTL 1, 2, 3: each hop sends Time ExceededNATNATmaps private IP:port to one public IPIPv4 vs IPv6IPv4 vs IPv632 vs 128 bits; SLAAC, no NAT neededAnycast and BGPAnycast and BGPsame prefix announced from many sitesOSPF and BGP policyOSPF and BGP policyPolicy first, then path, then IGP costDistance vector vs link stateDistance vector vs link stateRIP shares distances; OSPF floods the mapSubnets and CIDRSubnets and CIDR/24 = mask: same subnet? ARP, else routerVLSM PlanningVLSM PlanningLargest first: no gaps, one summary routeRouter queues and AQMRouter queues and AQMFull buffers add delay; drop earlyDelay, loss, throughputDelay, loss, throughputSlowest link sets pace; full buffer drops
This page on the Networking mind map · 62 pages in 10 branches · open it to see the whole map and test yourself in recall mode.