Sub topic 5
Route Aggregation and Longest-Prefix Match
Assume you know binary and decimal conversion, IPv4 prefixes, subnet masks, and the difference between a host and a router. This chapter uses those ideas to reduce routing-table size and select forwarding routes.
Route aggregation and supernetting
Route aggregation combines several smaller, contiguous network prefixes into one larger prefix. The larger prefix is called a supernet. Aggregation reduces the number of entries that routers must store and advertise.
For example, these two networks can be combined:
192.168.0.0/24192.168.1.0/24
Each /24 contains 256 addresses. Together, they contain 512 addresses, which is the size of a /23 block:
- Aggregate:
192.168.0.0/23
The prefix length decreases because the aggregate has one fewer network bit. In general, combining \(2^k\) equally sized aligned networks reduces the prefix length by \(k\).
Aggregation is valid only when the component networks are:
- Contiguous in address order.
- Equal in size.
- Properly aligned to the proposed aggregate boundary.
- Under the same administrative control or reachable through the same next hop.
For instance, 192.168.0.0/24 and 192.168.2.0/24 cannot be represented exactly by one /23. A /23 starting at 192.168.0.0 would also include 192.168.1.0/24.
| Component networks | Aggregate | Address count |
|---|---|---|
| `192.168.0.0/24`, `192.168.1.0/24` | `192.168.0.0/23` | 512 |
import ipaddress
networks = [
ipaddress.ip_network("192.168.0.0/24"),
ipaddress.ip_network("192.168.1.0/24"),
]
print(list(ipaddress.collapse_addresses(networks)))The output is [IPv4Network('192.168.0.0/23')].
Longest-prefix match in a forwarding table
A router may have several entries that contain the destination address. It chooses the matching entry with the longest prefix, meaning the largest prefix length. This rule is called longest-prefix match.
Consider these entries:
| Prefix | Next hop |
|---|---|
| `10.0.0.0/8` | A |
| `10.1.0.0/16` | B |
| `0.0.0.0/0` | C |
The /0 entry is the default route and matches every IPv4 address. The address 10.1.2.3 matches all three entries, but /16 is more specific than /8 and /0, so the router chooses next hop B. The address 10.2.0.1 chooses A, while 8.8.8.8 uses C.
A common exam error is choosing the first matching row instead of comparing prefix lengths.
Exercise
A table contains 172.16.0.0/12 → X, 172.20.0.0/16 → Y, and 0.0.0.0/0 → Z. Which next hop handles 172.20.5.1?
Show answer
Y, because the address matches all three entries and /16 is the longest matching prefix.