The Router-ID Inside BGP Best Path Selection

Where the Router-ID Fits in the Algorithm

Most BGP decisions are made early in the best path algorithm. Weight, local preference and AS_PATH length decide the vast majority of prefixes in a real network, and engineers rarely look further. But in the CCIE lab, and in networks with redundant exits and route reflectors, many prefixes arrive at the router with every early attribute equal. Those prefixes are decided by the last few steps, and almost all of those steps are about the Router-ID.

On Cisco IOS and IOS XE the algorithm compares paths in this order. Highest weight. Highest local preference. Locally originated routes. Shortest AS_PATH. Lowest origin code. Lowest MED, when the paths come from the same neighbouring AS. eBGP paths over iBGP paths. Lowest IGP metric to the next hop. Then, after the multipath check, come the steps this post is about: the oldest eBGP path, the lowest Router-ID, the shortest CLUSTER_LIST, and the lowest neighbour address.

Before going further, remember what the Router-ID is. It is the 32-bit BGP Identifier each router sends in its OPEN message, written like an IPv4 address. On Cisco it comes from "#bgp router-id", or from the highest up loopback, or from the highest up physical interface. In "#show ip bgp" detail output it is the value in brackets after the word "from".

To see these steps in action, consider a simple lab. R1 sits in AS 65001 with Router-ID 1.1.1.1. It has two eBGP neighbours: R2 in AS 65002 with Router-ID 2.2.2.2, and R3 in AS 65003 with Router-ID 3.3.3.3. Both learn 192.0.2.0/24 from AS 65100 and pass it to R1 with identical attributes. The AS_PATH length is two on both paths, the origin is IGP on both, there is no MED comparison because the neighbouring AS numbers differ, both paths are external, and both next hops are directly connected.

R1(config)#router bgp 65001
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#neighbor 10.1.12.2 remote-as 65002
R1(config-router)#neighbor 10.1.13.3 remote-as 65003

The Final Steps, One by One

Bring up the session to R3 first and the session to R2 a minute later. R1 now has two equal paths.

R1#show ip bgp 192.0.2.0
BGP routing table entry for 192.0.2.0/24, version 5
Paths: (2 available, best #2, table default)
  Advertised to update-groups:
     1
  Refresh Epoch 1
  65002 65100
    10.1.12.2 from 10.1.12.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 100, valid, external
  Refresh Epoch 1
  65003 65100
    10.1.13.3 from 10.1.13.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, external, best

The path through R3 is best, even though 3.3.3.3 is higher than 2.2.2.2. The reason is the oldest path rule. When both paths are external, Cisco keeps the path it received first. The goal is stability: if every newly arrived equal path replaced the current best, a flapping session somewhere upstream would make the best path, and the traffic, flap with it.

The consequence is that the result depends on history. Reload R3, let R2's path become the only path for a moment, and the best path will now stay on R2 after R3 returns. Two identical routers with identical configuration can reach different decisions.

Cisco skips this step in two situations. It is skipped when the paths have the same Router-ID, which happens with parallel sessions to the same neighbour, and it is skipped when there is no current best path yet, for example right after the router boots. In both cases the algorithm continues to the next step, which means eBGP paths can reach the neighbour address step too.

A decision based on history is not always what you want. To remove it, configure "#bgp bestpath compare-routerid". It tells the router to ignore the age of eBGP paths and go straight to the Router-ID comparison.

R1(config)#router bgp 65001
R1(config-router)#bgp bestpath compare-routerid
R1#show ip bgp 192.0.2.0
BGP routing table entry for 192.0.2.0/24, version 7
Paths: (2 available, best #1, table default)
  Advertised to update-groups:
     1
  Refresh Epoch 1
  65002 65100
    10.1.12.2 from 10.1.12.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 100, valid, external, best
  Refresh Epoch 1
  65003 65100
    10.1.13.3 from 10.1.13.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, external

The lowest Router-ID, 2.2.2.2, wins, and the result will be the same after every reload. In an exam task that says "the decision must not depend on which session came up first", this command is the answer. In production it is a design choice: it gives predictability, at the cost of the stability the oldest path rule provides.

The comparison changes once route reflectors deliver the paths, because route reflection changes what "Router-ID of the advertising router" means. A client that receives a reflected route does not peer with the router that originated it, so the bracketed value after "from" is the reflector's identifier, which says nothing about the actual exit. For this reason Cisco uses the ORIGINATOR_ID in place of the Router-ID when the path carries one.

Consider R5, a route reflector client in AS 65000. Two PEs, PE2 with Router-ID 2.2.2.2 and PE3 with Router-ID 3.3.3.3, both learn 198.51.100.0/24 with equal attributes. Reflector RR11 reflects PE3's path and reflector RR14 reflects PE2's path, and the IGP metrics to both PEs are equal.

R5#show ip bgp 198.51.100.0
BGP routing table entry for 198.51.100.0/24, version 12
Paths: (2 available, best #2, table default)
  Not advertised to any peer
  Refresh Epoch 1
  64510
    3.3.3.3 (metric 20) from 11.11.11.11 (11.11.11.11)
      Origin IGP, metric 0, localpref 100, valid, internal
      Originator: 3.3.3.3, Cluster list: 11.11.11.11
  Refresh Epoch 1
  64510
    2.2.2.2 (metric 20) from 14.14.14.14 (14.14.14.14)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      Originator: 2.2.2.2, Cluster list: 14.14.14.14

If R5 compared the reflectors' identifiers, the copy from 11.11.11.11 would win and traffic would leave through PE3. Cisco compares the originators instead, 2.2.2.2 against 3.3.3.3, so PE2 wins. Swap which reflector carries which path, and the result still stays on PE2. The exit chosen depends on the PEs, not on which reflector happened to deliver the path. That is the purpose of the substitution.

The oldest path rule does not apply here, because these are internal paths.

Sometimes the originators are the same, and then the next step has to decide, because the Router-ID step cannot separate them. The most common case is redundant reflectors: both RR14 and RR11 reflect the same path from PE2 to R5.

R5#show ip bgp 203.0.113.0
BGP routing table entry for 203.0.113.0/24, version 15
Paths: (2 available, best #2, table default)
  Not advertised to any peer
  Refresh Epoch 1
  64520
    2.2.2.2 (metric 20) from 14.14.14.14 (14.14.14.14)
      Origin IGP, metric 0, localpref 100, valid, internal
      Originator: 2.2.2.2, Cluster list: 14.14.14.14
  Refresh Epoch 1
  64520
    2.2.2.2 (metric 20) from 11.11.11.11 (11.11.11.11)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      Originator: 2.2.2.2, Cluster list: 11.11.11.11

The originators are equal, and the CLUSTER_LIST length is one on both, so this step does not decide either. In hierarchical designs, where one copy has crossed two clusters and the other only one, the shorter list wins here. Note what this step is not: there is no separate rule that prefers non-reflected paths over reflected ones. A non-reflected path has an empty CLUSTER_LIST, so it wins here only after the Router-ID comparison has already tied.

When nothing else separates two paths, the last step does. It compares the address of the neighbour the path was received from. In the output above, 11.11.11.11 is lower than 14.14.14.14, so the copy from RR11 is best. Both copies lead to the same PE, so traffic is unaffected. Only the control plane choice changes.

The same step settles parallel eBGP sessions. If R1 has two links to R2 with a session on each, both paths carry Router-ID 2.2.2.2, the oldest path step is skipped because the identifiers are equal, the CLUSTER_LIST is empty on both, and the lower neighbour address wins.

R1#show ip bgp 192.0.2.0
BGP routing table entry for 192.0.2.0/24, version 9
Paths: (2 available, best #1, table default)
  Advertised to update-groups:
     1
  Refresh Epoch 1
  65002 65100
    10.1.12.2 from 10.1.12.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 100, valid, external, best
  Refresh Epoch 1
  65002 65100
    10.2.12.2 from 10.2.12.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 100, valid, external

What This Means for Design and the Lab

Three practical rules come out of these steps. First, if your design relies on the last steps to choose an exit, the Router-ID plan is part of your traffic engineering, so choose identifiers deliberately and never let them change by accident. Second, if you want a predictable eBGP decision, configure "#bgp bestpath compare-routerid", and if you want stability, leave the oldest path rule alone. Third, if you actually care which exit wins, do not rely on these steps at all. Set local preference, weight or MED, so the decision is made early, documented, and easy to change.

In the lab, when a task's two paths look identical, read the bracketed values and the Originator line before you touch any policy. The answer is often already printed in the output.