#

Thursday, August 17, 2017

BGP Path Selection by Weight

Weight is the 1st attribute in the list.. It is the 1st thing which will be considered by a router to identify the best route. But because it is Cisco proprietary, you will not see it often.

(1) Can use to choose the best path for outbound traffic..
(2) Weight is not exchanged between routers, only local to the router..
(3) The path with the highest weight is preferred, default is 0..

Because weight is local to the router, we cannot use it with the routes we advertise to other neighbors. Route maps will be only applied to in bound traffic.. Let's see an example..


Basic BGP configuration is like the following..

R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 remote-as 2
R1(config-router)#neighbor 192.168.13.3 remote-as 2

R2(config)#router bgp 2
R2(config-router)#neighbor 192.168.12.1 remote-as 1
R2(config-router)#network 10.10.10.0 mask 255.255.255.0
R2(config-router)#network 20.20.20.0 mask 255.255.255.0

R3(config)#router bgp 2
R3(config-router)#neighbor 192.168.13.1 remote-as 1
R3(config-router)#network 10.10.10.0 mask 255.255.255.0
R3(config-router)#network 20.20.20.0 mask 255.255.255.0

For both 10.10.10.0/24 and 20.20.20.0/24 networks, best routes are learnt via 192.168.12.2 by default.. Because all other attributes are equal, the lowest router-id has become the most preferred..







Let's change this by changing the Weight of the routes.

Give higher weight to all the routes coming from one router?

If I want to make all the routes learning from R3 to be preferred, I would simply change the weight of the neighbor command for R3 on R1..

R1(config-router)#neighbor 192.168.13.3 weight 500

Hit clear ip bgp * to reset BGP neighbors and see the BGP table again..









Now you can see all the routes learnt via R3 is preferred now..

Give higher weight to some routes coming from one router?

Let's say I want to change only 20.20.20.0/24 to be weighted to 500. I would have to use a route map.. If you want to learn about route-maps, go here.

Let's clear the previous neighbor command and start again..

R1(config)#access-list 10 permit 20.20.20.0 0.0.0.255

R1(config)#route-map SET_WEIGHT permit 10
R1(config-route-map)#match ip address 10
R1(config-route-map)#set weight 500
R1(config)#route-map SET_WEIGHT permit 20

R1(config-router)#neighbor 192.168.13.3 route-map SET_WEIGHT in










Note:- 

The last line of the route map configuration route-map SET_WEIGHT permit 20 is necessary because the route map is applied to a BGP neighbor to filter routes. Without that line, only matching routes will be allowed, all other routes from that neighbor will be not advertised..

Also note that the default weight for a locally originated route is 32768..


No comments:

Post a Comment