BGP Path Selection: Selects The Best Path Based On A List of Attributes
BGP Path Selection: Selects The Best Path Based On A List of Attributes
IGPs, such as EIGRP or OSPF, choose routes based on lowest metric. They attempt to find the
shortest, fastest way to get traffic to its destination. BGP, however, has a different way of route
selection. It assigns various attributes to each path; these attributes can be administratively
manipulated to control the path that is selected.
Point to be noted-
When BGP has multiple paths to reach the destination they are stored in the BGP table. but only one
gets installed in the routing table.
Path attributes –
Path attributes is one kind of criteria which is used for best path selection in bgp.
BGP chooses a route to a network based on the attributes of its path. Four categories of attributes exist
as follows:
Well-known mandatory –
Must be recognized by all BGP routers, present in all BGP updates, and passed on to other BGP routers.
Such as - Next hop AS path, origin code.
Well-known discretionary –
Must be recognized by all BGP routers and passed on to other BGP routers but need not be present in
an update, such as - local preference.
Optional transitive –
Might or might not be recognized by a BGP router but is passed on to other BGP routers. If not
recognized, it is marked as partial, such as - Aggregator, community.
Optional nontransitive –
Might or might not be recognized by a BGP router and is not passed on to other routers, for such as -
Multi-Exit Discriminator (MED), originator ID.
1. If next hop not reachable then it will not compare other path attribute, if any router is receiving
any prefix from two NBR and next hop is reachable via both router, then BGP will not define
best path based on next hop only.
2. Next hop is a well-known mandatory attribute.
3. Automatically included in update msg.
Note – this attributes’ you can easily verify using two or three routers.
Weight Attribute-
1. It is a Cisco proprietary attribute; it means you won’t find it on other vendor router.
2. With using we can manipulate the path, we can decide which path/route should be more
preferable than other path.
3. For self advertised prefix weight will be always – 32768
4. Weight range (0- 65535), it means we can change weight up to 65535.
5. For receiving prefix weight will be always – 0; it means Weight is not exchanged between BGP
routers.
6. BGP will not carry weight information with bgp updates.
7. It is a locally significant, it means for locally generated routes or it is only locally significant in the
Router where it is configured.
8. Higher weight will be always preferred.
9. This attribute is not advertised to any bgp NBR.
10. It is used to manipulate route-selection to for outbound traffic.
11. You can configure weight per neighbor using the weight command.
Point to be remembered – Weight is applied where routers have two or multiple exit points.
Now let’s grasp these things that we have discussed above. By the simple topology.
So far I didn’t configure weight as you can see R1 router select path via 12.1.1.2, now I’m going to apply
weight on R1 router you will be able to see that traffic will be going through 13.1.1.2 ( R3 router ).
All right everything is okay till now.
Weight configuration –
(Before apply this command you should know what can be potential impact on your network)
Hence using the weight attribute we can manipulate path for outgoing traffic, OR you can say using
weight attribute we can make the decision with path/ route should be more preferable.
When you applies clear ip bgp * soft in what happens in the backhand.
Local Preference attribute in BGP.
1. Local preference is a well known discretionary attribute.
2. Local preference is exchanged within the AS (IBGP) and it only stays within the AS (iBGP).
3. Not exchanged between the AS.
4. Local preference defines how data traffic should be exit from an AS.
5. By default local preference value is – 100
6. Higher local preference will be always preferred.
7. Local Preference is a 32-bit number.
8. Local preference range is - 0 to 4294967295
9. It is configured on a router and exchanged between IBGP routers.
10. local preference attribute is part of the routing update and is exchanged among routers in
The same AS.
Note –
Local Preference is passed on to iBGP peers. If multiple paths exist, Local Preference BGP informs iBGP
routers how to exit the AS. Which path to prefer for outgoing traffic.
There are many ways to set local preference but here we have described only two methods.
➢ Directly putting default local preference by iBGP router to its neighbors. For an example.
R(config)# router bgp 100.
R(config-router)# bgp default local-preference 200
➢ On per route basis by calling a Route-map and access list/prefix-list through a neighbor. For an
example
R(config)# ip prefix-list Google 8.8.8.0/24
R(config)# route-map PREF permit 10
R(config-route-map)# match ip address prefix-list Google
R(config-route-map)# set local-preference 300
R(config)# router bgp 100
R(config)# neighbour 50.1.1.2 route-map PREF in
Another method –
➢ Access-list 10 permit 8.8.8.0 0.0.0.255
➢ route-map loca_pre permit 10
match ip address 10
set local-prefrence 200
route-map local_pre permit 20
exit
➢ router bgp 100
neighbor 50.1.1.2 route-map local_pre in
Whenever router prefix information with IBGP NBR then local preference will be add and whenever
IBGP router share prefix with EBGP neighbor then local preference will not add.
Self advertised –
1. Prefer route originated by the local router (next hop= 0.0.0.0)
2. Self advertised prefix will be always preferred.
3. If router receiving same prefix from different NBR then it will not compare self advertised.
4. Prefer the path that the local router originated. In the BGP table, you will see next hop 0.0.0.0.
You can get a path in the BGP table through the BGP network command, aggregation, or
redistribution. A BGP router will prefer routes that it installed into BGP itself over a route that
another router installed in BGP.
As you can see above the both router only advertised self advertised route/path.
After that you will check whether bgp route installed in routing or not – there is no route.
AS Path attribute-
On every router to check bgp updates message after that shut down the loopback of R3 router then you
will see which path will become as a best path, I’m just showing you for an example only here.
Configuration –
There are three origin codes you could see in the BGP table:-
I = BGP prefix
E= EGP prefix
? = Redistributed prefix
I = it means you have advertised this prefix using network command therefore you are getting this code.
Or you can say that - You will see IGP when you use the network command for BGP. It means you
advertised the network yourself in BGP.
Let’s prove it –
E= EGP prefix:-
EGP is historical and you won’t see it in the BGP table anymore. EGP is an old routing protocol we don’t
use it anymore.
Or you can say it – it is a old version of BGP, before it was using EGP, in legacy IOS were support it.
? = Redistributed prefix:-
Incomplete means you have redistributed something into BGP. Here’s a demonstration:-
?= it means this is bgp prefix, it is coming from any other routing protocol means redistributed prefix.
1. MED attribute:-
Configuration –
R1#show run | section bgp
router bgp 65502
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
network 192.168.1.0
network 192.168.2.0
neighbor 10.1.1.2 remote-as 65501
neighbor 30.1.1.2 remote-as 65501
no auto-summary
R1#
=================================
R2#show run | section bgp
router bgp 65501
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
redistribute ospf 100 metric 2
neighbor 4.4.4.4 remote-as 65501
neighbor 4.4.4.4 update-source Loopback2
neighbor 10.1.1.1 remote-as 65502
neighbor 20.1.1.1 remote-as 65501
neighbor 50.1.1.1 remote-as 65501
no auto-summary
R2#
=====================================
R2#show run | section ospf
router ospf 100
router-id 2.2.2.2
log-adjacency-changes
redistribute connected subnets
passive-interface GigabitEthernet0/0
network 2.2.2.0 0.0.0.255 area 0
network 20.1.1.0 0.0.0.255 area 0
network 50.1.1.0 0.0.0.255 area 0
redistribute ospf 100 metric 2
======================================
R3#show run | section bgp
router bgp 65501
no synchronization
bgp router-id 3.3.3.3
bgp log-neighbor-changes
redistribute ospf 100 metric 3
neighbor 4.4.4.4 remote-as 65501
neighbor 4.4.4.4 update-source Loopback3
neighbor 30.1.1.1 remote-as 65502
neighbor 40.1.1.1 remote-as 65501
neighbor 50.1.1.2 remote-as 65501
no auto-summary
R3#
========================================
R3#show run | section ospf
router ospf 100
router-id 3.3.3.3
log-adjacency-changes
redistribute connected subnets
passive-interface GigabitEthernet1/0
network 3.3.3.0 0.0.0.255 area 0
network 40.1.1.0 0.0.0.255 area 0
network 50.1.1.0 0.0.0.255 area 0
redistribute ospf 100 metric 3
=========================================
R4#show run | section bgp
router bgp 65501
no synchronization
bgp router-id 4.4.4.4
bgp log-neighbor-changes
neighbor 2.2.2.2 remote-as 65501
neighbor 2.2.2.2 update-source Loopback4
neighbor 3.3.3.3 remote-as 65501
neighbor 3.3.3.3 update-source Loopback4
neighbor 20.1.1.2 remote-as 65501
neighbor 40.1.1.2 remote-as 65501
no auto-summary
R4#
========================================
R4#show run | section ospf
router ospf 100
router-id 4.4.4.4
log-adjacency-changes
network 4.4.4.0 0.0.0.255 area 0
network 20.1.1.0 0.0.0.255 area 0
network 40.1.1.0 0.0.0.255 area 0
R4#
As you can see that we have designed topology for the redundancy in order to network should be
available forever. let me show you one by one .
Just look the trace route from R1 router, what did I do? Simply I have gone on R2 router shut down the
S4/0 interface & gigabitEthernet2/0. Then you get below output.
Traceroute from R1 to 4.4.4.0/24
Now What am I going to do to test MED but before that we have to verify from which path traffic is
going on then we will apply MED according to that.
R2#show access-lists
R2#
2. eBGP path over iBGP path (External over internal)
1. Prefer EBGP path over IBGP path it means if any prefix coming from to different NBR
one is IBGP NBR and another is one EBGP NBR then BGP will prefer external prefix
means EBGP prefixes’.
Configuration –
1. Prefer the path within the autonomous system with the lowest IGP metric to the BGP next hop.
2. If IGP configured background of bgp then bgp can use IGP cost to reach next hop address.
4. Oldest path (only for EBGP neighbors)
1. Prefer the path that we received first, in other words, the oldest path.
2. If router receiving same prefix coming from two different EBGP NBR then oldest path will be
always preferred.
3. Oldest path only compared is in EBGP Neighborship, not an IBGP.
4. Prefix that will receive first will become as a best path whether lower NBR ip address or not
same.
Right now I’m going to shutdown NBR using bgp command on RTR4_ISP –
➢ RTR4_ISP(config)#router bgp 65001
➢ RTR4_ISP(config-router)#neighbor 20.1.1.1 shutdown
Proved now –
1. Prefer the path with the lowest BGP neighbor router ID. The router ID is based on the highest IP
address. If you have a loopback interface, then the IP address on the loopback will be used. The
router ID can also be manually configured.
2. Router-id election criteria same as OSPF protocol
3. Lower router-id will be always preferred.
4. If router is receiving same prefix coming from two different IBGP neighbor then lower router-id
of NBR will be always preferred.
Let’s prove it –
Proved –
Note – you can also verify lower NBR router-id using below command –
Point to be noted –
If NBR router-id will be same then it will compare next attribute that is called – Lower neighbor ip
address.
6. Lower neighbor ip address –
1. Prefer the path with the lowest neighbor IP address. If you have two eBGP routers and two links
in between then the router ID will be the same. In this case, the neighbor IP address is the
tiebreaker.
2. If router is receiving same prefix coming from two NBR which router-id has same then lower
NBR router ip address will be preferred.
1. Whenever any routers give update to its ebgp neighbor, it will advertise update after modifying
their next-hop address.
2. whenever any router give update to its ibgp neighbor, it will advertise update without
Modifying their next-hop address
In order to I can enhance my skills. BGP full notes will be uploaded soon. One
more things please broadcast this notes with your friends & group, comment as
well.