BGP Path Attributes: Your BGP Path Selection Master Guide

The BGP path attributes and the BGP path selection refer to the BGP router’s process of examining the competing BGP paths (routes) or NLRIs (Network Layer Reachability Information) in its BGP table. The goal is to choose one route as the best route for each prefix (destination subnet).

The path attribute is the route metric in IGP routing protocols (EIGRP, OSPF, and IS-IS). All routes passing the same path (set of routers connected interfaces) will have the same route metric (cost in OSPF and distance in EIGRP). On the other hand, BGP has a different approach, where each prefix (NLRI in BGP terms) has its own BGP path attributes.

In this article, we will dig deep into the BGP path attributes and BGP path selection process, explaining how BGP selects the path to the destination prefix. Let’s dive deep into the world of BGP!

What is The BGP Path Attribute?


A BGP Path Attribute (PA) defines some facts about a particular route (path) through a network. Each PA defines something different about that path for a particular prefix (NLRI).

BGP automatically considers the first received path as the best path. When the BGP router receives additional paths, it compares the newer paths against the current best path. If there is a tie, processing continues onto the next step until it identifies the best path winner.

If one of the sequential path attributes comparison steps determines the best route, the comparison for that route stops.

After choosing a single BGP best path for a specific route (prefix), the BGP router will do the following:

  • Advertise the route to other BGP peers if no BGP filter prevents that.
  • Install the route in the routing table (RIB) if there is no better AD from another source.

The BGP router recalculates the best path for a prefix due to four possible events:

  • BGP next-hop reachability change (BGP route next hop is unreachable!).
  • Failure of an interface connected to an eBGP peer (eBGP peer flapping).
  • Reception of new paths for a route.
  • Redistribution change.

BGP Path Attributes Summary

For a quick reference, the table below shows the primary BGP path attributes used in the BGP path selection:

StepMnemonicShort PhraseWhich value is better?
0NNext hopThe next hop should be reachable, otherwise, the BGP router can NOT use the route
1WWeightBigger (it is not a BGP PA, but a Cisco-proprietary feature)
2LLOCAL_PREFBigger
3LLocally injected RoutesLocally injected routes are better than iBGP or eBGP learned routes.
4AAS_PATH lengthShorter AS path length is better
5OOriginPrefer routes with origin ‘i‘ over ‘e‘ and prefer ‘e‘ over’?
6MMEDSmaller
7NNeighbor TypeeBGP is better than iBGP
8IIGP metric to reach the Next hopSmaller
– – – – – – – – – – – – – –At this stage, Multipath will be considered if configured
9N/AOldest External (eBGP)When both paths are external, prefer the first path (the older one)
10N/ABGP Router ID (RID)The path with the lowest BGP RID is preferred
11N/ACLUSTER_LISTPrefer the route with the minimum CLUSTER_LIST length
12N/ANeighbor AddressPrefer the path that is received from the lowest neighbor address (configured using neighbor ip-address command)

BGP Path Attributes in The BGP Table

The BGP table contains various path attributes for each route, providing crucial information about the BGP routes. The figure below shows the BGP table with the BGP PAs listed.

A screenshot of a BGP routing table. It includes columns for Neighbor Type, Network, Next Hop, Metric, LocPrf, Weight, Path, and Origin. Specific entries show IPs like 192.168.2.1/32 with various metrics and statuses, highlighting details like locally injected and the command to check the next hop IP address.
A screenshot of a BGP routing table shows the BGP PAs.

The output below shows the detailed output of the BGP table. Note that the BGP PAs are equal till step 10 (Router ID).

A show bgp ipv4 unicast 192.168.5.5/32 output, displays BGP routing information for IP 192.168.5.5/32. Two path entries are shown. The first path entry, highlighted in red, is the best path. The second path entry, in blue, is not the best path because the RID is bigger.

BGP Path Attributes Classification

BGP path attributes are information associated with routing updates. They help BGP routers decide the best path to reach a destination network. The BGP attributes are classified into four categories:

BGP Path attributes (PAs) classification flowchart; the PAs splits into Well-known and optional. Well-Known: splits into Mandatory and Discretionary. Optional: splits into Transitive and Nontransitive. The respective attributes listed as follows: - Well-Known Mandatory: Next-hop, AS-Path and Origin. - Well-Known Discretionary: Local_Pref, Atomic_Aggregate. - Optional Transitive: Aggregator, Community. - Optional Non-transitive: MED, Originatior_ID, Cluster_List.
BGP Path Attribute Main Classification

  • Well-known Mandatory:
    • Must be recognized by all BGP routers.
    • Must be included in every BGP Update message.
    • Routing information errors occur without these attributes.
    • Example: NEXT_HOP, AS_PATH & ORIGIN.
  • Well-known Discretionary:
    • If it exists, all BGP routers will recognize it.
    • It will be included in every BGP update message if needed.
    • Examples: LOCAL_PREF, ATOMIC_AGGREGATE1 (Used for route aggregation).
  • Optional Transitive:
    • BGP routers may recognize it, which will be included in the BGP Update messages.
    • It carried from one AS (BGP Autonomous System) to another AS.
    • A BGP router not supporting this attribute can still receive routes with this attribute and advertise them to other peers.
    • Examples: AGGREGATOR2, COMMUNITY3.
  • Optional Non-transitive:
    • Influence only the routing policy within the AS.
    • If a BGP router does not support this attribute, it will not advertise routes with this attribute.
    • Examples: MED, ORIGINATOR_ID4, CLUSTER_LIST5.

Note: Not all BGP path attributes mentioned above are used in the BGP path selection process (mentioned in the table)!

BGP Inbound & Outbound Route Policies

The BGP best path selection algorithm influences how traffic enters or leaves the BGP autonomous system (AS); for a better understanding, we need to talk about the policy enforcement direction:

  • Inbound routing policy affects outbound traffic.
  • Outbound routing policy affects inbound traffic.

BGP path attribute value is modified (set) upon route reception (inbound policy) or route advertisement (outbound policy). We call it the BGP route policy and we use it to influence BGP’s local or neighboring AS routing.

For instance, as shown in the figure below, from the perspective of ASN 100, we assigned a BGP path attribute (PA) to the routes received from ASN 200 (setting the policy inbound). This influences the BGP router’s decision in ASN 100 for reaching subnet x (outbound traffic), causing routers in ASN 100 to favor the path through Router-D.

A network diagram with routers A, B, and C in BGP AS 100, and routers D and E in BGP AS 200. Red arrows show inbound policy updates from ASN 200 to ASN 100 for route x. The blue arrow indicates the best BGP path attribute to reach subnet x. Subnet x is marked in the top right in ASN 200.
BGP Inbound Routing Policy for Outbound Traffic (ASN 100 Perspective).

In the example in the figure below, from the perspective of ASN 100, we assigned a BGP path attribute (PA) to the routes advertised to ASN 200 (setting the policy outbound). This influences the BGP router’s decision in ASN 200 for reaching subnet y (inbound traffic), causing routers in ASN 200 to favor the path through Router-C.

A network diagram with routers A, B, and C in BGP AS 100, and routers D and E in BGP AS 200. Red arrows show outbound policy updates from ASN 100 to ASN 200 for route y in ASN 100. The blue arrow indicates the best BGP path attribute to reach subnet y from Router-E in ASN 200 towards Router-C in ASN 100. Subnet y is marked in the bottom in ASN 100.
BGP Outbound Routing Policy for Inbound Traffic (ASN 100 Perspective).

So, a basic rule for traffic engineering with BGP; is that BGP PA modifications in outbound routing policies influence inbound traffic, and BGP PA modifications to inbound routing policies influence outbound traffic.

The figure below shows the BGP PAs that engineers typically use to deploy traffic engineering and manage the BGP traffic paths in the inbound and outbound directions.

9 letters represent Illustration showing two popular methods to influence inbound and outbound BGP routes: "W", "L", "A" for outbound and "A" ,"M" for inbound. "W" stands for Weight "L" stands for Local Preference "A" stands for AS path length "M" stands for Multi-exit Discriminator.
Popular BGP Path Attributes for Inbound and Outbound Routes

  • Notes:
    • The BGP path selection process always considers the BGP PAs sequentially (steps 0 – 12), as mentioned in the table above, regardless of the BGP PA values we set for traffic engineering.
    • The BGP path attribute (PA) set or modification is configured using the route-maps under the BGP process.

BGP Path Attributes (Deep Dive)

In this section, we will dig deep into each BGP path attribute that contributes to the BGP path selection process. Again, we don’t consider all BGP path attributes for the BGP path selection process. Only the one I mentioned in the table (steps 0 – 12).

[Step 0] (N) Next Hop

When receiving a BGP update, the BGP router knows the next hop but not the outgoing interface! (This is how BGP works, right?). So, a routing protocol (IGP) or static routing must be able to perform a recursion routing lookup; otherwise, the route cannot be used.

If the router does not have a matching IP route for the BGP route’s Next_Hop IP address, the router will not know how to forward packets for that prefix using that BGP route.

To avoid this issue, at Step 0, the BGP best path algorithm (BGP Path Selection Process) removes such routes from consideration (Routes with no route to the next hop address).

Below is the default next-hop behavior according to the BGP neighbor type:

Neighbor TypeDefault Action for Advertised RoutesBGP Neighbor Command to Change The Default
iBGPDo NOT change the next hopnext-hop-self
eBGPChange the next hop to the address of the update-source x.x.x.x command.next-hop-unchanged

[Step 1] (W) Weight

The Weight value that we configure on a single BGP router can influence only that router’s path decision because the Weight cannot be communicated to other BGP peers.

When a router receives a BGP update, it can set the Weight value selectively per route using a route-map or for all routes learned from a single neighbor using a weight command.

The router’s best path algorithm examines the Weight of competing routes, choosing the route with the bigger Weight. However, the Weight cannot be learned in a received update (Weight is not a BGP PA).

The weight is set with inbound direction policy, to influence outbound traffic.

Below is the summary of the Weight features for Cisco routers and switches:

FeatureDescription
Is it a BGP PA?No; Cisco-proprietary feature
PurposeIdentifies a single router’s best route
ScopeIn a single router only
Default Value0 for learned routes, 32768 for locally injected routes
Changing the defaultsNot supported
Value Range0 through 65535
Which is best?Bigger value is better
ConfigurationThrough the route-map under the neighbor’s address-family with ‘in’ direction command or using weight command for a specific neighbor.

[Step 2] (L) Local Preference

The BGP Local Preference (Local_Pref) gives the routers inside a single BGP AS a value they can set per route and advertise to all iBGP routers inside the AS. So that all routers in the AS agree on which router is the best exit point for packets destined to that prefix.

Diagram of a network topology with routers R1, R2, R3, and R4. R1 and Prefix A within BGP AS100. R2, R3, R4 are in BGP AS200. Solid line from R1 to R2 and R3, dashed line from R2 to R4 and R3 representing the chosen path. Labels show local preference: 100 for R2 and 200 for R3, both connected to Prefix A.
BGP Local_Pref PA Example

Updates from eBGP peers do not include the Local_Pref PA value. By default, Cisco routers put a null value to Local_Pref for eBGP learned routes.

Below is the summary of the Local Preference features for Cisco routers and switches:

FeatureDescription
Is it a BGP PA?Yes, well-known, discretionary
PurposeIdentifies the best exit point from the AS to reach the prefix (NLRI)
ScopeThroughout the AS in which it was set (including confederation Sub Autonomous Systems)
Default Value100 for iBGP and Null for eBGP updates
Changing the defaultsNot supported
Value Range0 through 4,294,967,295
Which is best?Bigger value is better
ConfigurationThrough the route-map under the neighbor’s address-family with ‘in’ direction command.

[Step 3] (L) Locally Injected

Step 3 in the BGP path selection, BGP compares the source from which the routes were added to the BGP table.

When the BGP best path algorithm compares two routes in this step, if one was injected into BGP locally and the other was learned from a BGP peer (iBGP or eBGP), the BGP router chooses the route injected locally.

There are several ways to locally inject BGP routes, such as the network, redistribute, and aggregate commands.

  • Notes:
    • By default, locally injected routes will have a weight value of 32768.
    • When the BGP router injects a route to its BGP table, the router will NOT set AS_PATH or Next-hop values for that route.

[Step 4] (A) AS Path

The Autonomous System Path Length (AS_PATH) is a well-known mandatory attribute that uses a sequence of ASNs to describe the inter-AS route of the destination prefix.

When a BGP router originates a BGP route, its ASN is added to the AS_PATH. Then, as subsequent BGP speakers advertise the route to external peers, they prepend their ASN to the AS_PATH.

Diagram showing a network route with four ASes labeled ASa, ASb, ASc, and ASd. Arrows indicate path direction: from ASa to ASb, ASb to ASc, and ASc to ASd. Prefix P reached ASd with the AS_PATH: ASc ASb ASa.
BGP AS path includes all ASes the Prefix Passed Through


The result is that the AS_PATH describes all the ASes it has passed through, beginning with the most recent AS (the neighboring AS) and ending with the originating AS.

Due to BGP aggregation and confederation features, the AS_PATH attribute has the following components described in the table below:

ComponentDescriptionExample
AS_SEQAn ordered list of ASNs through which the route has been advertised. Used to prevent BGP loops and in path selection, influenced using AS_PATH pretending (inbound or outbound)100 200 300
AS_SETAn unordered list of ASNs through which the route has been advertised. Used when doing summarization (aggregation) to prevent routing loops{100, 300, 200}
AS_CONFED_SEQLike AS_SEQ but holds only confederation ASNs. Used to prevent BGP loops inside a real AS when using confederation but not inside sub-AS(65001 65002 65003)
AS_CONFED_SETLike AS_SET, but holds only confederation ASNs. Used when doing summarization (aggregation) inside confederations.{65001 65002 65003}

Step 4 in the BGP path selection, the smaller the AS_PATH length, the better the route.

The AS_PATH prepend mechanism allows us to increase the AS_PATH length by adding ASNs to it, making the route less preferable. By adding ASNs that already exist in a particular route’s AS_PATH, the feature will not affect the AS_PATH loop prevention mechanism.

A network diagram shows four square nodes representing BGP AS. Labeled ASa, ASb, ASc, and ASd. Red arrows indicate routes from ASa to ASc and ASd, and from ASc to ASd. A blue arrow marked Preferred Route points from ASb to ASc. Path labels include ASa, ASb, and ASd.
Prepending AS path to influence Route Decision


We can configure the AS_PATH prepending using the neighbor route-map command in either direction (in/out), the route map should have the set as-path prepend command.

[Step 5] (O) Origin

ORIGIN is a well-known mandatory attribute that specifies the origin of the routing update. The three Origin values are IGP (i), EGP (e), and incomplete (?)

  • IGP (i): The route was learned from an internal protocol to the originating AS, including static routes and connected interfaces. The BGP router assigns the origin of IGP if the route is injected into BGP via network command.

    EGP (e): The route was learned from the Exterior Gateway Protocol. Due to EGP being obsolete, you should never encounter this origin type.

  • Incomplete (?): The route was learned by some other means and there is no way to determine the original source of the route. Routes that BGP learns through the redistribute command will carry the incomplete origin attribute.

Although the original intent of the Origin PA is to identify the source from which BGP learned the route, we can also set the Origin PA as part of the best path algorithm to influence the BGP’s best path.

Step 5 in the BGP path selection process, IGP (i) > EGP (e) > incomplete (?)

Although the earlier steps in the BGP selection process (steps 1-4) are typically better for configuring BGP policies. BGP routing policies can set the ORIGIN value explicitly by using the set origin route-map subcommand.

[Step 6] (M) MED

The Multi Exit Discriminator (MED) is an optional nontransitive BGP attribute we use to influence routing decisions in neighboring ASes. In other words, we use the MED to tell the neighboring AS how to reach routes through the local AS.

When a BGP router learns a route from an external peer, it can pass the route’s MED to any iBGP peers. However, a router cannot advertise a MED that originated in a neighboring AS to a peer in another AS.

The MED is known as the external metric and is labeled as a “metric” in the BGP table. Also, it is shown in the IP routing table as the BGP route’s metric.

In step 6 in the BGP path selection process, the MED can be set in an outbound route map by a BGP router in one AS to influence the BGP decision process in another AS.

By default, MED is used for dual-homed designs. So, if the same route is advertised by external peers in different ASes, the MED value for those routes is ignored. However, the bestpath always-compare-med command overrides the default to consider MED values in all cases (including eBGP routes from different ASes).

Below is the summary of the MED features for Cisco routers and switches:

FeatureDescription
Is it a BGP PA?Yes, optional nontransitive
PurposeAllows an AS to tell a neighboring AS the best way to forward packets into the first AS
ScopeAdvertised by one AS into another, propagated inside the AS but no sent to any other ASes
Default Valuenot set (Null)
Changing the defaultsUsing the bestpath med missing-as-worst BGP subcommand; sets it to the maximum value.
Value Range0 through 4,294,967,295
Which is best?Smaller value is better
ConfigurationThrough the neighbor route-map out command, using the set metric command inside the route map. Or use set metric-type internal to link the MED value to the IGP metric of the route’s next hop.

[Step 7] (N) Neighbor Type

In step 7 in the BGP path selection process, BGP prefers the external route (eBGP) over the internal route (iBGP).

Having eBGP routes preferred over iBGP routes makes sense. Because the BGP protocol was originally a replacement for the Exterior Gateway Protocol (EGP), which takes care of external routes. And it should keep the internal routes for IGP protocols. So. The router relies more on IGP protocols like OSPF to learn the internal routes.

Below is the summary of the iBGP vs. eBGP differences:

FeatureeBGPiBGP
Neighboring peer’s ASNDifferentSame
Route’s Administrative Distance (AD)20200
Default next hop changeChange to local IP addressNo change
Default TTL in BGP messagesTTL = 1TTL = 255
Default LOCAL_PREF valueNULL100
Loop prevention ruleDon’t accept a route if it contains the local ASNDon’t send iBGP routes to iBGP neighbors
Append the local ASN in the AS_PATH when send the BGP updateYesNo

[Step 8] (I) IGP Metric to Next-hop

In step 8 in the BGP path selection process, the BGP router compares the metrics of the routes for each Next-Hop IP address and chooses the BGP route with the lower metric.

If an IGP-learned route is not used, for example, if both use connected routes, BGP considers the metrics to tie.

[Steps 9-12] Tie Breakers

If the BGP router couldn’t find the best route for a particular prefix (NLRI) after applying the steps (0 – 8), multiple routes tie for being the best route.

At this point, BGP needs to make two decisions:

  • First: Which route is the best? (only one route can be the best route at any time)
  • Second: Should multiple BGP routes for that prefix (NLRI) be added to the routing table?

BGP includes the following tiebreakers:

  • Step 9: Prefer the Oldest eBGP Route.
  • Step 10: Prefer the Smallest Neighbor Router ID (RID).
  • Step 11: Prefer the route with the Shortest Cluster-List.
  • Step 12: Prefer the route with the Smallest neighbor address.

Step 9 ensures the stable eBGP route is preferred, note that here we don’t talk about the oldest eBGP neighbor!

Also, note that steps 11 and 12 won’t be used unless we have two or more BGP neighborships with the same BGP router as each BGP router has a unique Router ID (RID).

BGP Path Attributes LABs

The most used BGP path attributes for traffic engineering are the LOCAL_PREF, AS_PATH and the MED. The following are LAB Demo for each BGP PA:

BGP LOCAL_PREF LAB Demo


BGP AS_PATH LAB Demo


BGP MED LAB Demo

Need Comprehensive BGP Content?

I hope this article was helpful. If you want comprehensive content about BGP, check out my Cisco Data Centers | MP-BGP course on Udemy.

  1. ATOMIC_AGGREGATE: A BGP path attribute that is used for route aggregation. ↩︎
  2. AGGREGATOR: lists the RID and ASN of the BGP router that created the summary route ↩︎
  3. COMMUNITY: provides a mechanism to group routes so that routing policies can be applied to all routes with the same community (similar to route tag in IGPs. ↩︎
  4. ORIGINATOR_ID: used by RRs to denote the RID of the iBGP neighbor that injected the NLRI into the AS ↩︎
  5. CLUSTER_LIST: used by the RRs to list the RR cluster IDs to prevent loops. ↩︎

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Scroll to Top