BGP Weight Attribute



BGP Weight Attribute




The weight attribute is a Cisco defined attribute. The weight is used for a best path selection process. The weight is assigned locally to the router. It is a value that only makes sense to the specific router and which is not propagated or carried through any of the route updates. A weight can be a number from 0 to 65535. Paths that the router originates have a weight of 32768 by default and other paths have a weight of zero.

Routes with a higher weight are preferred when multiple routes exist to the same destination. Let us study the above example. RTA has learned about network 175.10.0.0 from AS4 and will propagate the update to RTC. RTB has also learned about network 175.10.0.0 from AS4 and will propagate it to RTC. RTC has now two ways for reaching 175.10.0.0 and has to decide which way to go. If on RTC we can set the weight of the updates coming from RTA to be higher than the weight of updates coming from RTB, then we will force RTC to use RTA as a next hop to reach 175.10.0.0. This is achieved by using multiple methods:

  • Using the neighbor command: neighbor {ip−address|peer−group} weight weight.
  • Using AS path access−lists: ip as−path access−list access−list−number {permit|deny} as−regular−expression neighbor ip−address filter−list access−list−number weight weight.
  • Using route−maps.
RTC#
router bgp 300
neighbor 1.1.1.1 remote−as 100
neighbor 1.1.1.1 weight 200
!−− route to 175.10.0.0 from RTA has 200 weight
neighbor 2.2.2.2 remote−as 200
neighbor 2.2.2.2 weight 100
!−− route to 175.10.0.0 from RTB will have 100 weight

Routes with higher weight are preferred when multiple routes exist to the same destination. RTA is preferred as the next hop.

The same outcome can be achieved using IP as−path and filter lists.

RTC#
router bgp 300
neighbor 1.1.1.1 remote−as 100
neighbor 1.1.1.1 filter−list 5 weight 200
neighbor 2.2.2.2 remote−as 200
neighbor 2.2.2.2 filter−list 6 weight 100
...
ip as−path access−list 5 permit ^100$
!−− this only permits path 100
ip as−path access−list 6 permit ^200$
...
The same outcome as above can be achieved by using routemaps.
RTC#
router bgp 300
neighbor 1.1.1.1 remote−as 100
neighbor 1.1.1.1 route−map setweightin in
neighbor 2.2.2.2 remote−as 200
neighbor 2.2.2.2 route−map setweightin in
...
ip as−path access−list 5 permit ^100$
...
route−map setweightin permit 10
match as−path 5
set weight 200
!−− anything that applies to access−list 5, such as packets from AS100, have weight 200
route−map setweightin permit 20
set weight 100
!−− anything else would have weight 100