The BGP weight attribute is the first on the list in the BGP best path algorithm
- Prefer the path with the highest WEIGHT.
Note: WEIGHT is a Cisco-specific parameter. It is local to the router on which it is configured.
So if you want to influence your BGP routing outbound on a cisco router you can set the weight attribute. However this value is only locally significant on the router and the information is not passed between neighbors. This solution does not scale very well and in most cases local preference is used as this attribute is passed between iBGP neighbors.
There are some circumstances where weight is used and in the following examples I will show you how to configure it.
Note: The default weight for learned routes is 0 and the default weight for a locally originated route is 32768
Using the topology below lets go through a bgp weight configuration example.
BGP Weight Attribute Configuration
Each router in this topology is addressed with its router number as the last octet .eg all interfaces on R1 end in .1 and on R5 .5 etc
Each router has a loopback configured and advertised into BGP R1=184.108.40.206, R2=220.127.116.11 etc
All routers are peering with each other using eBGP
Lets take a look at the BGP output on R1 to see its view of the network.
Using the command sh ip bgp we can see all the prefixes in BGP the chosen route is the one with the < beside it.
In this case for R1 to get to R6 it has chosen the path through R4
You can see for the prefix 18.104.22.168/32 there are two paths one through 10.0.15.4 (R5) and the other through 10.0.14.4 (R4)
The weights for both of these routes are 0, you can also see for the prefix 22.214.171.124 (loopback on R1) that the weight is 32768 this is because it is a locally generated route.
You might be wondering why R1 has chosen to route via R5? If we take a moment away from BGP Weight and just step through the BGP best path algorithm you we will work it out.
- Prefer the path with the highest Weight – Both Weights are equal so move onto step2
- Prefer the path with the highest Local Preference – Local preference is the same for both routes
- Prefer the path that was locally originated – Same for both
- Prefer the path with lowest AS Path – Both routes have an AS path of 2
- Prefer the path with the lowest origin type – Same for both
- Prefer the path with the lowest MED – Skipped
- Prefer eBGP over iBGP – both routes are eBGP
- Prefer the path with the lowest IGP metric to the next BGP Hop – Same for both
- Check if multipath is enabled – Skipped
- When both paths are external prefer the oldest one – This is the tiebreaker!
So after all of that we have come down to the oldest route in the table, so basically the one that loaded first.
To prove that we can restart the bgp process on R4 to make R5 the oldest route. On R4 I have done a clear ip bgp * This now makes the route through R5 the oldest one and is preferred.
Back to BGP weight! – we now want to ensure that whatever happens R1 will route through R4 (10.0.14.4) to get to 126.96.36.199
To achieve that using weight we have two options.
- Set the Weight Attribute on the neighbor – this will affect all routes learnt from that neighbor
- Using a route-map and an access list only match specific routes to have the weight set on.
First lets set the weight using the neighbor statement.
Under BGP enter the following command – neighbor 10.0.14.4 weight 100
R1#conf t Enter configuration commands, one per line. End with CNTL/Z. R1(config)#router bgp 1 R1(config-router)#neighbor 10.0.14.4 weight 100 R1(config-router)#end R1# R1#sh run | sec router bgp router bgp 1 bgp log-neighbor-changes network 188.8.131.52 mask 255.255.255.255 network 10.0.14.0 mask 255.255.255.0 network 10.0.15.0 mask 255.255.255.0 neighbor 10.0.14.4 remote-as 4 neighbor 10.0.14.4 weight 100 neighbor 10.0.15.5 remote-as 5 R1#
You can see now the weight attribute is configured for the neighbor 10.0.14.4 (R4) This will affect all routes learnt from R4 lets take a look at the bgp table now.
You will also notice that all prefixes received from R4 have also had their weight changed to 100
So the other option is to set the weight on a per prefix basis using a route-map
For this example we only want to set the weight for the 184.108.40.206/32 prefix
First we need to match this prefix in an access list
R1(config)#access-l 1 permit 220.127.116.11 0.0.0.0 R1(config)#route-map SET-WEIGHT permit R1(config-route-map)#match ip address 1 R1(config-route-map)#set weight 100 R1(config-route-map)#route-map SET-WEIGHT permit 20
This is now applied to the neighbor statement for R4 – we also need to remove the previous weight attribute
R1(config)#router bgp 1 R1(config-router)#no neighbor 10.0.14.4 weight 100
R1(config-router)#neighbor 10.0.14.4 route-map SET-WEIGHT in
If we just do a route-refresh you can see the attributes change
R1#clear ip bgp * soft in
This does a route refresh with the new attributes but does not take down the BGP neighbor
Take a look at the changes below
You can see now that we have changed the weight attribute for the 18.104.22.168/32 prefix only. All other routes have the default weight of 0.
To compare the differences of BGP Weight vs Local Preference please read my post on the BGP Local Preference Attribute.
For a Video walk through of this post click play on the video below
Good luck with your studies!