BGP Best Path Selection Simulator (Cisco IOS order, step by step)
BGP Best Path Selection Simulator (Cisco IOS / IOS-XE)
Enter 2–8 candidate paths for one prefix, set the router options, and see which path Cisco IOS would select, why every other path lost, which paths become multipaths, and how the result looks in show ip bgp. Everything runs in your browser.
| Path | Valid | Peer type | Next hop | Neighbor IP | Weight | LOCAL_PREF | Locally originated | AIGP | AS_PATH | ORIGIN | MED | IGP metric | Age (s) | Peer router ID | ORIGINATOR_ID | CLUSTER_LIST len | Actions |
|---|
What this BGP best path simulator does
When a Cisco router learns the same prefix from several BGP neighbors it must pick exactly one best path (plus optional multipaths) to install in the routing table and advertise onward. The rules are simple to list but surprisingly easy to misapply in a lab or in an exam: MED is only compared between paths from the same neighboring AS, the “oldest path” rule applies only to eBGP paths, an AS_SET counts as one hop, and without bgp deterministic-med the outcome can depend on the order in which paths arrived. The simulator above implements the Cisco IOS/IOS-XE algorithm step by step and shows the pairwise comparisons that IOS actually performs, so you can check your reasoning for CCNP and CCIE study or before changing policy in production.
How BGP chooses the best path (Cisco order)
Paths that are not valid are ignored first: the next hop must be reachable (resolvable in the RIB), the path must not be suppressed or dampened, and a path whose AS_PATH contains the router's own AS is not accepted. Among the remaining paths Cisco IOS compares two paths at a time and the first attribute that differs decides:
- Highest weight. Cisco-specific, local to the router and never advertised. Default 0 for learned paths and 32768 for locally originated ones.
- Highest LOCAL_PREF. Shared inside the AS through iBGP; default 100. The normal tool to choose an exit point for outbound traffic.
- Locally originated. Paths created on this router with
networkor redistribution win over learned paths; they are also preferred over local aggregates created withaggregate-address. - Lowest AIGP (accumulated IGP metric, RFC 7311), when the attribute is present and enabled. The simulator compares it only when both paths carry a value.
- Shortest AS_PATH. An AS_SET counts as 1 regardless of how many ASNs it holds; AS_CONFED_SEQUENCE and AS_CONFED_SET are not counted. Skipped with
bgp bestpath as-path ignore. - Lowest ORIGIN: IGP (i) < EGP (e) < Incomplete (?).
- Lowest MED, by default only between paths whose first AS in the AS_PATH (the neighboring AS) is the same. A missing MED is treated as 0 unless
bgp bestpath med missing-as-worstmakes it 4,294,967,295.bgp always-compare-medcompares MED regardless of the neighboring AS. - eBGP over iBGP. Paths learned from confederation peers are treated as internal.
- Lowest IGP metric to the BGP next hop.
- Multipath determination. If
maximum-pathsis configured, paths that tie with the best path on all the previous steps (and meet the other multipath rules) are installed as well. This does not change the best path. - Oldest path, only when both paths are external. This keeps the best path stable and avoids flaps. Skipped with
bgp bestpath compare-routeridor when both paths come from the same router ID. - Lowest BGP router ID of the advertising peer. For reflected routes the ORIGINATOR_ID is used instead.
- Shortest CLUSTER_LIST, which matters when the originator/router ID is the same.
- Lowest neighbor address, the address configured in the
neighborstatement.
RFC 4271 (section 9.1) defines the vendor-neutral core of this list: LOCAL_PREF, then AS_PATH length, ORIGIN, MED from the same neighbor AS (a missing MED counts as the lowest value), eBGP over iBGP, interior cost to the next hop, BGP identifier and peer address. RFC 4456 adds ORIGINATOR_ID and CLUSTER_LIST for route reflection. Weight, the locally-originated step and the oldest-path rule are Cisco additions.
Worked examples
1. LOCAL_PREF beats a shorter AS_PATH
Preset “Local pref wins”: P1 is an eBGP path with AS_PATH 65001 (length 1) and the default LOCAL_PREF 100. P2 is an iBGP path with LOCAL_PREF 150 and a three-AS path. Weights are equal, so step 2 decides immediately and P2 wins; AS_PATH length (step 5) is never reached. This is why LOCAL_PREF is the main tool for outbound traffic engineering: it overrides everything that the neighbor ASes can influence.
2. MED from different neighboring ASes is ignored
Preset “MED from different ASes”: P1 (AS 65001, MED 50), P2 (AS 65002, MED 10) and P3 (AS 65001, MED 100) are all eBGP. With default settings IOS compares the newest path P1 with P2: different neighboring ASes, so MED is skipped, and the older path P2 wins on step 11. P2 against P3: again different ASes, and P3 is the oldest, so P3 wins – the path with the highest MED. Turn on bgp always-compare-med and P2 (MED 10) wins at step 7. With only bgp deterministic-med, P1 first beats P3 inside the AS 65001 group on MED, and then the group winners P1 and P2 are compared: P2 wins because it is older.
3. IGP metric tie-break and iBGP multipath
Preset “IGP metric tie-break”: three iBGP paths with identical attributes and IGP metrics 30, 20 and 20 to their next hops. P1 loses at step 9. P2 and P3 tie through step 9 and become multipaths with maximum-paths ibgp 2; the best path between them is chosen at step 12 by the lower router ID (P2). Because the paths are internal, the oldest-path rule is not used.
4. MED non-determinism (why deterministic-med exists)
Preset “MED non-determinism”: P1 (AS 65001, MED 200, router ID 10.0.0.1), P2 (AS 65002, MED 100, router ID 10.0.0.2) and P3 (AS 65001, MED 100, router ID 10.0.0.3), all iBGP with the same IGP metric. Head to head, P1 beats P2 (router ID), P2 beats P3 (router ID) and P3 beats P1 (MED) – a cycle, like rock-paper-scissors. Comparing newest first (P3, P2, P1) gives P1, but a different arrival order gives P2 or P3. The simulator tries every comparison order and reports the spread of winners. With bgp deterministic-med IOS first picks the best path of each neighbor AS (P3 for AS 65001, P2 for AS 65002) and then compares those, so the result is always P2.
Vendor differences
This simulator follows Cisco IOS and IOS-XE. Other implementations use the same RFC 4271 core but differ in details: Junos has no weight attribute (route preference plays a similar local role) and handles MED grouping and the age tie-breaker in its own way; IOS-XR and FRR have their own defaults and knobs (for example for MED handling, multipath and router-ID comparison). Always check the platform documentation before assuming that a tie-breaker behaves the same everywhere.
Known simplifications
- The sequential comparison starts with the newest path and walks to the oldest (or follows the table order if you choose it). Real IOS also takes the previously selected best path into account, so live behaviour after a churn event can differ.
bgp bestpath med confed, synchronization, RIB-failure, additional-paths and best-external are not modelled. Confederation segments are skipped when the neighboring AS for MED is determined.- Multipath checks: same peer class (eBGP or iBGP), not locally originated, equal weight, LOCAL_PREF, AIGP, AS_PATH length and content (only length with multipath-relax), ORIGIN, MED and IGP metric, and a different next hop.
FAQ
Why does my Cisco router ignore a lower MED?
By default IOS compares MED only between paths whose neighboring AS (the first AS in the AS_PATH) is the same. Paths from different ASes skip the MED step and are decided by later steps such as eBGP over iBGP, IGP metric, path age or router ID. Use bgp always-compare-med on every router in the AS if you want MED compared across neighbor ASes.
Is a missing MED the best or the worst value?
On Cisco IOS a missing MED is treated as 0, the best possible value, which matches RFC 4271. The command bgp bestpath med missing-as-worst treats it as 4,294,967,295 instead, so paths without MED lose the MED comparison.
What does bgp deterministic-med change?
Without it, IOS compares paths pairwise in arrival order, and because MED is only compared within the same neighbor AS the “better than” relation is not transitive, so the winner can depend on the order in which paths were received. With bgp deterministic-med paths are grouped by neighboring AS, the best path of each group is selected first, and then the group winners are compared. Cisco recommends enabling it consistently on all routers in the AS.
Why does the oldest eBGP path win instead of the lowest router ID?
For two external paths that tie through the IGP-metric step, IOS prefers the path received first to reduce route flapping. The rule is skipped if bgp bestpath compare-routerid is configured, if both paths have the same router ID, or if either path is internal – then the lowest router ID decides.
How does an AS_SET affect AS_PATH length?
An AS_SET, typically created by aggregate-address ... as-set, counts as one AS regardless of how many ASNs it contains. Confederation segments (AS_CONFED_SEQUENCE and AS_CONFED_SET) are not counted at all.
Is BGP weight advertised to neighbors?
No. Weight is a Cisco-specific value local to the router where it is set; it is not carried in any BGP update. To influence the whole AS, use LOCAL_PREF instead.
Comments
Post a Comment