UCB CS168 Notes Chapter 2 Routing

Last updated on April 10, 2026 am

This article is currently an experimental machine translation and may contain errors. If anything is unclear, please refer to original Chinese version. I am continuously working to improve the translation.

Introduction to Routing

What is Routing?

Suppose A and B are both connected to the Internet, but A and B are not directly connected. Now A wants to send a message to B — where should A send the message so that it reaches B? What path does the message take along the way? This is the core problem this chapter needs to solve.

Specifically, this chapter covers:

  • Building a model of the Internet, clearly defining the Routing Problem, and identifying the factors that influence it
  • Exploring several different routing protocols, and discussing how to scale them to the entire Internet
  • A brief look at the actual hardware devices used to implement these routing protocols

Inter-Domain and Intra-Domain Routing

Based on our previous experience designing other systems (unrelated to computer networks), we could have a central system that manages all routers worldwide, responsible for packet delivery across the globe. However, given the vastness and complexity of the Internet, this is clearly unrealistic.

So instead, we will leverage the property that Internet is Network of Networks:

  • Each Local Network has its own routing protocol, specifically handling packet forwarding within that network
  • Between Intra-Domains, establish routing protocols that span networks

Since Local Networks differ greatly from one another, it is perfectly normal to choose different routing protocols. The protocol used to route packets within a Local Network is called an intra-domain routing protocol, or interior gateway protocol (IGP); real-world examples include OSPF and IS-IS.

Similarly, the protocol used to communicate between different networks is called an inter-domain routing protocol, or exterior gateway protocol (EGP). Obviously, to build the Internet, there can only be one universal EGP, and that is BGP (Border Gateway Protocol).

The concepts of IGP and BGP seem clearly separated, but in practice this is not always the case — for example, BGP is occasionally used within inter-domain networks.

Model for Intra-Domain Routing

Modeling the Network as a Graph

Exactly what the title says. One thing to note: a link can only connect two machines.

Routers and Hosts

In our simplified model, machines are classified into the following two categories:

  • End Hosts: machines connected to the Internet that send and receive data, and are not responsible for forwarding intermediate packets
  • Routers: responsible for forwarding intermediate packets; routers do not send packets, nor do they serve as the final destination of packets

Routers are sometimes also called switches. Routers and switches historically differed, but today the two terms are used interchangeably. In these notes, we will use the term "router" wherever possible.

The above passage is questionable — the school's course may not take this view; to be verified, TODO

End Hosts in Routing

End hosts usually do not participate in routing protocols, because they do not forward intermediate packets.

End hosts are often connected to a single router via a single link, and send all outbound information to that router, which decides how to forward packets to their final destination. This strategy is called the default route of the end host.

When designing Routing Protocols, end hosts are often ignored.

Packets

In this chapter we make some simplifications to the abstraction of packets:

  • Each packet contains:
    • A Header with metadata
    • A payload at the Application Layer Level
  • We ignore nested headers and multiple layers

We focus on the destination address field and source address field in the Header's metadata.

Addressing

We need a protocol to assign an address to every machine on the network.

This will be discussed in detail later (of course, we know it is the IP protocol).

Define the Routing Problem: When a router receives a packet, how does it know where to forward the packet so that it eventually reaches its destination?

Network Topologies Change

New devices may join or leave the Internet at any time, and links may fail at any moment.

Therefore, the routing protocols we design need to be robust to these changing network topologies.

Routing Protocols are Distributed

I think this point is very important. The network topology changes at any time, but because the Internet is distributed, a single router has no ability to know the topology of the entire network, so the routing protocols we design must also be distributed, so that new network topology information can be propagated to each router through the routing protocol.

Each router must compute its own portion of the answer, and together these form the global solution to the routing problem.

In addition, the distributed nature of routers also means: if a router fails, the protocol must also coordinate the other routers, as well as handle the recovery of that router.

This property needs to be considered in the design — mainly the possibility of packet loss.

Routing States

Routing State: the set of rules each router uses to forward received packets. These rules may be correct or incorrect, and we need to check them.

Bad Routing Strategies

For example, let's casually name two bad rules: forwarding randomly, and forwarding to all neighbors.

Forwarding Tables

Inside a router, a table is stored; for each possible destination, it records where the corresponding next hop should be. This is called the forwarding table.

By recording the forwarding table, we have a complete Routing State, because as long as we know the destination, we know how to get there.

The next intermediate router to which a packet will be forwarded is called the next hop.

In the real world, routers usually map destinations to physical ports, rather than to next hops.

This is a subtle distinction that reflects the fact that routers actually do not care about the identity of neighboring routers. The only decision a router needs to make is to send the packet out along a certain line, regardless of who that line connects to. For simplicity, in these notes we will draw forwarding tables that map destinations to next hops (rather than physical ports).

It is easy to see that using a forwarding table is a form of Destination-Based Forwarding.

Routing vs. Forwarding

Routing:

  • The process by which routers communicate with each other to determine how to fill in their respective forwarding tables.
  • It is a global process; filling in the forwarding table requires knowledge of the network's global topology.

Forwarding:

  • The process by which a router receives a packet, looks up the appropriate next hop in the forwarding table, and sends the packet out.
  • It is a local process; it can be completed with only knowledge of the forwarding table.

Routing State Validity

Evaluating the validity of a routing state:

  • A routing state consists of the forwarding tables of every router, which together tell us how packets will travel through the network
  • Validity must be evaluated in a global context, not in a local context

Definition:

The global routing state is valid if and only if, for any destination, packets never get stuck in a dead end or a loop.

  • A dead end means a packet arrives at a router, but the router does not know where to forward it
  • A loop is fairly easy to understand: forwarding tables point to each other, but note here that an end host must not be part of a loop

This condition is a necessary and sufficient condition.

  • Proof of necessity:
    • If a dead end exists, a packet gets stuck when it reaches the dead end and cannot get out
    • If a loop exists, a packet gets trapped in the loop and cannot get out
    • So, a valid routing state contains no dead ends and no loops
    • Necessity is fairly obvious
  • Proof of sufficiency:
    • If no loop exists, a packet cannot arrive at the same router twice
    • If no dead end exists, a packet will not stop before reaching its destination
    • Since the total number of routers is finite, the packet will eventually reach the destination

Directed Delivery Trees

This subsection is mainly about how to judge, from a graph perspective, whether a global routing state is valid.

To simplify the problem, let us first consider only a single destination end host, ignoring all other end hosts. That is, the graph has exactly one node with out-degree 0.

Then, for this graph, it suffices to satisfy the following requirements:

  • Exactly one node with out-degree 0
  • All other nodes have out-degree 1
  • Connected — a spanning tree rooted at the end host

Least-Cost Routing

Simply put, the graph has positive edge weights, and we want packets to reach the destination along the lowest-cost path.

How are costs (edge weights) assigned? Generally, they are assigned by network operators.

Note that costs are local to the router; that is, a router knows the cost of its own outgoing links, but a router does not automatically know the costs of other links in the entire network. This matches our claim that "routers do not have a global view of the entire network topology."

Here we assume edge weights are always positive integers, and the cost from A to B is always the same as from B to A.

Static Routing

This can be understood as manual hard-coding: obtain all forwarding tables and build Routing based on them.

Although we certainly cannot do this on every router, it is frequently used in practice — you can think of it as manually writing forwarding tables.

Distance-Vector Protocol

I think this is the most important section of this chapter.

Algorithm Sketch

The typical distance-vector protocol is RIP (Routing Information Protocol), and the D-V Protocol we are designing has many similarities with RIP.

To summarize, there are two core points:

For each destination:

  • If a route to that destination is learned, update the forwarding table
  • Tell all neighbors (Announcement / Advertisement)

Direction of Announcements and Messages

This is really just a reminder of an easy-to-miss point:

The direction in which packets are sent and the direction of Announcements are opposite.

Rule 1: Bellman-Ford

  • The original text here is very verbose; here I distill the essence directly

Initially, the forwarding table entry from A to R1 is generally a static route, i.e., hard-coded.

Both R3 and R4 can reach A, but going through R4 costs less, so R5 will choose the path through R4 and write it into its forwarding table.

Here we update our earlier statement: add a column to the forwarding table that also records the known minimum cost to reach the destination (= the advertised cost plus the link cost to the neighbor).

Note: Formally, the forwarding table stores key-value pairs, mapping each destination to a tuple containing the next hop and the distance. For simplicity, we will draw it as a three-column table.

This operation is the "relaxation" operation in Dijkstra's algorithm; Bellman-Ford is even simpler than Dijkstra — it just relaxes all edges once.

However, due to the constraints of routing protocols, what we are designing is a distributed, asynchronous protocol.

  • The protocol is distributed because we do not require a single machine to run the entire algorithm; instead, each router computes its own portion of the answer (filling in its own forwarding table) without being able to see the complete network graph
  • The protocol is asynchronous because all routers can run the algorithm simultaneously, with no need to control the order of operations

Summary: for each destination:

  • If an Advertisement for a path to that destination is received, update the table if:
    • The destination is not in the table
    • The cost in the Advertisement plus the Link cost to the neighbor is better than the known best cost
  • Then, Advertise to all neighbors

Rule 2: Updates From Next-Hop

Under the rules we described earlier, whenever an Advertisement is received for some destination with a cost lower than what is currently recorded in the forwarding table, the table is updated; if the cost is higher, it is ignored.

But this rule has a problem: suppose the best path recorded in our forwarding table changes — the cost of the route through the original router increases. We are forced to accept this information.

In short, add one more rule to the previous ones:

Summary: for each destination:

  • If an Advertisement for a path to that destination is received, update the table if:
    • The destination is not in the table
    • The cost in the Advertisement plus the Link cost to the neighbor is better than the known best cost
    • The Advertisement comes from the current next-hop
  • Then, Advertise to all neighbors

Rule 3: Resending

Simply add one rule: there exists an Advertisement Interval; every time this interval elapses, the router must resend its Advertisement, broadcasting its current information.

This is to prevent the problem where an Advertisement is lost in transit, causing the forwarding table to never be built.

Summary: for each destination:

  • If an Advertisement for a path to that destination is received, update the table if:
    • The destination is not in the table
    • The cost in the Advertisement plus the Link cost to the neighbor is better than the known best cost
    • The Advertisement comes from the current next-hop
  • When the routing table is updated, Advertise to all neighbors, and do so periodically.

Note: Resending can be combined with the previous rules, i.e.:

  • Whenever the forwarding table changes, the router immediately advertises — this is called triggered updates
  • Advertising at the interval still happens, unaffected by triggered updates

Based on the current rules, after the protocol converges, routers will still periodically send Advertisements, but none will be accepted, because the network is in a stable state at that point and every node already has the lowest-cost path.

Rule 4: Expiring

Routers may fail, and a failed router cannot broadcast the fact that it has a problem, so our forwarding table can only keep forwarding toward the broken place, causing packet loss.

To solve this problem, set a time to live (TTL) for every entry (row) in the forwarding table. This is a countdown telling us how much longer this entry may be kept.

If we receive an Advertisement from the next-hop, we can reset the TTL to the default; otherwise, delete the entry.

Summary: for each destination:

  • If an Advertisement for a path to that destination is received, update the table if:
    • The destination is not in the table
    • The cost in the Advertisement plus the Link cost to the neighbor is better than the known best cost
    • The Advertisement comes from the current next-hop
  • When the routing table is updated, Advertise to all neighbors, and do so periodically.
  • If a routing table entry expires, delete it.

Rule 5: Poisoning Expired Routes

If the TTL is relatively long and the router has died, waiting for the TTL to expire takes a long time, which somewhat wastes time for the system; moreover, forwarding to an already-failed router during the wait also causes packet loss.

Solution: poison — when:

  • A node fails

  • A TTL expires

explicitly announce that the path is no longer valid.

A Poison Announcement reads like this: I am router xx, and router yy is infinitely far from me. It propagates in exactly the same way as a normal Advertisement.

One must be careful to avoid forwarding packets along poisoned paths. If a routing table entry says A is reachable via R1 at a cost of infinity, this actually means A cannot be reached via R1. When we receive a packet destined for A, we must never forward it to R1.

Applying Rule 2, a previously valid path through the recorded next-hop can be quickly updated once it becomes invalid.

Summary: for each destination:

  • If an Advertisement for a path to that destination is received, update the table if:
    • The destination is not in the table
    • The cost in the Advertisement plus the Link cost to the neighbor is better than the known best cost
    • The Advertisement comes from the current next-hop, including poison announcements
  • When the routing table is updated, Advertise to all neighbors, and do so periodically.
  • If a routing table entry expires, set it to poison and announce it.

Rule 6A: Split Horizon

For this problem we temporarily ignore poison, because even with it there is no real difference — the problem still occurs.

Showing another problem:

R2's original table:

To: Via: Cost:
A R1 2

Because the TTL expired, it was deleted (actually, even with poison there would be no difference here). Then, due to Resending, R3 sends an announcement to R2:

As a result, a loop appears, which is bad.

To solve this problem, we propose Split Horizon: never send routing information back to the person who provided that route.

"Sending back" here means: do not send back along the Via attribute in the Forwarding Table.

Summary: for each destination:

  • If an Advertisement for a path to that destination is received, update the table if:
    • The destination is not in the table
    • The cost in the Advertisement plus the Link cost to the neighbor is better than the known best cost
    • The Advertisement comes from the current next-hop, including poison announcements
  • When the routing table is updated, Advertise to all neighbors, and do so periodically.
    • But do not send the advertisement back to the next-hop
  • If a routing table entry expires, set it to poison and announce it.

Rule 6B: Poison Reverse

This is another way to avoid creating loops. Note that it cannot be used together with Split Horizon.

Under the Poison Reverse rule, Poison Announcements are explicitly sent back.

Returning to the previous scenario:

  • With Split Horizon, R3 sends nothing
  • With Poison Reverse, it looks like this:

This likewise prevents the formation of loops.

Summary: for each destination:

  • If an Advertisement for a path to that destination is received, update the table if:
    • The destination is not in the table
    • The cost in the Advertisement plus the Link cost to the neighbor is better than the known best cost
    • The Advertisement comes from the current next-hop, including poison announcements
  • When the routing table is updated, Advertise to all neighbors, and do so periodically.
    • But do not send the advertisement back to the next-hop
    • Or, send a poison advertisement back to the next-hop
  • If a routing table entry expires, set it to poison and announce it.

Be sure to note that Split Horizon and Poison Reverse are mutually exclusive — you must choose one.

Rule 7: Count to Infinity

Split Horizon and Poison Reverse can only avoid loops of length 2, but our current Routing Protocol can still involve routing loops of length $\geq 3$.

The demonstration of this graph example is rather complicated; here is a brief explanation:

  • Originally there is a steady state of R1-R2-R3-A
  • The A-R3 link breaks; according to Rule 5, R3 modifies its forwarding table and sends poison announcements to R1 and R2
  • As it happens, this announcement gets dropped on its way to R1
  • Although R3 could send messages again later (Rule 3), here we assume all possible problems occur before that
  • So R1 keeps sending fake normal announcements, causing R2's poisoned entry to be overwritten by announcements with a smaller cost that are actually invalid (why not send to R3? Because of split horizon)
  • Then R2 receives the message and continues sending to R3
  • ...and so it enters a loop, with the cost continuously increasing — the increase being the cost each router needs to send outbound

Why doesn't split horizon work here? Because R1 is only restricted from sending to R3, but nothing says it cannot send to R2.

The solution to this problem is actually quite blunt: set a maximum cost value; anything above it is treated as infinity (a poisoned entry). For example, in the RIP protocol, this value is 16.

So, in the scenario above, the loop exists for a while and then everything gets poisoned.

Summary: for each destination:

  • If an Advertisement for a path to that destination is received, update the table if:
    • The destination is not in the table
    • The cost in the Advertisement plus the Link cost to the neighbor is better than the known best cost
    • The Advertisement comes from the current next-hop, including poison announcements
  • When the routing table is updated, Advertise to all neighbors, and do so periodically.
    • But do not send the advertisement back to the next-hop
    • Or, send a poison advertisement back to the next-hop
    • Any cost ≥ the given value is treated as infinity
  • If a routing table entry expires, set it to poison and announce it.

Eventful Updates

The title means "event-driven updates."

This is really just a summary.

Situations in which a router sends announcements:

  1. When the forwarding table changes (triggered update), such as:
    • When a new announcement is accepted
    • When a new link is added (e.g. a static route)
    • When a link goes down
  2. Periodic sending
  3. Sending after expiration (replaced by poison)

Among these, the triggered update is actually an optimization; without it, the Routing Protocol would still work.

Link-State Protocols

Another kind of interior gateway protocol.

IS-IS and OSPF are two examples of Link-State Protocols.

Unlike the Distance-Vector Protocol, the Link-State Protocol performs local computation:

  • Each node is independent
  • Each computes the complete solution itself, without using computation results from neighbors

In one sentence: each router learns the complete network topology graph, then runs a shortest-path algorithm on that graph to fill in its forwarding table.

We design this protocol in two steps:

  1. How to compute shortest paths
  2. How to learn the entire network graph

Computing Paths

There are many shortest-path algorithms; Dijkstra, Bellman-Ford, or anything else will do.

The main problem is: each router can only control its own current forwarding and cannot influence the behavior of the next-hop. If the next-hop computes a different path, a loop may result.

To avoid this problem, we need to ensure that the forwarding decisions made by all routers are compatible with each other. The following conditions must be met:

  • All routers know the same network topology graph
  • All routers are looking for the shortest path
  • All edge weights are positive (to prevent negative-weight cycles)
  • All routers use the same tie-breaking rule; that is, if there are multiple shortest paths of equal cost, all routers choose the same one

Learning About Graph Topology

First, send "hello" messages to all neighbors:

Hello messages need to be resent periodically (similar to DVP); if a neighbor hasn't sent one for a while, it is considered gone.

We also need to broadcast who our neighbors are. And taking this figure as an example, after R2 broadcasts that its neighbors are R1 and R3, R1 and R3 must also broadcast who R2's neighbors are; other routers do the same.

This is called flooding information across the network; here we also need to resend messages periodically.

Avoiding Infinite Flooding

In this structure, the two routers will send messages to each other infinitely, continuously wasting bandwidth.

Note that this is different from periodically resending messages for reliability. To ensure reliability, we might resend a message every 5 seconds. But in this infinite loop, the routers are receiving and resending duplicate announcements at the maximum rate (e.g., millions of times per second).

If a loop exists, the growth in the number of broadcasts can even be exponential, with more serious consequences.

To solve this problem:

  • When a message is seen for the first time:
    • Send it to all neighbors
    • And record that we have already seen this message
  • If the same message is seen again, do not send it again

To uniquely identify a message, we can introduce timestamps (or other counters unique to each message).

Convergence

Once the network topology changes, the network may take some time to converge again.

We must first wait for the change to be detected, then wait for the new information to propagate through the network, and then wait for the routers to compute their forwarding tables.

During this waiting period, the network is in an invalid routing state, because there is no complete network topology graph.

Depending on the implementation, distance-vector protocols may converge more slowly. If the network changes, we must wait for our neighbors to recompute and re-advertise paths before we can update our own forwarding table. Then all of our neighbors must in turn wait for us, and so on. In contrast, in a link-state protocol, all nodes can quickly flood the new information and recompute simultaneously.

Link-state protocols are suitable for small local networks, but difficult to scale to the global Internet.

In practice, most networks use a combination of distance-vector protocols and link-state protocols.

Addressing

Scaling Routing

So far we have been using labels like A, B, C, D to number destinations. However, if we want to scale routing protocols to the entire Internet, this is clearly unrealistic, because:

  • If we run a Distance-Vector Protocol, we would need to announce every host in the world
  • If we run a Link-State Protocol, every router would need to know the topology of the entire Internet

So, we will scale routing by using a more suitable addressing scheme.

IP Addressing

The Internet uses a different addressing scheme at each layer; at Layer 3 (the Network Layer), IP Addressing is used.

No further explanation here.

Hierarchical Addressing

Earlier we said Internet = Network of Networks.

This figure is very intuitive. A brief summary of the idea and its benefits:

  • Number several local networks, using it as the first number: the network identifier

  • Number the routers within a local network, written as the second number: the host identifier

  • For R9 in Network 2, suppose it wants to reach any host in Network 1; the forwarding table only needs to contain 1*, and similarly for others

  • This allows us to:

    • Simplify the forwarding table

    • If the network topology in another local network changes — for example, we originally wanted to reach 1.2, but 1.2 left — R9's forwarding table is unaffected

      In fact, changes within a local network (e.g., a new host joining the network) happen much more frequently than changes between networks (e.g., a new underground cable being laid), so it is a good thing that local changes only affect local forwarding tables.

  • For any router within, say, a Local Network, the forwarding table needs to spell out the next-hop in detail for routers within the local network, but for anything outside the local network, a wildcard like x.* suffices

Default Routes

In the previous subsection we learned that, combined with the wildcard *, an entry can represent a range; this idea can be extended further.

Taking this figure as an example, we find that for R2 to go outward, apart from the directly connected 2.4 and 2.5, everything else must go through R3, so we can just write it as *.*.

As for R4, the forwarding table might look like this:

Most hosts have only a single hard-coded default route. For example, host 2.4's forwarding table has only one entry, instructing it to send everything to R2. In fact, your home computer has only one entry, instructing it to send everything to your home router. This is why hosts do not need to participate in routing protocols.

Assigning Hierarchical IP Addresses: Classful Addressing

This subsection mainly introduces an addressing scheme that has already been phased out:

  • The leading field indicates how to segment
  • The Network field addresses local networks
  • The Hosts field addresses hosts within a domain

Assigning Hierarchical IP Addresses: CIDR

CIDR (Classless Inter-Domain Routing) is the scheme still used by the modern Internet, allowing the number of bits to be set arbitrarily.

Multi-Layered Hierarchical Assignment

The main point of this subsection is that there can be many levels of hierarchy (not just the two layers of Networks-Hosts).

Taking IPv4 as an example, it is managed by the organization ICANN, which allocates address blocks to Regional Internet Registries (RIRs) representing specific countries or regions.

For example, ICANN allocates all addresses starting with 1101 to ARIN (North America), and then ARIN allocates the remaining portion to various organizations / ISPs — for example, all addresses starting with 1101 11001 are allocated to AT&T, and AT&T continues to allocate downward.

How many bits to allocate here is arbitrary.

Writing IP Addresses

Dotted-quad notation: every 8 bits are written as an integer between 0 and 255, joined by ..

There are two ways to represent a range: slash notation and the netmask.

slash notation

First write out the fixed prefix, then pad all remaining unfixed bits with 0, and convert the resulting 32-bit value into a dotted-quad IP address. Then, after the slash, we write the number of fixed bits.

For example, if the prefix is 11000000, padding with zeros gives 11000000 00000000 00000000 00000000, which in dotted-quad form is 192.0.0.0; since the first 8 bits are fixed, it is written as 192.0.0.0/8.

Slash notation can sometimes look a bit confusing, because we use arbitrary 8-bit divisions and write the numbers in decimal. For example, an 8-bit prefix 11000000 and a 12-bit prefix 11000000 0000 would be written as 192.0.0.0/8 and 192.0.0.0/12 (the same IP address representing different ranges). As another example, if I own the 4-bit prefix 1100, I can allocate the 5-bit prefix 11001. As ranges, these are written as 192.0.0.0/4 and 200.0.0.0/5. At first glance, it is not clear that the second range is actually a subset of the first; we must write out the bits to confirm.

netmask

The netmask is an alternative to the part after the slash in slash notation.

To write a netmask, we write 1 for all fixed bits and 0 for all non-fixed bits, and convert the result to dotted-quad form.

For example, still using the earlier 192.0.0.0/8 as an example: since the first 8 bits are fixed, the netmask is 11111111 00000000 00000000 00000000, i.e., 255.0.0.0.

Netmasks are commonly used inside computers, because bitwise-ANDing an IP address with the netmask zeroes out all host bits, leaving only the network bits.

Aggregating Routes with CIDR

Just like the aggregation discussed in the Hierarchical Addressing and Default Route sections, this section explains how to aggregate using CIDR.

Actually, the principle is very simple:

The figure speaks for itself.

Multi-Homing

For Stanford, there are two Homings (two upper-level Hosts).

Then the aggregation we did earlier for AT&T no longer works, because traffic might also go through R7.

At this point we introduce longest prefix matching: when querying the forwarding table, always look for the most specific one first (the one with the longer prefix).

Router Hardware

What Do Routers Do?

  • Fill in the forwarding table by running routing protocols
  • When a packet arrives, look at the destination IP address and choose the appropriate link to forward the packet

Data, Control, Management Planes

A router's software + hardware components can be conceptually divided into three planes:

  • Data plane
    • Mainly responsible for forwarding packets
    • Runs locally, without coordinating with other routers
  • Control plane
    • Mainly responsible for communicating with other routers and running routing protocols
  • Management plane
    • Used to tell routers what to do, and to see what they are doing
    • The system interacts with humans through the management plane to configure and monitor routers: How much cost should be assigned to each link? Which routing protocol should be run? How much traffic is carried on each link? Has any physical component of the router failed?

The data plane runs very fast (at hardware speed), while — since packets arrive far more frequently than the network topology changes — the control plane handles more complex tasks and runs relatively slowly; the management plane runs the slowest.

The data plane and control plane run in real time, receiving and processing packets with latencies on the order of nanoseconds (data) and seconds (control), respectively. In contrast, management-plane operations typically take tens to hundreds of seconds.

What's Inside a Router?

Chassis: the case; Linecard: line card

All physical ports are connected to each other; each port can both receive and forward packets.

Of course, forming a complete graph is too inefficient, so we use a fabric of wires to connect the linecards together; each linecard is equipped with a CPU to facilitate the connections.

In addition to all the linecards, there is a separate controller card with its own CPU, used to communicate with other routers and execute routing protocols, run algorithms to compute paths, and write forwarding tables.

Take a careful look at these three figures:

Types of Packets

  • user packet: the forwarding chip first reads the destination field in the header, then reads the forwarding table and selects the appropriate port; if the destination port is on a different linecard, the packet is sent along the fabric (switching fabric) to the corresponding linecard and then sent out

  • control-plane traffic: destined for the router itself, such as the announcements sent when running routing protocols; when the router receives such a packet, the forwarding chip uploads it to the controller card, and the controller card's CPU then processes the information

  • punt traffic: the translation is "punted traffic"; it is essentially a user packet, but requires special handling:

    For example, if we receive a packet with a TTL of 1, the packet has expired and we should not forward it. We may also need to send an error message to the sender. When a router receives a punted packet, the forwarding chip "punts" the packet to the controller card for special handling

Scaling Routers

Why are routers split into this particular architecture?

Essentially, it is because routers have different requirements for different tasks: the speed of forwarding is extremely demanding, while other tasks may not be as demanding.

For example, for forwarding packets, there are dedicated optimizations in the data plane.

This is what is meant by "due to the scale," because a single router forwards an enormous volume of packets.

Linecard Functionality

  1. Receiving packets
    • PHY part: parses the analog signal into bits
    • MAC part: performs link-layer tasks
    • All of these are implemented in hardware
  2. Processing packets
    • Understanding the header
    • Finding the next-hop
    • Updating the packet: decrementing the TTL, updating the checksum, etc.
  3. Forwarding the packet along the fabric

To speed up the above operations, the forwarding chip is highly specialized and can basically only perform these limited tasks. If a function not supported by the forwarding chip is needed, the packet is forwarded to the CPU on the controller card.

Packet Queuing

  • only one queue for a router
  • drop the packet if the queue is full
  • FIFO

Efficient Forwarding Table Lookup

Recall from earlier that reading the forwarding table requires "longest prefix matching".

A Trie is used to achieve relatively efficient lookups

Model for Inter-Domain Routing

Defining Autonomous Systems (AS)

We define the AS to formalize the concept of a Local Network: an AS is one or more local networks managed by the same operator.

Types of ASes

  • stub AS: only provides internet connectivity for hosts in its local network, only sends and receives packets on behalf of the hosts inside it, and does not forward packets between different ASes
  • transit AS: can forward and receive packets, such as various ISPs

Inter-Domain Topology Is Defined by Business Relationships

The relationships between ASes:

  • customer, consumes traffic
  • provider, provides traffic
  • peer, sends traffic to each other, roughly equal amounts, without paying each other

AS Graph with Business Relationships

Directed edges point from providers to customers, and undirected edges connect two peers.

Note that the direction of the arrows does not indicate the direction of packet transmission. In fact, even along a directed edge, packets can travel in both directions. Customers typically pay providers for the ability to send packets to the rest of the internet and to receive packets from the rest of the internet.

AS Graphs are Acyclic

The AS graph has no directed cycles. This is because a cycle would cause money to flow back to itself, which is unreasonable in reality.

Provider Hierarchy and Tier 1 ASes

We can arrange the AS graph so that all arrows point downward, and the AS graph naturally becomes layered.

At the top layer are Tier 1 ASes. Real-world entities corresponding to this include China Telecom.

Gao-Rexford Rules for Routing Policies

In practice, most autonomous systems set their policies according to some standard conventions, and these conventions are known as the Gao-Rexford rules. These conventions are based on an assumption: organizations in the real world like to make money and dislike losing money.

Specifically, two rules:

  1. When multiple paths are available, the priority is: customer > peer > provider
  2. An AS has no obligation to provide service, so instead of announcing routes to all neighbors and allowing anyone to forward packets through the AS, it only announces routes for which it can be paid for forwarding

Border Gateway Protocol

The only inter-domain routing protocol in use.

BGM based on Distance-Vector Protocol

As the title says, but with some differences.

The Announcement in a DVP is split into export and import in BGP.

Why? In BGP, we need to respect the privacy of each AS. If we used a link-state protocol, then every autonomous system would have to disclose its policies to the entire network so that everyone would have complete knowledge to compute routes on their own.

This is where Policy-Based Import and Export comes in.

Each AS only exports (announces) the routes it prefers according to its policy. Meanwhile, when importing (selecting) routes, an autonomous system chooses the best route based on policy rather than distance.

We use the Gao-Rexford Rule.

A brief summary:

  • An AS prefers to import routes announced by customers, then routes announced by peers, and finally routes announced by providers
  • An AS only agrees to participate in a route if at least one neighbor is a customer — an AS should only announce a route externally after accepting it, ensuring that one side of the route has a customer neighbor

Here is an example:

Replacing D with a Customer or a Peer yields different results; just think about making money.

Route Advertised by Export Route to
Customer Everyone
Peer Customer
Provider Customer

Some Modifications

BGP allows an AS to aggregate multiple destinations into a single forwarding table entry

In BGP, each AS chooses paths based on its own preferences, so loops may occur.

To avoid this problem, BGP announcements no longer contain the distance to the destination, but instead contain the complete AS path to the destination. This turns the protocol from a Distance-Vector Protocol into a Path-Vector Protocol.

Then, an AS can determine whether a loop exists based on the content of the announcement.

BGP Implementation and Issues

iBGP and eBGP

i: internal, e: external

A brief summary of the core concepts:

eBGP sessions occur between two routers from different ASes

iBGP sessions occur between two routers within the same AS

A, B, and G in the figure are called BGP speakers

These speakers communicate with the outside and then pass the external information to the inside of the AS; this is done via another protocol, which is part of the inter-domain protocol.

In this way, each router has two tables: one internal table and one table for external ASes.

Hot Potato Routing

There are two paths here; where should a packet sent from X toward Verizon go?

By computing via the IGP whether F or I is closer, the packet exits through the nearest exit, in order to make use of others' bandwidth as much as possible and save money.

MED

If two exits are equidistant, we need a tie-breaking rule.

The exit AS can declare a preference for one route over another, and this preference is measured by MED, where lower is better.

Therefore, J is chosen as the exit here.

Import Policy Priority

When multiple announcements for the same destination are received, paths are selected according to the following tie-breaking rules, in order:

  1. Gao-Rexford rules, customer>peer>provider
  2. shorter path (at the AS level, i.e., passing through fewer ASes)
  3. choose the one closer to the exit router (hot-potato)
  4. choose the one with a lower MED value
  5. choose arbitrarily

Paths in the internet are often asymmetric. If two hosts send packets back and forth, the path in one direction may differ from the path in the other direction.

BGP Attributes

Only 3 are covered here:

The LOCAL PREFERENCE attribute encodes the Gao-Rexford import rules within a particular autonomous system (AS). An AS can assign a high value to more preferred routes (e.g., routes from customers) and a lower value to less preferred routes (e.g., routes from providers). This attribute has locality and is only propagated via iBGP messages. This attribute is not sent to other autonomous systems in eBGP announcements, because other autonomous systems do not need to know this AS's preference settings.

LOCAL PREFERENCE can be used to distinguish whether it is a provider, a customer, or a peer.

ASPATH is what was mentioned before — the entire path, and this is global.

There is also the MED attribute, which was mentioned earlier, so it won't be explained again.

IP Header

Brief Overview

This part feels rather confusing to read; more can be added later, TODO. Here we only give a brief overview.

First, in order for all devices to parse packets, the header includes:

  • IP Version (ipv4 ipv6), 4 bits
  • header length, because the header length is not fixed, 4 bits
  • packet length, 16 bits
  • destination IP address, 32 bits, for forwarding packets
  • protocol value, indicating whether TCP or UDP is used, 8 bits; 6 represents TCP and 17 represents UDP, the TCP/UDP Header follows the IP Header
  • source IP address, for sending replies, 32 bits

To handle special cases, the following fields are also included:

  • TTL, to prevent infinite loops, 8 bits
  • checksum, 16 bits
    • the checksum only covers the fixed part; it does not check non-fixed parts such as Options and PAD

These two fields only apply to the IP Header and cannot detect anomalies in the Payload.

Routers can perform fragmentation; the identification (16-bit), flags (3-bit), and offset (13-bit) fields in the header are used to implement fragmentation.

There are some other fields as well, but they are no longer used in modern times.

Changes in IPv6

  1. The checksum is removed

    The rationale for including a checksum is: if a packet is corrupted and the corruption goes undetected, the corrupted packet continues to be sent, wasting bandwidth. Including a checksum ensures the packet is dropped, so bandwidth is not wasted on corrupted packets. In modern times, bandwidth is no longer the bottleneck, so the checksum is no longer necessary; even if some corrupted packets travel through the network, they will not have a huge impact on performance.

  2. The fragmentation mechanism is removed; if an IPv6 packet is too large for a particular link, the router will drop the packet; the responsibility for fragmentation is given to end hosts rather than routers.

  3. In IPv6, the header length is fixed, so there is no header length field.

There are some other changes as well; more will be added later, TODO.


UCB CS168 Notes Chapter 2 Routing
https://blog.wendain.ing/en/posts/cs168-note-2/
Author
wendaining
Posted on
April 5, 2026
Updated on
April 10, 2026
Licensed under