Tuesday, January 24, 2012

BGP LOCAL PREF ,LOCAL PREF WITH COMMUNITIES & AS PATH PREPENDING

BGP LOCAL PREFERENCE
--------------------
So local preference is the next in path selection after weight
local Pref affect AS wide and influence path selection for all routers
int the AS for the routes set
SO it is set on inbound control plane traffic (updates)
and will affect outbound dataplance traffic decisions
Highest is best
default value is 100

route-map FROM-BB1
set local-preference 101
router bgp 100
neighbor 54.28.1.254 route-map FROM-BB1 in

There is an option the most service providers or should give as of teh RFC 1998 Using
Communties for Local Preference. It basically details that service provider should on
recieving routes with the community of
any of the following 
"SP AS" : 70
"SP:AS" : 80
"SP:AS" :90     
you should the local pref for that route to 70,80 or 90 depending on which was recieved.
So this would influence return path to my AS

Communties are transitive so this is a good option for influencing as it will be passed AS
to AS

Another option for influencing how network get to you could be set AS Path Prepending
i.e in update set your AS multiple times making the AS path longer + less desirable
route-map TO-R2
set as-path prepend 300 300 300 300
router bgp 300
neighbor 155.28.23.2 route-map TO-R2 out

LAB
---

OK for the lab same scenerio as last lab. BB1 is advertising 11.1.1.1 r1 is recieving
11.1.1.1 from both r6 and r4. The path selection is tied right up till metric to next hop
and it selects r4 as it has shorter metric to the next hop on bb3 then the next hop on bb1
we want to influence all router in the AS to take the router 6 path rather than the r4 path

r1
--
r1#sh ip bgp
BGP table version is 16, local router ID is 1.1.1.1
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
*>i11.1.1.1/32      172.25.13.3              0    100      0 54 i
* i                 10.229.254.1             0    100      0 54 i
r1#

we see it is using next hop of bb3 for the best route

r6
---
ok on r6

we create a route map setting local-pref 110
r6(config)#route-map LOCAL permit 10
r6(config-route-map)#set local-pref 110
r6(config-route-map)#exit

then on router bgp for the neighbor relationship to bb1 we say for routes coming in from
this neighbor set the local preference. We set it coming in to affect the dataplane traffic
going out
r6(config)#router bgp 100
r6(config-router)#neighbor 10.229.254.1 route-map LOCAL in
r6(config-router)#

on r6
r6#sh ip bgp
BGP table version is 2, local router ID is 6.6.6.6
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
*> 11.1.1.1/32      10.229.254.1             0    110      0 54 i
r6#

we see the local pref has changed to 110

we are recieving both routes one from r6 the other from bb2
r4#sh ip bgp
BGP table version is 3, local router ID is 4.4.4.4
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
*>i11.1.1.1/32      10.229.254.1             0    110      0 54 i
*                   172.25.13.3                            0 54 i
r4#

we are selecting the r6 as of the local preference

on r1
r1#sh ip bgp
BGP table version is 17, local router ID is 1.1.1.1
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
*>i11.1.1.1/32      10.229.254.1             0    110      0 54 i
r1#

we only get the one route as r4 is not sending the route via bb3 as it has not choosen that
as the best route
OK i will do quick lab on local preference affect incoming taffic through the use of
communities

so r5  AS 400 has ebgp connections to r4 and r1 in AS 100

r5#sh ip bg
*Jan 24 21:41:14.559: %SYS-5-CONFIG_I: Configured from console by consolep
BGP table version is 113, local router ID is 5.5.5.5
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
*  11.1.1.1/32      4.4.4.4                                0 100 54 i
*                   3.3.3.3                                0 300 100 54 i
*>                  1.1.1.1                                0 100 54 i
r5#

On r5 currently we are choosing 1.1.1.1 r1 as entry to AS 100 to get to AS 54
we want to use local prefernce to influence it onto r4 with communities

so on r5
---------
we specify the community list
r5(config)#ip community-list 1 permit 500:120
r5(config)#route-map MATCH
r5(config-route-map)#match community 1
r5(config-route-map)#set local-pref 120

so we have a route map matching community 1 which is 500:120 if that is present we will sent
the local preference

r5(config)#router bgp 400
r5(config-router)#neighbor 4.4.4.4 route-map MATCH in
r5(config-router)#
we have applieds for route from r4

r4
---

OK we have create a route-map in r4 setting the community to 500:120
r4(config)#route-map SET
r4(config-route-map)#set community 500:120

r4(config)#router bgp 100
r4(config-router)#neighbor 5.5.5.5 route-map SET out
r4(config-router)#neighbor 5.5.5.5 send-community
so we apply the route-map to neighbor 5..5.5.5 in the outbound direction


r5
---
r5#sh ip bg
*Jan 24 22:02:35.903: %SYS-5-CONFIG_I: Configured from console by consolep
BGP table version is 3, local router ID is 5.5.5.5
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
*> 11.1.1.1/32      4.4.4.4                       120      0 100 54 i
*                   1.1.1.1                                0 100 54 i
*                   3.3.3.3                                0 300 100 54 i

we are now choosing the via r4 as the local preference is 120

ANother way we could do this is by using the AS Path Prepending

I have defaulted it back

r5#sh ip bgp
BGP table version is 2, local router ID is 5.5.5.5
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
*  11.1.1.1/32      4.4.4.4                                0 100 54 i
*>                  1.1.1.1                                0 100 54 i
*                   3.3.3.3                                0 300 100 54 i
r5#

ok we will do this from r1


r1
---
r1(config)#route-map ASPATH permit 10
r1(config-route-map)#set as-path prepend 100 100 100

ok for r1 i have created a route-map setting AS-Path to an extra 3 AS's

r1(config)#router bgp 100
r1(config-router)#neighbor 5.5.5.5 route-map ASPATH out
r1(config-router)#

so i have set the ASPATH out outbound to affect the incoming taffic path

r5#sh ip bgp
BGP table version is 3, local router ID is 5.5.5.5
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
*  11.1.1.1/32      1.1.1.1                                0 100 100 100 100 54 i
*>                  4.4.4.4                                0 100 54 i

we are seeing now r1 is sending AS path of 5 compared to r4 which is 2 so no r4 is the
preference/







No comments:

Post a Comment