cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
414
Views
35
Helpful
4
Replies

BGP Best Path Selection Algorithm Question

Dear Community,

 

I am reading that step 3 of the BGP best path selection is the following:

 

"3. If the LOCAL_PREF values are the same, prefer the route that was originated locally on the router and injected into BGP with the network or aggregate statement or through redistribution. That is, prefer a route that was learned from an IGP or from a direct connection on the same router. Note that a route injected into BGP via the network statement or redistribution is preferred over a local aggregate injected by the aggregate-address statement."

 

I am having issues understanding this statement and had the following questions:

 

1) Does this mean that if a router receives a route (NLRI) via BGP for a network that the router itself already knows about through either an IGP or directly connected, that it will prefer the IGP/Directly connected route over the BGP learned route?

 

2) Does this mean that if a router receives the same route (NLRI) from two different sources, that it will choose the route along the path that contains the "true" originating router? Put another way, will it choose the route that leads back to the router that advertised this route via the "network"/"redistribution"/"aggregate" statement vs just forwarding it on after learning it?

 

3) If #2 is true, how does the receiving router know which path leads back to the "true" origin? Via the Origin code?

 

Thank so much for any help you can provide in clearing this up. 

 

1 Accepted Solution

Accepted Solutions

Giuseppe Larosa
Hall of Fame Master Hall of Fame Master
Hall of Fame Master

Hello @ChristopherCraddock66504 ,

when referring to the BGP best path selection all the candidates are BGP advertisements.

 

In Cisco implementation step 3 is almost never used for a simple reason:

locally injected BGP prefixes have weight 32,768 so they are picked up at step 1 the highest weight.

Step 3  just tells us that in case there is a BGP prefix originated locally in two ways:  way1 by network command  , way2 via aggregate-address command the first method via network command is preferred.

 

1)  No the meaning is the one I have reported above in the BGP best path selection the comparison is always done between different BGP advertisements that are present in the BGP table.  So if a router receives a BGP prefix that is exaclty the same ( prefix and prefix length) as a connected route or an IGP route the following happens:

in case of a connected route the Connected route will be installed in the IP routing table, the BGP prefix is accepted and stays in the BGP table.

in case of an IGP route it depends from the type of BGP session the BGP prefix was received :

eBGP has AD 20 so the BGP route in this case will override the IGP prefix and will be installed in the IP routing table and the BGP table.

iBGP has AD 200 so the BGP route is not installed in the IP routing table and it stays in the BGP table only.

 

>> 2)

Does this mean that if a router receives the same route (NLRI) from two different sources, that it will choose the route along the path that contains the "true" originating router? Put another way, will it choose the route that leads back to the router that advertised this route via the "network"/"redistribution"/"aggregate" statement vs just forwarding it on after learning it?

 

If a router receives two BGP advertisements for the same prefix it will apply the BGP best path selection algorithm to select a best path using the first criteria in the ordered list that allows to choice a best one.

First it checks the respective BGP next-hops that need to be known in its local IP routing table in order to make the advertisement acceptable,

Then if weight are the same, local preference is the same, the AS path length attribute comes to play . The AS path attribute tells how many AS the route has gone through not how many routers. However, a shortest AS path is preferred and it is considered nearer to the source of the prefix.

If the AS path length are the same the origin code is considered and a network command leads always to a code of i IGP preferred over E EGP preferred over ?  ( unknown used by Cisco implementation when using redistribute command).

 

3) >> how does the receiving router know which path leads back to the "true" origin? Via the Origin code?

 

The origin code is considered only if the AS path length are the same, in that case if the origin codes are different the one with ì code will be picked up as best path.

 

Be aware that the BGP origin code can be modified using a route-map when needed, so there is no guarantee that an origin code of i means the prefix was generated by network command.

 

Hope to help

Giuseppe

 

View solution in original post

4 Replies 4

Giuseppe Larosa
Hall of Fame Master Hall of Fame Master
Hall of Fame Master

Hello @ChristopherCraddock66504 ,

when referring to the BGP best path selection all the candidates are BGP advertisements.

 

In Cisco implementation step 3 is almost never used for a simple reason:

locally injected BGP prefixes have weight 32,768 so they are picked up at step 1 the highest weight.

Step 3  just tells us that in case there is a BGP prefix originated locally in two ways:  way1 by network command  , way2 via aggregate-address command the first method via network command is preferred.

 

1)  No the meaning is the one I have reported above in the BGP best path selection the comparison is always done between different BGP advertisements that are present in the BGP table.  So if a router receives a BGP prefix that is exaclty the same ( prefix and prefix length) as a connected route or an IGP route the following happens:

in case of a connected route the Connected route will be installed in the IP routing table, the BGP prefix is accepted and stays in the BGP table.

in case of an IGP route it depends from the type of BGP session the BGP prefix was received :

eBGP has AD 20 so the BGP route in this case will override the IGP prefix and will be installed in the IP routing table and the BGP table.

iBGP has AD 200 so the BGP route is not installed in the IP routing table and it stays in the BGP table only.

 

>> 2)

Does this mean that if a router receives the same route (NLRI) from two different sources, that it will choose the route along the path that contains the "true" originating router? Put another way, will it choose the route that leads back to the router that advertised this route via the "network"/"redistribution"/"aggregate" statement vs just forwarding it on after learning it?

 

If a router receives two BGP advertisements for the same prefix it will apply the BGP best path selection algorithm to select a best path using the first criteria in the ordered list that allows to choice a best one.

First it checks the respective BGP next-hops that need to be known in its local IP routing table in order to make the advertisement acceptable,

Then if weight are the same, local preference is the same, the AS path length attribute comes to play . The AS path attribute tells how many AS the route has gone through not how many routers. However, a shortest AS path is preferred and it is considered nearer to the source of the prefix.

If the AS path length are the same the origin code is considered and a network command leads always to a code of i IGP preferred over E EGP preferred over ?  ( unknown used by Cisco implementation when using redistribute command).

 

3) >> how does the receiving router know which path leads back to the "true" origin? Via the Origin code?

 

The origin code is considered only if the AS path length are the same, in that case if the origin codes are different the one with ì code will be picked up as best path.

 

Be aware that the BGP origin code can be modified using a route-map when needed, so there is no guarantee that an origin code of i means the prefix was generated by network command.

 

Hope to help

Giuseppe

 

Giuseppe,

 

Thanks again so much for the detailed explanations. This really is helping me to understand the best path selection process. I truly appreciate the time you are taking to assist. 

paul driver
VIP Expert VIP Expert
VIP Expert

Hello


@ChristopherCraddock66504 wrote:

Does this mean that if a router receives a route (NLRI) via BGP for a network that the router itself already knows about through either an IGP or directly connected, that it will prefer the IGP/Directly connected route over the BGP learned route?


YES


@ChristopherCraddock66504 wrote:

(2) Does this mean that if a router receives the same route (NLRI) from two different sources, that it will choose the route along the path that contains the "true" originating router? Put another way, will it choose the route that leads back to the router that advertised this route via the "network"/"redistribution"/"aggregate" statement vs just forwarding it on after learning it?


YES


@ChristopherCraddock66504 wrote:

3) If #2 is true, how does the receiving router know which path leads back to the "true" origin? Via the Origin code?


Yes - the Origin path attribute (PA) code notations describe how the NLRI was first entered into to bgp table, which is then part of the over all bgp path selection process, However its worth noting the origin code can be manually change thus affecting how that prefix is then selected within bgp.

 

(i) IGP = Network command, bgp neighbour default route
(e) EGP = not applicable now
(?) incomplete =  redsitributed, aggreegate, default route originate




Addtionaly - summary routes via the aggreegate-address origin codes
As-set (not used = (i)
As-set (used and all subnets in that summary have a origin of i  then = (i)
As-set (used and at least one of those subnets in that summary have a origin of i  then = (?)

Please rate and mark as an accepted solution if you have found any of the information provided useful.
This then could assist others on these forums to find a valuable answer and broadens the community’s global network.

Kind Regards
Paul

Thank you Paul, your reply is very much appreciated. 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers