Northbound APIs and SDN programming
Northbound APIs let SDN applications talk to the SDN controller (query network state and request control actions) — usually using REST/RESTCONF/gRPC and model-driven data (YANG), and SDN programming means writing apps that use these APIs to implement routing, security and orchestration logic.
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
Network engineers and software developers use Northbound APIs when they write controller applications to automate network tasks (topology discovery, path computation, flow installation, telemetry). Clear understanding lets you design programs that are portable across controllers and that correctly read network state and push control intents.
Key ideas
Controller application: software that runs on or beside the controller and uses the NB API to implement policies (load balancing, access control). It may be called an SDN app.
REST (Representational State Transfer): an architectural style for networked applications using HTTP verbs (GET, POST, PUT, DELETE). For SDN NB APIs, REST is common because it is simple and language-agnostic. Assumption: controller exposes resource URIs that map to network objects (flows, switches, ports). Also, GET is safe, PUT is idempotent, and POST typically creates resources. Event subscriptions are often delivered via WebSockets, Server-Sent Events, or long-polling since plain REST is request/response.
YANG: a data modelling language for configuration and state data. Used with NETCONF and RESTCONF. Definition: YANG is a language that defines hierarchical data schemas for network configuration and operational data.
NETCONF: an RPC-based protocol to read/write network configuration using XML over SSH. Assumption: device or controller supports NETCONF server. In SDN architectures, NETCONF is most commonly used southbound on devices; controllers more often expose RESTCONF/REST on the northbound.
RESTCONF: a REST-like mapping of YANG-defined data over HTTP. It provides similar semantics to NETCONF but with HTTP operations and JSON/XML payloads.
gRPC / Protocol Buffers: a binary, RPC framework for efficient, strongly-typed NB APIs. Definition: gRPC uses Protocol Buffers for message schema, and supports bi-directional streaming useful for telemetry.
Model-Driven APIs: APIs that expose data following a schema (YANG). Exact property: model-driven APIs enable programmatic validation, code generation and consistent representations across controllers.
Intent-based API: a higher abstraction where the app specifies what it wants (an intent) and the controller computes how to implement it. Definition: an intent is a declarative description of desired state (e.g., “connect host A to host B with bandwidth X”). Assumption: controller translates intent to flows or paths.
Relationship to other topics: NB API sits above the controller and uses data gathered via southbound protocols (e.g., OpenFlow, OVSDB, NETCONF, gNMI). Applications using the NB API implement logic required for data centre needs and NFV orchestration.
Diagrams to draw in an exam answer (label every box):
- A vertical stack: top row "Applications / Orchestrator (NB Apps)"; middle "SDN Controller (NB API, DB, Path computation)"; bottom "Network Devices (switches)" with arrows: Apps -> Controller labelled "Northbound API (REST/gRPC)" and Controller -> Switches labelled "Southbound API (OpenFlow/OVSDB/NETCONF/gNMI/P4Runtime)". Also show Apps reading "Topology" and writing "Flow rules".
Formulas
For programming and APIs, remember these syntax and common HTTP patterns (each on its own line):
GET /api/topology — retrieve current topology (may return JSON list of switches/links)
GET /api/switches/{id}/ports — retrieve ports of a switch
POST /api/flows — create (install) a flow; body contains match/actions JSON
PUT /api/flows/{flow-id} — update an existing flow (use PATCH for partial updates if supported)
DELETE /api/flows/{flow-id} — remove a flow
Content-Type: application/json — header used when body is JSON; also send Accept: application/json as appropriate. Prefer HTTPS endpoints and validate TLS certificates in production.
Authorization: Basic <base64(user:pass)> or Authorization: Bearer <token> — common auth headers
grpc.Call(RouteRequest) — generic gRPC client call; specific syntax depends on generated stubs
<rpc><get-config>... (NETCONF over SSH) — NETCONF XML RPC example (controller/device dependent)
When using YANG/RESTCONF remember base path form: /restconf/data/<module>:<container>. Use Accept: application/yang-data+json and Content-Type: application/yang-data+json for data resources; RPCs live under /restconf/operations.
Worked examples
Example 1 — Install a simple flow using REST (exam-style trace): Problem: Host H1 (MAC a1) attached to switch S1 port 1 must send to host H2 (MAC a2) on port 2. Install a flow on S1 to forward frames with destination MAC a2 out port 2.
Assumptions: controller exposes a REST endpoint POST /api/flows and accepts JSON { "switch": "s1", "priority": 100, "match": {"eth_dst": "aa:bb:cc:dd:ee:02"}, "actions": [{"output":2}] }.
Steps:
- Compose JSON body:
{ "switch": "s1", "priority": 100, "match": {"eth_dst": "aa:bb:cc:dd:ee:02"}, "actions": [{"output":2}] }. - HTTP request (curl):
curl -u admin:admin -H "Content-Type: application/json" -X POST http://controller:8080/api/flows -d '<body>' - Expected server response: HTTP 200 OK or 201 Created (controller-specific) with a flow identifier in the response body or Location header.
- Controller programs S1 via southbound (OpenFlow) with a flow matching eth_dst=aa:bb:cc:dd:ee:02 and action output:2.
Expected observable effect: frames to MAC aa:bb:cc:dd:ee:02 are forwarded out port 2. If testing in Mininet, verify with ping or arp and ovs-ofctl dump-flows on the switch.
Example 2 — Simple SDN app algorithm traced on a small network (theory/model answer): Network: S1--S2--S3 in a line. Hosts: H1 on S1 port 1, H2 on S3 port 1. Objective: install shortest-path flows both directions using controller NB API that provides topology and a flows endpoint.
Algorithm (high-level):
- Controller app calls
GET /api/topology-> receives nodes [S1,S2,S3] and links [(S1,S2),(S2,S3)]. - Compute shortest path S1->S3 = [S1,S2,S3]. Explanation: path length metric = hop count.
- For each switch on path, compute output port toward next-hop. For S1: out-port to S2 = p12; S2: out-port to S3 = p23; S3: out-port to host = p3h.
- POST flows for each switch with matches for src/dst IP or MAC. Example for S2:
POST /api/flowsbody includesswitch: "S2", match: {ipv4_src: "10.0.0.1/32", ipv4_dst: "10.0.0.2/32"}, actions: [{output: p23}].
Trace on S2: after steps it receives a flow with priority 200 matching H1->H2 and outputs to S3. Reverse direction similar.
This is a model answer: include explicit REST calls, show computed ports, and state assumptions (controller has accurate topology and mapping host->switch/port).
Common mistakes
- Forgetting authentication and receiving 401/403 in exams when showing curl examples.
- Using wrong Content-Type (e.g., sending JSON but header not set) causing 415 Unsupported Media Type.
- Not handling asynchronous events: assuming GET immediately reflects a newly pushed flow without considering eventual consistency or processing delay.
- Hard-coding switch IDs or port numbers without showing how they were discovered via topology API.
- Installing overlapping flows without correct priorities — causing unexpected packet handling.
For your exam
Common question types:
- Definitions and short notes: define NB API, RESTCONF, YANG, intent-based APIs. Full mark answer: give formal definition, assumptions and one example use-case.
- Diagram and explanation: draw the SDN stack showing NB and SB APIs and explain traffic flow for a simple policy. Full mark answer: draw labeled stack, arrows, and explain a sample operation (app requests path, controller programs flows southbound).
- Derivation/algorithm question: given a small topology, show steps of an app that computes shortest path and installs flows. Full mark answer: request topology via API, show Dijkstra or simple BFS steps, compute output ports and show exact REST calls or flow entries.
- Programming snippet: write a small Python function that queries topology and posts a flow. Full mark answer: include requests usage, auth header, JSON body and error handling.
- Practical/behavioural question: differences between RESTCONF and gRPC for telemetry. Full mark answer: compare data format, streaming, performance, and when to choose which.
What to include for full marks:
- State assumptions (controller features, authentication, topology freshness).
- Give exact API method and sample JSON or pseudo-code.
- Explain error handling (HTTP codes) and that higher numeric values mean higher priority for flows (e.g., OpenFlow).
- If asked for a diagram, include labelled boxes and arrows.
Quick check
- What is the purpose of a northbound API in SDN?
- Name two data models or protocols commonly used with northbound APIs.
- Why must you check flow priorities when installing overlapping flows?
Answers: 1. To let controller applications read network state and request control actions from the controller. 2. YANG/RESTCONF and gRPC/Protocol Buffers (also REST with JSON). 3. Because priority decides which flow matches packets when multiple flow entries overlap; wrong priority causes incorrect forwarding.
Note for the reviewer: I have explained controller endpoints generically because actual URIs and JSON schemas differ between controllers (OpenDaylight, Floodlight, ONOS). I have not assumed any single-controller exact endpoint names.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?