BGPLocal Preference – Enforcing Policies

bgp local preferencesBGP is the established inter-domain routing protocol of the Internet. It was designed specifically for routing and managing large scale interconnecting autonomous systems (AS). What makes BGP so suited to the Internet today is not just its robust nature and wealth of configuration controls, but its ability to suggest and apply policy. Without policy BGP would simply be another distance vector protocol that counted hops (AS) to the destination network. BGP does not just simply compare the lengths of paths it learns. It applies policies against the attributes sent within the routing updates to determine the best path. BGP is a path vector protocol that compares attributes when determining the best route and it favors policy over proximity.

Learn more about BGP and routing by taking a course at Udemy.com

So how does BGP compare attributes, and what are these attributes sent in the routing updates? To understand attributes, you must understand how the BGP routing protocol differs from other routing protocols. BGP is an external routing protocol designed to work by connecting private domains or autonomous systems (AS). An AS is considered a network under a common administrative control. The key point here is that these AS systems are private, so the conventional interior network protocols such as RIP or OSPF are automatically discovered and peered with. Neighboring hosts have to agree to form mutual manual configuration, and this is what BGP requires. Additionally, unlike interior routing protocols where full disclosure of peers’ routing tables is desirable, external AS peers do not work in the same way. There must be methods to filter and exclude routes from updates. BGP facilitates this through BGP policies.

Learn more about routing protocols by taking a class at Udemy.com

BGP Policies   

BGP applies or suggests policies by using attributes, which it assigns to the AS path that it advertises. The AS path is a list of AS addresses, which have to be followed in order to get to a destination network. If BGP only used the length of the AS path to determine the best path to take, it would be simply a distant vector protocol but BGP does not do this. BGP compares routes against a list of policies when determining the best path to offer.

The steps BGP takes when comparing a route are:

  1. Ignore any route whose next-hop is unobtainable
  2. Local Preference
  3. Select self sourced routes
  4. Select shortest AS path

You can see from the list that the highest priority is not the length of the AS path but the attribute setting local preference. BGP first compares the local preference, and if one route has a higher setting, then it wins and the process halts there. No further comparisons are considered. Therefore, a route with a higher local preference will prevail over a route with a shorter AS path.

An administrator can configure the AS to be higher than the default setting of 100 when advertising the network routes as a suggestion of their preference in the desire to influence the routing decision made by other BGP routers. The local preference is the local administrators preferred route, which he would like other systems to use. Its importance is in that BGP works within an AS, which are private, so it is a way for an administrator to enforce their routing policy throughout the AS, without having to go about configuring every router. Therefore, in order to make one route more acceptable than another, the local preference field is set to a higher value than the default setting of 100. This is particularly useful when used within an AS. This is because internal BGP routers have some other BGP rules that they follow, one of which is to try to use the nearest gateway when comparing routes. The administrator can define the particular route to use to get to a specific location such as an Internet Gateway in order to over-rule that behavior.

The local preference value on a router is configured from the command line:

bgp default local-preference <value>

This is not advisable as all routers in an AS should have the same local preference setting or things can get unmanageable very quickly. It is advisable to state the BGP policy in one place, rather than have bits and pieces configured here and there. The tool bag of instruments used to collate and apply policies is a route map. By setting the policy out within a route map and configuring the specific attribute values within the route-map, applying, editing and troubleshooting a policy is easier.

Route-Maps

Route-maps as described above are a collection of individual policy instruments used to match on certain attributes of a route and set others. An administrator typically applies route filtering using route-maps based on multiple attributes. Local preference being an attribute is set in a route-map, where the administrator matches a route and then configures that route’s local preference. An example of how to set the local preference of a route is shown below:

route-map testmap permit 10

! matches prefixes against access list 10

match ip address 10

! matches prefixes against the interface through which the BGP peer is reachable

match interface FastEthernet0/0

! sets the Local Preference value of 100

set local preference 100

Applying Local Preference in Practice

When applying a local preference within an AS, a common application is when a network is dual homed to different ISPs. For example, take an ISP A & B. The network administrator wishes to apply a policy that determines which ISP is preferable. In this situation, the iBGP routers in the network will follow the general rule of using the closest gateway. This may not be desirable as they may use the more expensive or for whatever reason the less desirable ISP. Therefore, the administrator wishes to set routes advertised from ISP B as having a higher local preference. By setting the routes advertised from ISP B’s eBGP gateway router with a higher local preference, then the other iBGP routers receiving the routing updates will compare the similar routes coming from ISP A & ISP B and prefer ISP B.

Want to know more about BGP? Take a course at Udemy.com