BGP Weight Attribute

8
The BGP weight attribute is the first on the list in the BGP best path algorithm 1. 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.

description

BGP Attrubute manipulation

Transcript of BGP Weight Attribute

Page 1: BGP Weight Attribute

The BGP weight attribute is the first on the list in the BGP best path algorithm

1. 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.

Page 2: BGP Weight Attribute

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=1.1.1.1, R2=2.2.2.2

etc

All routers are peering with each other using eBGP

Page 3: BGP Weight Attribute

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 6.6.6.6/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 1.1.1.1

(loopback on R1) that the weight is 32768 this is because it is a locally generated route.

Page 4: BGP Weight Attribute

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.

1. Prefer the path with the highest Weight – Both Weights are equal so move onto

step2

2. Prefer the path with the highest Local Preference – Local preference is the same

for both routes

3. Prefer the path that was locally originated – Same for both

4. Prefer the path with lowest AS Path – Both routes have an AS path of 2

5. Prefer the path with the lowest origin type – Same for both

6. Prefer the path with the lowest MED – Skipped

7. Prefer eBGP over iBGP – both routes are eBGP

8. Prefer the path with the lowest IGP metric to the next BGP Hop – Same for both

9. Check if multipath is enabled – Skipped

10.When both paths are external prefer the oldest one – This is the tiebreaker!

BGP Best Path Algorithm from Cisco  

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.

Page 5: BGP Weight Attribute

Back to BGP weight! – we now want to ensure that whatever happens R1 will route

through R4 (10.0.14.4) to get to 6.6.6.6

To achieve that using weight we have two options.

1. Set the BGP Weight Attribute on the neighbor – this will affect all routes learnt

from that neighbor

2. 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

Page 6: BGP Weight Attribute

R1#

R1#sh run | sec router bgp

router bgp 1

bgp log-neighbor-changes

network 1.1.1.1 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.

Page 7: BGP Weight Attribute

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 6.6.6.6/32 prefix

First we need to match this prefix in an access list

R1(config)#access-l 1 permit 6.6.6.6 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

Page 8: BGP Weight Attribute

You can see now that we have changed the weight attribute for the 6.6.6.6/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