10 – The Network Layer: Routing, Forwarding and Inside a Router
Course: ICT Basic course · Level: introductory Book: Kurose & Ross, 9th ed., chapter 4 (network layer: data plane, 4.1–4.2) and chapter 5 (control plane: routing algorithms, OSPF, BGP, SDN – overview)
Learning goals
After this article you can:
- describe the job of the network layer and its best-effort service model;
- explain the difference between forwarding (data plane) and routing (control plane);
- explain how a router uses a forwarding table with longest prefix matching;
- describe the parts of a router and where packet loss happens;
- name the main routing protocols (OSPF, BGP) and explain the idea of Software-Defined Networking (SDN);
- use
ip route,tracerouteandmtr.
1. What does the network layer do?
The network layer moves datagrams from the sending host to the receiving host, across many routers.
- Sender: wraps transport-layer segments in IP datagrams.
- Routers: look at the IP header of every passing datagram and forward it.
- Receiver: unwraps the datagram and hands the segment to the transport layer.
Unlike the transport layer, the network layer runs in every host and every router.
Service model: best effort
The Internet's IP service gives no guarantees of delivery, order, delay or bandwidth. This sounds bad, but it works very well because:
- it's simple, so it could spread everywhere;
- enough capacity (overprovisioning) keeps most networks fast;
- reliability is added at the edges (TCP/QUIC), content is moved closer to users (CDNs), and applications adapt (adaptive video streaming).
2. Two key functions: forwarding and routing
| Forwarding | Routing | |
|---|---|---|
| What | move a packet from a router's input port to the right output port | determine the route (path) packets take from source to destination |
| Scope | local, one router | network-wide |
| Speed | nanoseconds, in hardware | seconds, in software |
| Plane | data plane | control plane |
| Analogy | choosing the right exit at one roundabout | planning the whole trip with a route planner |
Forwarding table and longest prefix matching
Routers don't store every IP address (there are billions). They store address ranges (prefixes):
| Destination prefix | Output link |
|---|---|
| 11001000 00010111 00010 * (200.23.16.0/21) | 0 |
| 11001000 00010111 00011000 ** (200.23.24.0/24) | 1 |
| 11001000 00010111 00011 * (200.23.24.0/21) | 2 |
| otherwise (0.0.0.0/0 – default route) | 3 |
Longest prefix match: if an address matches several entries, the router uses the most specific one (the longest prefix). Example: 200.23.24.170 matches /24 (link 1) and /21 (link 2) → the /24 wins → link 1.
Routers use special memory, TCAM, to do this lookup in one clock cycle.
Your own routing table
1 2 3 | |
3. Inside a router
1 2 3 4 5 6 7 | |
- Input port: receives bits (physical), unpacks frames (link layer), looks up the output port in the forwarding table. If the switching fabric is busy, packets wait in an input queue.
- Switching fabric: connects input ports to output ports. Types: memory, bus, interconnection network (crossbar). You only need to understand its role, not the details.
- Output port: queues packets until the link is free, then transmits them.
- Routing processor: runs routing protocols and management, and fills the forwarding tables (traditional routers), or talks to a remote SDN controller.
Where is packet loss?
When packets arrive faster than they can leave, queues build up at the output port (and sometimes the input port). When the buffer is full, packets are dropped. Which packet is dropped or sent first depends on the scheduling policy (FIFO, priority, fair queuing) and the drop policy (drop-tail, or AQM like RED/CoDel that drops early).
4. Routing protocols (overview)
Two families of routing algorithms:
- Link-state (e.g. OSPF, IS-IS): every router knows the complete network map and computes the shortest paths with Dijkstra's algorithm.
- Distance-vector (e.g. RIP, now legacy): routers only tell their neighbours "I can reach X at cost Y" (Bellman-Ford).
The Internet has two levels of routing:
| Level | Protocol | Purpose |
|---|---|---|
| Intra-AS (inside one network) | OSPF, IS-IS, (EIGRP – Cisco) | find the fastest path inside a company or ISP network |
| Inter-AS (between networks) | BGP (Border Gateway Protocol) | exchange reachability of prefixes between the ~75,000+ Autonomous Systems; routes are chosen mainly based on business policy (customer, peer, provider) |
Still in use? RIP is outdated, but you may still find it in very small or old networks and in teaching labs. OSPF and BGP are the standards.
5. Software-Defined Networking (SDN)
Traditional: every router has its own control plane and runs routing protocols with its neighbours (distributed).
SDN: the control plane is moved to a (logically) central controller. The controller computes the forwarding rules and installs them in simple switches via an open interface (originally OpenFlow). Rules can match on many header fields (MAC, IP, ports) with actions like forward, drop, modify → generalised forwarding ("match + action").
1 2 3 4 5 | |
Where is it used today? Google's B4 backbone between data centres, cloud networks (AWS, Azure virtual networks), SD-WAN for connecting company branch offices, network virtualisation in data centres (VMware NSX, Cisco ACI), and 5G core networks. Programmable switches using the P4 language go further than OpenFlow.
6. Try it yourself
ip route(orroute printon Windows): what is your default gateway?traceroute www.google.com/tracert www.google.comandmtr www.hva.nl: how many hops? Where does the traffic leave your provider's network? (Tip: look up unknown router IPs at https://bgp.he.net/.)- Longest prefix match: given the table in section 2, which link is used for 200.23.17.5? For 200.23.31.200? For 8.8.8.8?
- Look at the BGP routes for an HvA address: https://bgp.he.net/ → search for "SURF" (AS1103). How many prefixes does SURF announce?
- Kurose & Ross Wireshark IP exercise: https://gaia.cs.umass.edu/kurose_ross/wireshark.php (traceroute trace, TTL field).
Check your understanding
- What is the difference between forwarding and routing? Which one is the data plane?
- What does "best effort" mean?
- Explain longest prefix matching with an example.
- Where in a router can packet loss happen, and why?
- What is the difference between OSPF and BGP?
- What is the main idea of SDN?
References
Book
- Kurose & Ross, 9th ed., chapter 4.1–4.2 (overview, inside a router), 4.4 (generalised forwarding and SDN), chapter 5 (routing algorithms, OSPF, BGP, SDN control plane)
Videos
- Code.org – The Internet: Packets, Routing & Reliability https://www.youtube.com/watch?v=AYdF7b3nMto
- CrashCourse CS #29 – The Internet https://www.youtube.com/watch?v=AEaKrq3SpW8
- Jim Kurose's video lectures, chapters 4 and 5 – https://gaia.cs.umass.edu/kurose_ross/lectures.php
- Professor Messer – CompTIA Network+ N10-009 course (routing sections) – https://www.youtube.com/playlist?list=PLG49S3nxzAnl_tQe3kvnmeMid0mjF8Le8
Articles and tools
- Hurricane Electric BGP Toolkit – https://bgp.he.net/
- RIPEstat – information about any IP prefix or AS – https://stat.ripe.net/
- P4 Language Consortium – https://p4.org/
Cyber Security
Why is this important for cyber security?
- Routers see and control all traffic. A compromised router can read, redirect or block everything. Edge routers, firewalls and VPN appliances are popular targets of state hackers (e.g. campaigns by groups such as "Volt Typhoon" and "Salt Typhoon" against ISP and government routers).
- BGP is based on trust. Any network can announce any prefix. Mistakes or attacks (BGP hijacking / route leaks) can redirect or black-hole traffic for whole countries or companies. Examples: Pakistan Telecom accidentally took YouTube offline worldwide (2008); in 2018 attackers hijacked Amazon DNS prefixes to steal cryptocurrency; Facebook took itself off the Internet with a BGP configuration error (2021).
- The control plane is a single target in SDN. If an attacker takes over the SDN controller, they control the whole network.
- Traceroute and ICMP reveal network structure to attackers (reconnaissance).
What can you do to make it safe?
- RPKI (Resource Public Key Infrastructure): IP address holders sign which AS may announce their prefixes (ROAs); routers drop invalid announcements (Route Origin Validation). Most large networks, including many Dutch ISPs, now use it. Check your own ISP at https://isbgpsafeyet.com/.
- MANRS (Mutually Agreed Norms for Routing Security): good practice for network operators (filtering, anti-spoofing, coordination).
- Harden routers: change default credentials, use SSH (not Telnet) for management, put the management interface on a separate network, disable unused services, apply firmware updates quickly, and replace end-of-life devices.
- Protect routing protocols: authentication on OSPF/BGP sessions, prefix filters, maximum-prefix limits.
- SDN: secure and authenticate controller ↔ switch communication (TLS), restrict access to the controller, and make it redundant.
- Logging and monitoring: send router logs to a central system (SIEM); watch for configuration changes and unusual routes (e.g. with BGP monitoring services).
Extra references
- Is BGP safe yet? (test your ISP for RPKI) – https://isbgpsafeyet.com/
- MANRS – https://manrs.org/
- RIPE NCC – RPKI – https://www.ripe.net/manage-ips-and-asns/resource-management/rpki/
- CISA – guidance on securing network infrastructure devices – https://www.cisa.gov/