Explaining BGP path vector and preference hierarchy
BGP is a path vector protocol that prevents loops by using the AS_PATH attribute, where each AS appends its ASN when advertising routes; receiving its own ASN signals a loop, so the route is rejected. The best path selection prioritizes Cisco-specific weight (local to the router), then local preference (shared within an AS), followed by shortest AS path length, and origin code, emphasizing BGP's design for inter-AS routing and loop avoidance, with iBGP employing split-horizon rules to prevent forwarding learned routes among peers.
Border Gateway Protocol is described as a path‑vector protocol because what gets exchanged between speakers is not just “I can reach prefix X at cost Y”, but “I can reach prefix X via this ordered list of autonomous systems”. Every UPDATE that leaves an AS has that AS’s number prepended to the AS_PATH attribute. As a route propagates from AS to AS it accumulates a vector of the ASes it has traversed.
That vector serves two purposes:
- It encodes policy information — you can prefer or de‑prefer routes based on where they’ve been.
- It allows simple loop detection. When a BGP speaker receives an UPDATE, one of the first checks it does is “does this
AS_PATH already contain my own ASN?”. If it does, then accepting and re‑advertising that path would create a loop back into the local AS, so the route is discarded. The same principle underlies the iBGP “split horizon” rule: routes learned from one iBGP neighbour are not advertised to another iBGP neighbour, to avoid endless oscillation inside an AS.
When a BGP speaker has more than one usable path to a prefix, it runs a well‑defined best‑path selection algorithm. The exact tie‑breakers vary by implementation, but the commonly cited first few in the hierarchy you mention are:
- Highest weight – a Cisco‑specific knob that is local to a single router. By default it’s 0; anything you set higher wins.
- Highest local preference – a value carried in the
LOCAL_PREF attribute and propagated to all iBGP peers within an AS. Default is 100; higher wins.
- Prefer routes that were locally originated on this router (via a
network statement, redistribute, or aggregate).
- Shortest
AS_PATH – fewer AS hops is preferred.
- Lowest origin type – routes originated by an IGP (
IGP) are preferred over ones learned from an EGP (EGP), which in turn are preferred over “incomplete” origins (typically redistributed from other protocols).
If those are equal there are further tie‑breakers such as lowest MED, eBGP over iBGP, lowest IGP metric to the next hop, and so on, but the weight/local‑pref/AS‑path/origin steps are the primary policy levers operators use.