Tuesday, September 4, 2012

BGP weight attribute manipulation for best path





In this example we will try to manipulate the path choice based on weight metric. We've four routers R1 in AS100, R2 in AS 200, R3 AS 300, R4 AS 400. All routers shares with each other directly connected neighbors and no static/dynamic routing protocol is used anywhere.
R1<>R2
R2<>R3
R3<>R4
R1<>R4
All of them are e-bgp neighbor-ship. 

Weight Attribute:
Weight by default comes up when you have a route originating from a local to AS router. So if your router R xyz has a route to be advertised by you and you use network 'i'-origin then by default a value of 32768 is assigned to it showing that route is directly originated from it and is most preferred with this value. Weight attribute matter only to a router in an AS and doesn't get transferred to other AS. 

Objective:

Router R4 learns about network 223.200.0.0 /16 from two source R1 and R3. It may choose either of them to be a preferred route to reach the former depending upon AS_PATH choice which remains same in count. 
In our case R4 choice by default is 

R4(config)#do sh ip bgp
BGP table version is 2, local router ID is 4.4.4.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network                Next Hop            Metric LocPrf Weight Path
*  223.200.0.0/16   3.3.3.1                                                     0 300 200 i
*>                              4.4.4.1                                                     0 100 200 i          //best path via R1

Observation:

R4(config)#do sh ip bgp sum
BGP router identifier 4.4.4.2, local AS number 400
BGP table version is 2, main routing table version 2
1 network entries using 101 bytes of memory
2 path entries using 96 bytes of memory
2 BGP path attribute entries using 120 bytes of memory
2 BGP AS-PATH entries using 48 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 365 total bytes of memory
BGP activity 1/0 prefixes, 2/0 paths, scan interval 60 secs

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
3.3.3.1         4       300      14      14                   2        0        0       00:09:20        1
4.4.4.1         4       100      15      14                   2        0        0       00:10:01        1

Solution a two way round:

1. We can use the neighbor sub command under router bgp 400 and give a weight attribute directly for that neighbor.
neighbor 3.3.3.1 weight 4096
Note: All routes from that member will then have same weight attribute. It is more of static hard route manipulation.

2.  We can do it dynamically for specific routes learned from particular ASes. For R4 we will add one more command:

 router bgp 400
 no synchronization
 bgp log-neighbor-changes
 neighbor 3.3.3.1 remote-as 300
 neighbor 3.3.3.1 route-map weight_change in      //by calling a route-map

        I.            Create a route map:
      II.            route-map weight_change permit 10
    III.            match ip address 101
    IV.            set weight 4096

      V.            Follow below ace;
    VI.            access-list 101 permit ip 223.200.0.0 0.0.255.255 any
  VII.            access-list 102 permit ip any any


 
3. One more way is to use AS_PATH in acl and allow specific AS only. This but doesn't achieve our target of dynamic choice of best path rather it only allow certain ASes as per the list.
On R4:

        I.            router bgp 400
      II.            no synchronization
    III.            bgp log-neighbor-changes
    IV.            neighbor 3.3.3.1 remote-as 300
      V.            neighbor 3.3.3.1 filter-list 2 weight 4096   //setting filter-list to filter AS with a weight set

    VI.            Use AS_PATH acl;
  VII.            ip as-path access-list 2 permit ^300            //300 is AS number of R3


Using all the above ideas one case make a path less/more preferred by a router local to an AS when it has more than one way to reach the destination.


Good luck!!

 

No comments: