Computer Networking › Section D · The network layer: data plane › Topic D.6
Generalized forwarding and SDN
A classic router looks at one field, the destination address, and picks an output link. Generalised forwarding lets a device match on almost any header field and then forward, drop, copy or rewrite the packet, turning routers, firewalls and NATs into one programmable kind of box.
From destination-based to match-plus-action
Destination-based forwarding, as described in Inside a router, takes two steps: look up the destination IP address, then send the datagram to an output port. Generalised forwarding keeps the two-step shape but widens both steps. The match can use fields from several layers at once: link-layer addresses, IP addresses, the transport protocol and port numbers. The action can forward to one or many ports, drop the packet, rewrite header fields, or hand the packet to a remote controller. This match-plus-action idea is the data-plane half of software-defined networking (SDN); the controller that writes the rules is the control-plane half.
Flow tables
In SDN a packet switch holds a flow table, a match-plus-action table installed by a remote controller. Each entry has three parts. A set of header values to match, in which any field can be a wildcard; for example, IP destination 10.2.0.0/16 with every other field set to any. A set of counters, recording how many packets and bytes have matched and when the entry was last used. And a set of actions to apply to matching packets. Entries also carry a priority, because a packet can match several entries and the switch must use the highest-priority one. The best-known standard for such tables and the messages that manage them is OpenFlow.
What can be matched
OpenFlow 1.0, the first widely deployed version, defined twelve match fields drawn from three layers. From the link layer: the switch's input port, source and destination MAC addresses, the Ethernet type (such as 0x0800 for IPv4 or 0x0806 for ARP), the VLAN identifier and VLAN priority. From the network layer: source and destination IP addresses, the IP protocol number and the service bits. From the transport layer: source and destination TCP or UDP ports. Later versions added many more fields, including IPv6 and MPLS, and pipelines of several tables. The set is deliberately limited: matching every possible field would make switch hardware slow and costly.
What actions can do
The core actions are few. Forward sends the packet out of one port, out of all ports except the one it arrived on (flooding), or to the controller. Drop discards it; an entry with no action at all has the same effect. Modify-field rewrites header values, such as MAC or IP addresses or port numbers, before forwarding. Actions can be combined: rewrite a destination address and then forward. A table-miss entry, at the lowest priority with every field wildcarded, decides what happens to packets that match nothing else; a common choice is to send them to the controller, which can then install a new rule.
Worked example: reading a flow table
A switch has four entries. Priority 300: IP destination 10.2.0.7 and TCP destination port 22, action drop. Priority 200: IP destination 10.2.0.0/16, forward to port 3. Priority 100: input port 1, forward to port 2. Priority 0: everything, send to controller. 1. A TCP packet for 10.2.0.7 port 22 matches 300, 200 and 0; 300 wins, so it is dropped. 2. A TCP packet for 10.2.0.7 port 443 matches 200 and 0: port 3. 3. A UDP packet for 10.9.1.1 arriving on port 1 matches 100 and 0: port 2. 4. The same packet arriving on port 4 matches only the table-miss entry: controller. Check: each packet took its highest-priority match.
One abstraction, many devices
Match-plus-action can imitate devices that used to be separate boxes. A router matches the longest destination prefix and forwards. A link-layer switch matches the destination MAC address and forwards, flooding when it does not know where a MAC address lives. A firewall matches addresses and ports and drops what policy forbids. A NAT matches a connection and rewrites addresses and ports. A load balancer matches traffic for one service address and rewrites it towards one of several servers. The controller picks the behaviour by choosing which entries to install, so one switch can play several of these roles at once.
Worked example: a load balancer from flow rules
Web traffic for a service address, 10.0.0.100 port 80, must be split between two servers, 10.0.1.11 and 10.0.1.12. 1. Clients sit in 10.5.0.0/16, which splits into 10.5.0.0/17 and 10.5.128.0/17. 2. Entry A: IP source 10.5.0.0/17, destination 10.0.0.100, TCP port 80; actions: set IP destination to 10.0.1.11, forward to port 5. 3. Entry B: the same but with source 10.5.128.0/17; set destination to 10.0.1.12, forward to port 6. 4. Matching return entries rewrite the servers' source address back to 10.0.0.100. Check: a client at 10.5.200.3 falls in the upper /17, so it always reaches 10.0.1.12, keeping each connection on one server.
Counters and programmable data planes
Because every entry counts packets and bytes, the controller can read per-flow traffic at any time, which helps with measurement, billing and spotting an attack. An entry can also expire after a timeout, so rules for finished flows clear themselves. OpenFlow fixes the list of headers a switch understands. Programmable data planes go further: in the P4 language, an operator describes how the switch parses headers, which tables it has and which fields they match, and compiles that onto a programmable switching chip. A new protocol header then needs new code, not new hardware.
Common mistakes to avoid
First, thinking generalised forwarding uses only the destination address; it can match link, network and transport fields together. Second, using the first matching entry instead of the highest-priority one. Third, assuming every packet goes to the controller; normally only table misses or explicitly marked packets do, and the switch forwards the rest in hardware. Fourth, forgetting that a NAT or load balancer built from rules needs matching return-path entries. Fifth, confusing the flow table, which the switch uses on each packet, with the controller's logic that decides what the table should contain.
Key takeaways
Generalised forwarding replaces lookup-the-destination with match-plus-action. An SDN switch's flow table, installed by a remote controller and standardised by OpenFlow, has match fields with wildcards, counters, actions and priorities. OpenFlow 1.0 matched twelve fields across the link, network and transport layers. Actions forward, flood, send to the controller, drop or modify fields, and a table-miss entry catches the rest. One abstraction can act as a router, switch, firewall, NAT or load balancer. Counters support measurement, and P4 makes the parser and tables themselves programmable.
Flashcards
Flashcard
Match on many header fields, then take one or more actions
Test your understanding
Question 1 of 5
A switch holds: priority 300, IP destination 10.2.0.7 and TCP port 22, drop; priority 200, IP destination 10.2.0.0/16, forward to port 3; priority 0, send to controller. What happens to a TCP packet for 10.2.0.7 port 22?
Question 2 of 5
Which set of fields could an OpenFlow 1.0 entry match in a single rule?
Question 3 of 5
Which action lets a flow-table switch behave like a NAT?
Question 4 of 5
A packet arrives that matches no entry except the lowest-priority catch-all. What is this entry called, and what does it commonly do?
Question 5 of 5
Why does each flow-table entry keep counters?
