Sub topic 1
What a Routing Protocol Has to Do
Prerequisites
This chapter assumes basic IP addressing, subnetting, routers, routing tables, longest-prefix match, and weighted graphs.
What a Routing Protocol Has to Do
A router forwards a packet by selecting an outgoing interface and next hop. A routing protocol learns the information needed to make that decision. It discovers reachable destination prefixes, compares possible paths, and installs the best routes in the routing table.
The protocol must also react when links or routers fail. A useful protocol supplies a metric, exchanges enough information with other routers, and eventually converges, meaning that routers settle on consistent routes after a change.
Modeling a Network as a Weighted Graph
Represent the network as a graph:
- A node represents a router.
- An edge represents a working link between routers.
- An edge weight represents the link's cost.
For example, if router A connects to B with cost 2 and B connects to C with cost 3, the path A-B-C has total cost 5.
A routing algorithm uses this graph to choose a path. The forwarding table then records the next hop, rather than the complete path.
Link Costs and Path Metrics
A metric is the value used to rank paths. RIP counts router hops. OSPF commonly uses a cost derived from interface bandwidth. Other protocols can combine delay, reliability, or policy.
The lowest metric is usually preferred, but a protocol may apply tie-breaking rules. Metrics are meaningful only within the protocol's rules. A path with fewer hops is not automatically faster if its links have very different capacities.
Distance-Vector Routing: Routing by Rumor
In distance-vector routing, each router tells its neighbors the cost it currently knows for each destination. A router does not need the whole topology. It learns routes indirectly from neighbors.
This approach is simple and uses relatively small messages, but information can be stale. Neighbor reports can also create temporary loops after a failure.
The Bellman-Ford Update Equation
For destination d, router x evaluates neighbor v with:
D(x,d) = min_v { cost(x,v) + D(v,d) }
It adds the local link cost to the neighbor's advertised cost, then chooses the smallest result. The selected neighbor becomes the next hop.
Exchanging Vectors with Neighbors
Routers send vectors periodically or when their routes change. On receiving an advertisement, a router updates a route when the new cost is lower or when the current next hop is reporting a changed cost.
INFINITY = 16
def update(table, neighbor, link_cost, advertised):
for destination, neighbor_cost in advertised.items():
candidate = min(link_cost + neighbor_cost, INFINITY)
current = table.get(destination)
if current is None or candidate < current[0]:
table[destination] = (candidate, neighbor)Exercise
Router A has a link cost of 2 to B. B advertises destination D at cost 4. What route cost does A calculate?
Show answer
A calculates 6: 2 for the A-B link plus 4 advertised by B.