Sub topic 20
Where Path-Vector Routing (BGP) Fits
This chapter assumes you have read the earlier chapters on distance-vector and link-state routing. It also assumes you know what an autonomous system is: a set of networks run by one organization under one routing policy. You should be comfortable with IP prefixes and with split horizon and count to infinity.
Why neither family works between organizations
RIP, OSPF, and IS-IS are interior gateway protocols (IGPs). They assume every router belongs to one administrator who wants the shortest or cheapest path. Two things break when you stretch them across the Internet.
- Scale. Link-state flooding gives every router the full topology. That is impractical for the roughly one million prefixes and tens of thousands of networks on the Internet.
- Policy. Between organizations, "shortest" is not the goal. A company may refuse to carry a competitor's traffic, prefer a cheaper provider, or hide its internal layout. A single numeric metric cannot express "use this route only for customers." Link-state also forces every participant to reveal its topology, which no one wants.
The Internet needs an exterior gateway protocol that scales, hides internal detail, and lets each network choose routes by its own rules. That protocol is the Border Gateway Protocol (BGP).
The path-vector idea
A path vector is a distance vector with the metric replaced by the full list of networks the route passes through. Instead of "prefix 192.0.2.0/24 is 3 hops away," a neighbor says "prefix 192.0.2.0/24 is reachable via AS 65003, then AS 65002, then AS 65001." This list is the AS path.
The AS path solves two problems at once:
- Loop detection. If a router sees its own AS number in a received path, the route has already passed through its network. It discards the route. No hold-down timers, poison reverse, or maximum metric is needed. Count to infinity cannot occur, because a looping path is rejected on sight.
- Policy hooks. The path is visible, so a network can filter or prefer routes by which ASes appear in them.
A minimal path-vector model
The code below mirrors the Bellman-Ford sketch from earlier chapters. The cost comparison becomes a path-length comparison, and a loop check comes first.
def receive(my_as, rib, prefix, as_path):
"""rib: prefix -> AS path (tuple). as_path: path as received from a neighbor."""
if my_as in as_path:
return False # loop: our own AS is already on the path
cur = rib.get(prefix)
if cur is None or len(as_path) < len(cur):
rib[prefix] = as_path
return True
return False
def advertise(my_as, rib):
"""Prepend our AS number to every path before sending it onward."""
return {prefix: (my_as,) + path for prefix, path in rib.items()}
prefix = "192.0.2.0/24"
rib_a = {prefix: ()} # AS 65001 originates the prefix
rib_b, rib_c = {}, {}
print(receive(65002, rib_b, prefix, advertise(65001, rib_a)[prefix])) # True
print(receive(65003, rib_c, prefix, advertise(65002, rib_b)[prefix])) # True
print(receive(65001, rib_a, prefix, advertise(65003, rib_c)[prefix])) # False (loop)
print(rib_c[prefix]) # (65002, 65001)This is a teaching model. Real BGP also handles withdrawals, multiple paths per prefix, and many more attributes.
How real BGP differs from the model
| Aspect | RIP (distance vector) | OSPF (link state) | BGP (path vector) |
|---|---|---|---|
| Information per route | Hop count | Full topology | Prefix plus AS path and attributes |
| Loop prevention | Split horizon, poison reverse, max metric 16 | Identical database and SPF | AS path contains own AS, so reject |
| Route choice | Lowest metric | Lowest total cost | Policy first, then shortest AS path and other tie-breakers |
| Updates | Periodic full table | Flooded changes | Incremental changes over a TCP session |
| Scope | Small internal networks | One organization | Between organizations |
Key points about the real protocol:
- BGP runs over TCP port 179. Peers are configured by hand, not discovered by hello packets. TCP supplies reliable delivery, so BGP sends the table once and then only changes.
- eBGP runs between different ASes. iBGP runs between routers in the same AS. An iBGP router does not re-advertise a route learned from one iBGP peer to another iBGP peer. The AS path cannot catch loops inside an AS, because it does not change there. This rule takes the place of split horizon, and it is why iBGP usually needs a full mesh of sessions, route reflectors, or confederations.
- Best-path selection checks attributes in a fixed order. Local preference comes first, and the highest value wins. A network sets it to express "prefer my customer's route over my provider's." Shortest AS path comes after that, then further tie-breakers.
- BGP does not find paths inside an AS. An IGP such as OSPF carries internal reachability, including the routes to BGP next hops. The two protocols work together.
Trade-offs and failure modes
- Slow convergence. BGP can explore many longer alternate paths before it settles after a withdrawal, a behavior called path exploration. Per-peer advertisement timers (the minimum route advertisement interval) slow this further. Convergence can take minutes, versus seconds for a tuned OSPF.
- Trust. BGP accepts what neighbors say. A network that wrongly announces a prefix it does not own can pull traffic toward itself. This is a route leak or hijack. Prefix filters and origin validation with RPKI reduce the risk.
- Policy conflicts. Because each network sets its own preferences, inconsistent policies can cause oscillation, where routes keep flipping and never converge.
Choosing at a glance
Use an IGP inside your network (OSPF or IS-IS for most medium and large networks, RIP only for small or legacy ones). Use BGP at the edge, where you connect to other organizations and policy matters more than the shortest path.
Exercise
A router in AS 65010 receives an announcement for 198.51.100.0/24 with the AS path [65020, 65010, 65030]. What does it do, and why does BGP need no hold-down timer or maximum metric to prevent a count-to-infinity loop here?
Show answer
It discards the route, because its own AS number (65010) already appears in the path, which means the route has passed through its network and would form a loop. Every path carries the full list of ASes, so a looping route is rejected the moment it arrives. Distance-vector protocols see only a cost, so they cannot recognize a loop and need split horizon, hold-down, and a maximum metric.
Exercise
Two paths to the same prefix reach your router. Path X has AS path length 2 and local preference 100. Path Y has AS path length 4 and local preference 200. Which does BGP choose, and why?
Show answer
Path Y. Local preference is compared before AS path length, and the higher value wins. Policy overrides path length.