BGP Path Selection and Attributes

Master BGP path selection and attributes. Learn how BGP chooses the best route with detailed explanations, configuration examples, and FAQs for students.

Understanding how Border Gateway Protocol (BGP) selects the best path is crucial for anyone studying networking. Unlike Interior Gateway Protocols (IGPs) that rely on simple metrics like hop count or cost, BGP utilizes a comprehensive list of attributes to determine the optimal route to a destination. This detailed BGP Path Selection and Attributes process provides granular control over how traffic is routed across the internet.

What is BGP Path Selection?

When a BGP router learns about multiple paths to the same destination network (with the exact same prefix), it needs a method to decide which path is the best path. This decision-making process is known as BGP path selection. Only the selected best path will be installed into the router's main routing table, though all learned paths are stored in the BGP table.

BGP path selection follows a strict, ordered list of attributes. The router evaluates these attributes one by one, from top to bottom, until a tie-breaker is found. If one path has a better attribute according to the priority list, that path is chosen. If attributes are equal, BGP moves to the next attribute in the sequence.

The BGP Best Path Selection Algorithm: A Detailed Look

BGP's path selection algorithm involves a prioritized list of attributes. Here’s a breakdown of the attributes in their specific order:

  1. Weight: This is the first attribute BGP considers. It's a Cisco proprietary value, local to the router, and not exchanged between BGP neighbors. The path with the highest weight is preferred. Default weight for routes not originated by the local router is 0. A route originated by the router itself has a default weight of 32768.
  2. Local Preference: Used within an autonomous system (AS) and exchanged between iBGP routers. The path with the highest local preference is preferred. The default value is 100.
  3. Originate: BGP prefers the path that the local router originated. You'll typically see a next hop of 0.0.0.0 in the BGP table for such routes. These routes can be injected into BGP via the network command, redistribution, or aggregation.
  4. AS Path Length: The path with the shortest AS path length is preferred. For example, a path AS 1 2 3 is better than AS 1 2 3 4 5.
  5. Origin Code: BGP prefers the path with the lowest origin code. The codes are ordered: IGP (lowest) > EGP > INCOMPLETE (highest).
  6. MED (Multi-Exit Discriminator): The path with the lowest MED is preferred. MED is exchanged between autonomous systems to influence inbound traffic decisions.
  7. eBGP Path over iBGP Path: BGP prefers an eBGP (external BGP) path over an iBGP (internal BGP) path.
  8. Shortest IGP Path to BGP Next Hop: Within the autonomous system, BGP prefers the path with the lowest Interior Gateway Protocol (IGP) metric to reach the BGP next hop address.
  9. Oldest Path: If all other attributes are equal, BGP prefers the path that was received first (the oldest path).
  10. Router ID: BGP prefers the path with the lowest BGP neighbor router ID. The router ID is often based on the highest IP address (e.g., a loopback interface) or can be manually configured.
  11. Neighbor IP Address: As a final tie-breaker, especially if router IDs are the same (e.g., between two eBGP routers with multiple links), BGP prefers the path with the lowest neighbor IP address.

BGP Attributes in Action: The Weight Attribute

The Weight attribute is a prime example of how network administrators can influence BGP path selection. Since it's local to the router and Cisco proprietary, it offers a powerful way to steer traffic locally.

Consider a scenario where Router R1 in AS 1 can reach AS 3 via AS 2 or AS 4. If you want R1 to always use AS 2, you can assign a higher weight to paths learned from AS 2's neighbor.

Configuring Weight per Neighbor

You can set the weight for all prefixes learned from a specific neighbor. For example, on R1, to prefer paths from neighbor 192.168.13.3:

R1(config)# router bgp 1 R1(config-router)# neighbor 192.168.13.3 weight 500

After this configuration and a BGP clear, any prefixes received from 192.168.13.3 will have a weight of 500, making them preferred over paths with a default weight of 0.

Configuring Weight per Prefix using Route-Maps

For more granular control, route-maps allow you to set the weight for specific prefixes. Suppose you want to assign a weight of 400 only to network 22.22.22.0/24 from a neighbor.

  1. Remove existing weight configuration: R1(config-router)# no neighbor 192.168.13.3 weight 500
  2. Define an Access-List: R1(config)# access-list 1 permit 22.22.22.0 0.0.0.255
  3. Create a Route-Map: R1(config)# route-map SETWEIGHT permit 10 R1(config-route-map)# match ip address 1 R1(config-route-map)# set weight 400 R1(config-route-map)# exit R1(config)# route-map SETWEIGHT permit 20 (This permit statement ensures other prefixes are still processed with default weight 0 if not matched by permit 10) R1(config-route-map)# set weight 0 R1(config-route-map)# exit
  4. Apply Route-Map to Neighbor: R1(config-router)# neighbor 192.168.13.3 route-map SETWEIGHT in

This setup ensures only 22.22.22.0/24 receives a weight of 400, while other prefixes from 192.168.13.3 retain their default weight of 0.

BGP Table Symbols: Understanding Path Status

When examining a BGP table (e.g., show ip bgp), you'll encounter symbols that indicate the status of paths:

  • *: Indicates a valid path, meaning it's reachable and syntactically correct.
  • >: Designates the best path selected by BGP. This is the path that will be installed into the IP routing table.
  • i: Signifies an internal path, learned from an iBGP neighbor.

Exceptions to Standard BGP Path Selection

While the ordered list of attributes is fundamental, there are advanced BGP features that can modify or bypass parts of this process. These include:

  • Confederations: A way to break a large AS into smaller, more manageable sub-ASes.
  • Route Reflectors: Used to overcome the iBGP full-mesh requirement.
  • Multipath: Allows BGP to install multiple paths to the same destination in the routing table for load balancing.

Conclusion: Mastering BGP Path Selection for Network Control

Understanding BGP path selection and attributes is fundamental for managing traffic flow in complex, interconnected networks. By manipulating these attributes, network engineers can finely tune routing decisions, influencing how their autonomous system interacts with the global internet. This level of control is essential for ensuring optimal performance, redundancy, and policy enforcement.

Frequently Asked Questions about BGP Path Selection

What is the primary goal of BGP path selection?

The primary goal of BGP path selection is to determine the single best path among multiple available routes to a destination network. This best path is then installed into the IP routing table, enabling the router to forward traffic efficiently and according to configured policies, providing granular control beyond simple shortest-path metrics.

How does BGP path selection differ from IGP path selection?

BGP path selection differs significantly from IGP (Interior Gateway Protocol) path selection. IGPs like RIP, OSPF, or EIGRP typically base their best path decision on a simple metric (e.g., hop count for RIP, cost for OSPF) to find the shortest or cheapest path within a single autonomous system. BGP, on the other hand, uses a complex, ordered list of eleven attributes to make decisions, allowing for much more granular control over traffic engineering across multiple autonomous systems, prioritizing factors like administrative policy over just the shortest distance.

Is the Weight attribute exchanged between BGP routers?

No, the Weight attribute is strictly local to the router on which it is configured. It is a Cisco proprietary attribute and is not exchanged between BGP routers. This means that a router's Weight configuration only influences its own outbound path selection decisions, providing a local mechanism for traffic steering without affecting neighboring BGP devices.

What happens if all BGP attributes are identical for multiple paths?

If all BGP attributes are identical for multiple paths to the same destination, the BGP path selection process will use the neighbor's IP address as the final tie-breaker. It will prefer the path learned from the BGP neighbor with the lowest IP address. This ensures that even in highly symmetrical network designs, BGP can consistently select a single best path.

Can advanced BGP features influence path selection?

Yes, advanced BGP features can significantly influence or even override the standard BGP path selection process. Features like BGP confederations, route reflectors, and BGP multipath can alter how paths are considered, advertised, or even allow multiple paths to be installed in the routing table for load sharing. These features provide flexibility for complex network designs and specific traffic engineering requirements.

Related topics