BGP Path Attributes

AS_PATH, NEXT_HOP, LOCAL_PREF, and other BGP decision-making attributes.

Introduction: Beyond a Simple Metric

In the world of internal routing protocols like OSPF, a router鈥檚 life is relatively simple. It learns about different paths, calculates a single numerical value: the metric or cost, for each one, and chooses the path with the lowest number. The fastest route wins. This is perfect for a network under a single administrative control where speed and efficiency are the top priorities.

The global Internet, however, is a federation of thousands of independent networks, or . Here, the "best" path is rarely the fastest one. Routing decisions are not based on a single number but on a complex web of business relationships, financial agreements, and technical policies. The Border Gateway Protocol (BGP) is the protocol that manages these relationships. To make these complex decisions, BGP needs more than just a single metric. It needs a rich set of information about each route.

This is where BGP attributes come into play. Attributes are pieces of information, or properties, attached to a BGP route that describe its characteristics. They are the language of BGP, allowing network administrators to implement policies and influence how traffic flows into and out of their networks. Understanding these attributes is the key to understanding BGP itself.

The Four Categories of BGP Attributes

BGP attributes are not all created equal. They are classified into four categories based on how well-known they are and whether they must be passed along between routers.

Well-known Mandatory

These attributes must be understood by every BGP-speaking router and must be present in every BGP UPDATE message. They are the fundamental, non-negotiable properties of a route.

Analogy: The destination address on a letter. Without it, the letter is useless.

Examples: AS_PATH, ORIGIN, NEXT_HOP.

Well-known Discretionary

These attributes are also understood by all BGP routers, but they don't have to be included in every update. They are optional but universally recognized.

Analogy: A "Fragile" sticker on a package. The postal service understands it, but not every package needs one.

Example: LOCAL_PREFERENCE.

Optional Transitive

These attributes may not be understood by every router. If a router does not understand a transitive attribute, its duty is to accept it, mark it as a partial attribute, and pass it along unchanged to its BGP peers.

Analogy: A special company tracking code on an international package. The foreign postal service doesn't understand it but passes it on with the package.

Example: AGGREGATOR, COMMUNITY.

Optional Non-transitive

These attributes may not be understood by every router. If a router does not recognize a non-transitive attribute, it should simply ignore it and not pass it on to its peers.

Analogy: A handwritten note from one mail carrier to the next. If the next carrier can't read it, they just throw it away.

Example: MED (Multi-Exit Discriminator).

AS_PATH - The Mandatory Itinerary

The AS_PATH is the most critical of all BGP attributes. It is a Well-known Mandatory attribute that serves two vital functions: loop prevention and basic path selection.

Function 1: Loop Prevention

The AS_PATH is a list of all Autonomous System Numbers (ASNs) a route advertisement has traversed. As a router forwards an update to a peer in a different AS, it prepends (adds its own ASN to the beginning of) the list.

This creates a simple but foolproof mechanism for preventing routing loops on a global scale. The fundamental rule of BGP is: a router must discard any BGP update it receives if its own ASN is already present in the AS_PATH list. This ensures that a route advertisement can never loop back to an AS it has already passed through.

Function 2: Path Selection

In the absence of other policy configurations, the length of the AS_PATH serves as a primary metric for BGP. When a router has multiple valid paths to the same destination, it will prefer the one with the shortest AS_PATH.

Example: Shortest Path Wins

Router D needs to choose a path to Network X.

  • It receives a route from neighbor B with AS_PATH: (65002, 65001). The length is 2.
  • It receives a route from neighbor C with AS_PATH: (65003, 65005, 65004, 65001). The length is 4.

Because the path through B has a shorter AS_PATH (2 hops versus 4), Router D will choose it as the best path and install it in its routing table.

NEXT_HOP - The Immediate Direction

The NEXT_HOP is another Well-known Mandatory attribute. Its function is seemingly simple: it is the IP address of the next router that should be used to forward packets for the advertised destination. However, its behavior is subtly different in eBGP versus iBGP, a critical concept to understand.

NEXT_HOP in eBGP (External BGP)

When a router advertises a route to a peer in a different AS (an eBGP neighbor), the rule is simple: the advertising router sets the NEXT_HOP attribute to its own IP address on the interface connecting the two peers. It is essentially saying, "To reach this network, send your packets to me at this specific address."

NEXT_HOP in iBGP (Internal BGP)

This is where things get complicated. When a route learned from an eBGP neighbor is then advertised to an iBGP peer (a router within the same AS), the NEXT_HOP attribute is, by default, left unchanged.

Example: The Unreachable Next-Hop Problem

  1. The ISP's router (at IP 203.0.113.1203.0.113.1) sends an eBGP update to your company's Edge_Router (at IP 203.0.113.2203.0.113.2) for the network 8.8.8.0/248.8.8.0/24. The NEXT_HOP attribute in this update is 203.0.113.1203.0.113.1.
  2. Edge_Router now has a valid route. It forwards this information to its iBGP peer, Internal_Router.
  3. By default, Edge_Router does not change the NEXT_HOP. So, Internal_Router receives an update for 8.8.8.0/248.8.8.0/24 with the NEXT_HOP still set to 203.0.113.1203.0.113.1.
  4. Problem: Internal_Router is inside your company network. It has no direct connection to the ISP and likely has no route in its IGP (e.g., OSPF) table telling it how to reach the 203.0.113.1203.0.113.1 address. The NEXT_HOP is unreachable, and therefore, the entire route is unusable.
The Solution: Next-Hop-Self

The standard solution to this problem is to configure the Edge_Router to change the NEXT_HOP attribute for routes advertised to iBGP peers. The command, known as next-hop-self, tells the router: "When you advertise this route to an internal peer, set the NEXT_HOP address to your own internal IP address." This way, the internal routers receive a NEXT_HOP that they know how to reach via the internal network.

Other Key Attributes in Path Selection

Beyond AS_PATH and NEXT_HOP, several other attributes play crucial roles in BGP's sophisticated path selection process. They are the primary tools used by network administrators to implement routing policies.

ORIGIN (Well-known Mandatory)

The ORIGIN attribute is a simple but important piece of information indicating how a route was first injected into BGP. It serves as an early tie-breaker in path selection. There are three origin codes, listed in order of preference:

  • IGP (Code 0): The route originated from a `network` command within BGP on a router in the originating AS. This is considered the most reliable origin.
  • EGP (Code 1): The route was learned via the historic Exterior Gateway Protocol, BGP's predecessor. This is virtually never seen today.
  • INCOMPLETE (Code 2): The route was injected into BGP via . This is considered the least trustworthy origin because BGP has no information about the route's history before it was redistributed.

A router will always prefer a path with a lower ORIGIN code.

LOCAL_PREF (Well-known Discretionary)

LOCAL_PREFERENCE is the primary tool for influencing outbound traffic flow within a single AS. It is a numerical value that is only exchanged between iBGP peers; it is never sent to external neighbors.

The rule is simple: a higher LOCAL_PREF is more preferred. The default value is 100. By setting a higher local preference for routes learned from a preferred ISP, an administrator can ensure all routers within their AS will choose that ISP as the primary exit point.

MED (Optional Non-transitive)

The Multi-Exit Discriminator (MED) attribute is the primary tool for influencing inbound traffic from a neighboring AS. It acts as a suggestion to an adjacent AS about which of your network's entry points it should prefer.

The rule is the opposite of LOCAL_PREF: a lower MED value is more preferred. If an AS has two links to the same provider, it can advertise its routes with a lower MED on the primary link and a higher MED on the backup link. This tells the provider, "Please send traffic to me via this lower-cost path." However, as an optional attribute, the receiving AS is under no obligation to honor the MED.

    BGP Path Attributes | Teleinf Edu