O'Reilly Book Excerpts: BGP
Traffic Engineering: Local Routing Policy
Setting the Local Preference
The easiest and most effective way to influence the BGP path selection process is to adjust the Local Preference. This works well when certain routes are always better than others, for instance:
- Routes over the main connection are preferred over routes that use a slower backup connection.
- Routes from peering connections are preferred over routes from transit connections.
- Routes directly to customers are preferred over external routes.
Example 6-2 shows part of a BGP configuration where the routes received from both peers receive different Local Preference values.
Example 6-2: Setting the Local Preference for all routes received from a BGP neighbor
! router bgp 60055 neighbor 220.127.116.11 remote-as 40077 neighbor 18.104.22.168 route-map ispa-in in neighbor 22.214.171.124 remote-as 50066 neighbor 126.96.36.199 route-map ispb-in in ! route-map ispa-in permit 10 set local-preference 90 ! route-map ispb-in permit 10 set local-preference 110 !
In This Series
Traffic Engineering: Queuing, Traffic Shaping, and Policing
Traffic Engineering: Finding the Right Route
The permit keyword in the route-map statement means matched routes will be permitted to enter the BGP table or be propagated to the neighbor; a deny route map will filter out all routes matching the match clause. The number 10 is the sequence number, used to apply the different route maps with the same tag in the right sequence. In this case, there is only one route map for each tag (
ispb-in), so the sequence number doesn't do anything.
Since we want to match all routes, there is no need to supply a match clause for the route maps. Both route maps just use a set clause to set the Local Preference for every route that is received from the respective neighbor. This has the effect that if ISP B has a route to a destination, this route will always be preferred over the route ISP A has to the same destination. Routes from ISP A will be used only if there is no matching route over ISP B. This would be a good routing policy if traffic over ISP B is a lot cheaper than traffic over ISP A. Example 6-3 shows the BGP table after applying the route maps.
Example 6-3: Partial BGP table with different Local Preferences
BR1#show ip bgp BGP table version is 619734, local router ID is 188.8.131.52 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Path * 184.108.40.206/19 220.127.116.11 90 40077 397 i *> 18.104.22.168 110 50066 5703 397 i * 22.214.171.124/16 126.96.36.199 90 40077 30021 i *> 188.8.131.52 110 50066 30021 i * 184.108.40.206/20 220.127.116.11 90 40077 5930 1070 i *> 18.104.22.168 110 50066 1070 i
Under normal circumstances, the router would choose the route over AS 40077 for network
22.214.171.124/19 because the path over AS 50066 is longer. The higher Local Preference has precedence over the AS path length, however, so the route over ISP B is selected, as indicated with a
> character. For
126.96.36.199/16, the AS path is the same length, so under other circumstances the decision would have come down to the tie- breaking rules. And for
188.8.131.52/20, the higher Local Preference doesn't really make a difference, because the route over AS 50066 has a shorter path anyway.
This policy works well as long as ISP B provides good connectivity to all destinations on the Net. But maybe ISP B peers with AS 30088 over a heavily congested connection, as shown in Figure 6-2.
Figure 6-2. The congestion between ISP B and AS 30088
In this case, routes that traverse AS 30088 should be avoided. This is accomplished in Example 6-4.
Example 6-4: Setting the Local Preference depending on AS path
! ip as-path access-list 4 permit _30088_ ip as-path access-list 4 deny .* ! route-map ispa-in permit 10 set local-preference 90 ! route-map ispb-in permit 10 match as-path 4 set local-preference 80 ! route-map ispb-in permit 20 set local-preference 110 !
The route map
ispb-in permit 10 uses a match clause pointing to AS path access list 4 to find all routes with AS number 30088 in their AS path. The underscore characters before and after the AS number match a space, and the beginning or the end of the path. For a five-digit AS number, this doesn't make a difference, but the regular expression "3008" not only matches paths with AS number 3008 in it, but also with AS numbers such as 13008, 30080, 30081 and so on.
The routes received from ISP B that match AS path access list 4 are assigned a Local Preference value of 80. Routes not matching AS path access list 4 will be evaluated by the
ispb-in permit 20 route map. There, they are always matched and assigned a Local Preference of 110.
Example 6-5 shows the result of applying these route maps for a route to a customer of AS 30088. Under normal circumstances, the second route would have been chosen because the path is shorter, but the modified Local Preference values make sure the first route is used.
Example 6-5: The result of Local Preference manipulation
BR1#show ip bgp 184.108.40.206 BGP routing table entry for 220.127.116.11/20, version 239188 Paths: (2 available, best #1) Not advertised to any peer 40077 1800 30088 20099 18.104.22.168 from 22.214.171.124 (126.96.36.199) Origin IGP, metric 20, localpref 90, valid, external, best, ref 2 50066 30088 20099 188.8.131.52 from 184.108.40.206 (220.127.116.11) Origin IGP, localpref 80, valid, external, ref 2
Pages: 1, 2