Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Flow tables, matching and pipeline processing

Flow tables hold flow entries that match packet header fields and direct packet processing; pipeline processing means packets pass through a sequence of tables where matches, priorities, instructions and actions determine forwarding and other behaviors.

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

Flow tables and pipeline processing are the core of how a software-defined switch decides what to do with each packet. An engineer uses these ideas when programming an SDN switch (for example through OpenFlow or Open vSwitch) to implement routing, filtering, load balancing or telemetry in data-centre and campus networks.

Key ideas

Start by defining the terms you will see.

  • Packet: a unit of data on the network; for our discussion we treat the header fields (Ethernet, IP, TCP/UDP) as the values that match rules.
  • Flow table: A table in the switch that contains multiple flow entries. A flow table is searched to find a flow entry whose match fields match the packet; the entry then provides instructions and actions for the packet.
  • Flow entry: A record in a flow table. It contains a match (set of packet header fields and optional masks), a priority (numeric), zero or more instructions (such as METER, APPLY_ACTIONS, CLEAR_ACTIONS, WRITE_ACTIONS, GOTO_TABLE, WRITE_METADATA), optional timeouts (idle_timeout, hard_timeout) and counters, and a controller-defined cookie (opaque value; not required to be unique).
  • Match: A pattern against packet fields. Matches may be exact (value equals), masked/prefix (for example IPv4/24) or wildcard (field not considered). The set of matchable fields are the match fields (for example in_port, eth_type, ipv4_src, ipv4_dst, ip_proto, tcp_src).
  • Priority: A numeric value associated with a flow entry. When multiple entries match, the highest-priority entry is selected. If multiple entries of the same highest priority match, the selection is undefined by the spec; controllers must avoid such ties.
  • Instruction: High-level directives attached to an entry. Common instructions are METER, APPLY_ACTIONS (apply these actions immediately to the packet), CLEAR_ACTIONS (clear the action set), WRITE_ACTIONS (merge these actions into the action set, to be applied later), WRITE_METADATA (store metadata for later tables to match on), and GOTO_TABLE (continue processing in the specified next table).
  • Action: A low-level operation such as output to a port, set field, push/pop header, or group-table operations. OpenFlow does not define a literal 'drop' action; dropping is achieved by executing no output actions (ovs-ofctl's actions=drop is a shorthand). Actions can be in the instruction APPLY_ACTIONS or accumulated in the action set.
  • Action set: The set of actions accumulated by WRITE_ACTIONS instructions (initially empty). The action set is applied once, in a fixed order defined by the OpenFlow spec, when pipeline processing ends. APPLY_ACTIONS execute immediately; CLEAR_ACTIONS clears the set.
  • Table-miss: What happens when no entry matches a packet in a table. Controllers typically install an explicit lowest-priority match-all flow (the table-miss entry) whose instructions specify drop, send to controller, or GOTO another table. If no table-miss entry is present, the packet is dropped by default.
  • Pipeline processing: The sequence in which a packet starts at table 0 and may move across tables (0 → 1 → 2 …) following GOTO_TABLE instructions. The packet may be modified by APPLY_ACTIONS or have actions staged with WRITE_ACTIONS while moving through the pipeline.
  • Metadata: A per-packet value that can be written by one table and matched by later tables — useful for tracking state across tables (for example VLAN id tagging for later matching). In OpenFlow 1.3+, metadata is a 64-bit value; its initial value is 0 at pipeline start.

Exact operational rules (as you should write in an exam):

  1. On packet arrival, the switch begins at table 0.
  2. The switch finds all flow entries in the current table whose match conditions are satisfied by the packet and metadata.
  3. Among matching entries, the switch selects the entry with the highest priority. (If there is a priority tie, the result is implementation-defined — controllers must avoid ties.)
  4. The selected entry's instructions are executed in this OpenFlow-defined order: METER, APPLY_ACTIONS (immediate), CLEAR_ACTIONS, WRITE_ACTIONS (merge into the action set), WRITE_METADATA, GOTO_TABLE (to a higher-numbered table only).
  5. If a GOTO_TABLE instruction is present, processing continues at the target table (packet and metadata as modified). Otherwise the pipeline ends and the action set is applied once (for example, executing OUTPUT actions). If the applied action set contains no output, the packet is dropped.
  6. If no entry matches, the table-miss behavior applies (usually drop or send-to-controller or goto specified table).

Diagram to draw for an exam: Draw three boxes labelled "Table 0", "Table 1", "Table 2" in a horizontal row. From an input arrow (label it "incoming packet + metadata=0"), point to Table 0. Inside each table box draw rows: Match | Priority | Instructions | Actions. From Table 0 draw a GOTO arrow to Table 1 on matching a certain entry. Indicate APPLY_ACTIONS modifying packet fields and WRITE_ACTIONS being added to action set. At the right of Table 2 draw an action-set box and an OUTPUT arrow to show final output.

Assumptions to state in answers: assume the OpenFlow model (multi-table pipeline), that priorities are numeric and higher value means higher precedence, that matches are evaluated on the current packet headers and metadata, and that controllers may insert explicit table-miss entries.

Formulas

This topic is mainly syntax and procedure rather than numeric formulas. Remember these command / syntax patterns (example uses ovs-ofctl style): add-flow 'table=<n>,priority=<p>,in_port=<port>,eth_type=0x0800,ipv4_dst=<addr>/<mask>,ip_proto=6,tcp_dst=<port>,actions=<action-list>' Meaning: add a flow to table n with given priority and match fields; actions list is comma-separated, e.g. output:2,set_field:10.0.0.5->ipv4_dst. Example match syntax elements to remember: in_port, eth_type, ipv4_src, ipv4_dst (optionally /mask), ip_proto (6 for TCP, 17 for UDP) a.k.a. nw_proto in older OVS syntax, tcp_src/tcp_dst a.k.a. tp_src/tp_dst, vlan_vid. Important instruction/action names to remember: apply_actions, write_actions, goto_table:<n>, write_metadata:<value>/<mask>, meter:<id>, group:<id>, output:<port>, set_field:<value>-><field>.

Worked examples

Example 1 — Pipeline trace with two tables Given: Table 0 entries:

  • E0: priority=200, match in_port=1, ip, instructions: write_metadata:0x100/0xfff, goto_table:1
  • E1: priority=100, match in_port=1, instructions: apply_actions:output:CONTROLLER Table 1 entries:
  • E2: priority=100, match metadata=0x100/0xfff, ip_proto=6, tcp_dst=80, instructions: apply_actions:set_field:10.0.0.5->ipv4_dst, write_actions:output:2
  • Table-miss in Table 1: drop Trace packet: packet arrives on port 1, IPv4 TCP dst port 80. Step 1: Start at Table 0. The packet is IPv4 on in_port=1, so both E0 (in_port=1, ip) and E1 (in_port=1) match. E0 has priority 200 > 100, so E0 is chosen. Step 2: Execute E0 instructions: write_metadata sets metadata=0x100; goto_table=1 causes pipeline to continue to Table 1. Step 3: Table 1 matching: E2 matches (metadata and tcp dst 80). Execute E2: APPLY_ACTIONS set_field modifies packet's ipv4_dst to 10.0.0.5 immediately. WRITE_ACTIONS adds output:2 to action set. Step 4: No GOTO_TABLE in E2, so pipeline ends. Execute action set: output:2 sends packet out of port 2 with modified dst IP. Final: packet forwarded out port 2 with destination IP 10.0.0.5. (Bold final result in exam answers.)

Example 2 — Match conflict and priorities Table 0 entries:

  • A: priority=300, match ipv4_dst=10.1.0.0/16, actions=output:2
  • B: priority=200, match ipv4_dst=10.1.1.5 (exact), actions=output:3 Packet has ipv4_dst=10.1.1.5. Step 1: Both A and B match because the /16 covers 10.1.1.5 and the exact match also matches. Step 2: Higher priority is A (300) so A will be selected — packet forwarded to port 2. Students often expect exact match to win; remind that priority number matters, not mask length. If the controller wanted the exact host route to take precedence it must set its priority higher than 300. Final: packet -> port 2.

Example 3 — Flow add command (small practical) Command to add a flow matching TCP dst 80 from port 1 and output to port 2 in table 0 with priority 150: ovs-ofctl add-flow br0 "table=0,priority=150,in_port=1,ip,nw_proto=6,tp_dst=80,actions=output:2" (Exact syntax may vary by ovs-ofctl/OpenFlow version; exam answers should show the pattern.)

Common mistakes

  • Forgetting to set or check table-miss behavior — then unexpected drops occur.
  • Relying on unspecified tie-breaking when two entries have identical priority; controllers should avoid priority ties.
  • Assuming GOTO_TABLE implicitly applies actions — GOTO_TABLE only continues the pipeline; the action set is applied once at the end (and can be cleared only by CLEAR_ACTIONS).
  • Using different syntax versions of ovs-ofctl without checking the installed OpenFlow version (1.0 versus 1.3 differences matter).

For your exam

Kinds of questions you will see:

  • Definitions: define flow table, flow entry, action set, table-miss, metadata — short precise definitions earn marks.
  • Short notes: explain APPLY_ACTIONS vs WRITE_ACTIONS; explain metadata use; explain table-miss handling.
  • Derivations / procedural: show step-by-step how a given packet is processed through a two- or three-table pipeline (draw the diagram and annotate each step). Always state assumptions (OpenFlow model, priority rule).
  • Programs / commands: write an ovs-ofctl add-flow command to implement a rule; show how to add a table-miss rule to send unknown packets to controller.
  • Diagrams: draw the pipeline boxes, show action set and immediate actions — label flows and GOTO arrows. What a full-marks answer includes: clear definitions, a correct diagram labelled as above, an explicit step-by-step trace showing which entries match, how priority is chosen, what instructions execute and their order, and the final actions taken. If asked for commands, provide correct syntax and mention OpenFlow version restrictions.

Quick check

  1. What decides which of several matching flow entries is selected for a packet?
  2. How does APPLY_ACTIONS differ from WRITE_ACTIONS in pipeline processing?
  3. What is the usual starting table number when a packet enters an OpenFlow pipeline? Answers: 1) The entry with the highest numeric priority is selected (avoid priority ties). 2) APPLY_ACTIONS are executed immediately and affect the packet headers seen by later tables; WRITE_ACTIONS add to the action set that is executed when the pipeline finishes. 3) Table 0.

(Notes for the reviewer: I have used the OpenFlow pipeline model and ovs-ofctl syntax as examples. Where exact OpenFlow spec wording differs between versions I have summarized the common model. I flagged places you should verify listed below.)

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?