Sub topic 3
Flooding Link-State Advertisements
Assume you know IP addressing, routing tables, longest-prefix match, and basic weighted graphs.
Flooding the network map
A link-state router discovers neighbors with Hello packets. After forming an adjacency, it creates a link-state advertisement (LSA) describing its links, costs, and neighbors. It floods the LSA through the routing area. Each router forwards a newer LSA once, identified by its sequence number, and discards duplicates or expired entries.
Link-state database and shortest paths
Each router stores the received LSAs in a link-state database (LSDB). Routers in the same area should build equivalent databases. The LSDB is the graph; it is not yet the forwarding table.
The router runs Dijkstra’s shortest-path-first (SPF) algorithm on that graph. The algorithm repeatedly selects the lowest-cost unvisited node, then relaxes its outgoing edges. The first neighbor chosen from the source becomes the next hop.
import heapq
def spf(graph, source):
distance = {source: 0}
next_hop = {}
heap = [(0, source, None)]
while heap:
cost, node, first = heapq.heappop(heap)
if node in next_hop or node == source and cost != 0:
continue
next_hop[node] = first
for neighbor, edge_cost in graph[node].items():
new_cost = cost + edge_cost
if new_cost < distance.get(neighbor, float("inf")):
distance[neighbor] = new_cost
hop = neighbor if node == source else first
heapq.heappush(heap, (new_cost, neighbor, hop))
return distance, next_hop
graph = {"A": {"B": 2, "C": 5}, "B": {"A": 2, "C": 1},
"C": {"A": 5, "B": 1}}
print(spf(graph, "A"))OSPF and IS-IS
OSPF uses interface costs, commonly derived from bandwidth. Areas limit flooding and SPF work. Area 0 is the backbone. On broadcast networks, a designated router (DR) and backup DR reduce the number of adjacencies and LSA exchanges.
IS-IS also floods link-state information and runs SPF. It uses a two-level hierarchy, commonly called Level 1 and Level 2, and runs directly over the data-link layer rather than inside IP. OSPF integrates naturally with IP addressing; IS-IS is often favored in large provider networks.
| Protocol | Typical metric | Scaling feature |
|---|---|---|
| RIP | Hop count, maximum 15 | Small networks only |
| OSPF | Configurable interface cost | Areas and DRs |
| IS-IS | Configurable interface metric | Level 1/Level 2 hierarchy |
Related designs
EIGRP uses DUAL, which keeps feasible successor routes and can avoid recomputing the whole network after every failure. It is an advanced distance-vector design.
BGP is a path-vector protocol. It exchanges reachable prefixes plus attributes and AS paths between autonomous systems. It applies policy, rather than simply choosing the lowest internal link cost.
Exercise
Why can two routers in one OSPF area calculate different paths?
Show answer
Their LSDBs may differ because an LSA is missing, stale, or not yet flooded, or their interface costs are configured differently.