11.3 BGP Attributes & Junos Path Selection Algorithm
Key Takeaways
BGP path attributes are categorized into four standardized classes: Well-known Mandatory, Well-known Discretionary, Optional Transitive, and Optional Non-Transitive.
Well-known mandatory attributes must be recognized by all BGP implementations and included in every route update: AS_PATH, NEXT_HOP, and ORIGIN.
Local Preference is a well-known discretionary attribute carried only within an AS (default value 100 in Junos) used to influence outbound enterprise traffic exit points.
Multi-Exit Discriminator (MED) is an optional non-transitive attribute used to convey exit link preference to an adjacent neighboring AS; Junos compares MED only among paths from the same AS by default.
Check usable next hop and route preference first; then compare Local Preference, AS path, origin, MED, EBGP/IBGP, IGP next-hop cost, stability, router/originator ID, cluster-list length and peer address.
BGP Attributes & Junos Path Selection Algorithm
Unlike Interior Gateway Protocols that compute shortest paths using scalar link metrics (such as OSPF cost or IS-IS metric), BGP determines optimal routes through a rich, multi-tiered collection of Path Attributes. Each BGP Update message advertising a prefix carries a payload of attributes describing the path's origin, history, administrative preference, and transit constraints.
When a Junos routing device receives multiple candidate paths to the exact same destination prefix, it executes the Junos BGP Path Selection Algorithm. This ordered mechanism evaluates eligibility, preference and attributes to choose a best route submitted to the Junos master routing table (inet.0).
1. Classification of BGP Path Attributes
RFC 4271 divides BGP path attributes into four distinct architectural categories based on whether an attribute must be supported by all implementations and whether it must be propagated across autonomous system boundaries:
+---------------------------------------------------------------------------------------------------+
| BGP PATH ATTRIBUTE CLASSIFICATION MATRIX |
+-----------------------+---------------------------------------+-----------------------------------+
| Category | Definition & Handling Requirement | Standard Attributes |
+-----------------------+---------------------------------------+-----------------------------------+
| Well-Known Mandatory | Must be recognized by all BGP | - AS_PATH |
| | implementations; MUST be present in | - NEXT_HOP |
| | every BGP Update advertising an NLRI. | - ORIGIN |
+-----------------------+---------------------------------------+-----------------------------------+
| Well-Known | Must be recognized by all BGP | - LOCAL_PREF |
| Discretionary | implementations; MAY be included in | - ATOMIC_AGGREGATE |
| | an Update at sender's discretion. | |
+-----------------------+---------------------------------------+-----------------------------------+
| Optional Transitive | May or may not be recognized by an | - COMMUNITY |
| | implementation; if unrecognized, MUST | - AGGREGATOR |
| | be accepted and forwarded to peers. | |
+-----------------------+---------------------------------------+-----------------------------------+
| Optional | May or may not be recognized by an | - MULTI_EXIT_DISC (MED / Metric) |
| Non-Transitive | implementation; if unrecognized, MUST | - ORIGINATOR_ID |
| | be quietly discarded and NOT passed. | - CLUSTER_LIST |
+-----------------------+---------------------------------------+-----------------------------------+
2. In-Depth Attribute Analysis
Well-Known Mandatory Attributes
AS_PATH: An ordered list of Autonomous System numbers that the route advertisement has traversed. Whenever an EBGP router advertises a route to an external peer, it prepends its own local ASN to the sequence. TheAS_PATHserves two essential functions:- Loop Detection: If a router receives an Update containing its own local ASN anywhere in the
AS_PATH, the route is rejected. - Metric / Path Length: Paths traversing fewer autonomous systems are preferred over longer paths.
The attribute contains segments:
AS_SEQUENCE(ordered list of traversed ASNs) andAS_SET(unordered set resulting from route summarization; anAS_SETcounts as exactly 1 AS in path length calculations regardless of how many ASNs it contains).
- Loop Detection: If a router receives an Update containing its own local ASN anywhere in the
NEXT_HOP: The IP address of the next-hop router used to forward transit packets toward the destination prefix. In EBGP, this is typically the IP address of the peer's interface. In IBGP, the external next-hop is preserved unchanged across the internal network.ORIGIN: Identifies how the route was initially introduced into BGP. It carries one of three standardized values:- IGP (Value 0): The route has IGP origin. Junos export of local routes commonly assigns this origin; Junos does not use an IOS-style BGP network statement. Represented as
IGPoriin routing tables. - EGP (Value 1): The prefix was learned via the legacy Exterior Gateway Protocol (RFC 904). Historical; rarely observed in production.
- Incomplete (Value 2): The origin is unspecified/incomplete. Do not infer this value solely because a Junos export policy redistributed a static route; inspect the actual attribute or set it explicitly. Represented as
Incompleteor?in routing tables. Tiebreaker hierarchy:IGPis preferred overEGP, which is preferred overIncomplete(IGP < EGP < Incomplete).
- IGP (Value 0): The route has IGP origin. Junos export of local routes commonly assigns this origin; Junos does not use an IOS-style BGP network statement. Represented as
Well-Known Discretionary Attributes
LOCAL_PREF(Local Preference): A 32-bit unsigned integer value used to indicate the degree of preference for a route within an Autonomous System. It is distributed exclusively within IBGP sessions and is stripped before routes are advertised to EBGP peers.- Junos Default:
100. - Evaluation: Higher is preferred. An enterprise administrator uses Local Preference on ingress border routers to select the primary outbound ISP for egress traffic.
- Junos Default:
ATOMIC_AGGREGATE: Informs downstream BGP speakers that an upstream router generated an aggregate route that caused path attribute details (such as specific ASNs) to be omitted.
Optional Attributes
COMMUNITY(Optional Transitive): A 32-bit numerical tag appended to routes to facilitate traffic grouping, filtering, and automated policy application across administrative domains.MULTI_EXIT_DISC(MED / Metric - Optional Non-Transitive): A 32-bit value advertised by an autonomous system to convey its preferred ingress link to a neighboring AS when multiple connections exist between the same two autonomous systems.- Evaluation: Lower is preferred.
- Propagation: Transmitted to an external peer, but that peer cannot re-transmit the MED value to third-party autonomous systems.
- Junos Default Rule: Junos OS only compares MED values between routes received from the exact same neighboring Autonomous System. If two competing paths originate from different ASNs, Junos skips MED evaluation and proceeds to the next tiebreaker.
3. Junos Route Selection and BGP Tie-Breakers
First verify a usable next hop and compare Junos route preference (lower wins). BGP normally has preference 170 for both EBGP and IBGP, but a policy can change it. Equal default preference is why the attribute sequence matters; it is not a reason to omit preference when a scenario explicitly changes it.
For eligible BGP paths with equal route preference and without optional AIGP or other path-selection changes, the common sequence is:
| Comparison | Preferred value |
|---|---|
| Local Preference | Higher; default 100 |
| AS-path length | Shorter; an AS_SET counts as one, confederation segments as zero |
| Origin | IGP before EGP before Incomplete |
| MED | Lower; normally compare only paths with the same neighboring AS |
| External versus internal BGP | EBGP before IBGP |
| IGP cost to BGP next hop | Lower |
| External-path stability | Prefer the older/current active EBGP path when the rule applies |
| Router ID | Lower; substitute ORIGINATOR_ID when present |
| Cluster list | Shorter; absent list has length zero |
| Peer address | Lower |
Juniper’s complete RPD procedure additionally covers optional AIGP, strictly internal/local routes and primary-versus-secondary routes. These are not new universal steps to insert blindly into every basic BGP question. Start with the inputs actually supplied and identify the earliest comparison that differs.
Worked Attribute Decisions
Two reachable paths have equal preference 170. Path A has Local Preference 100 and AS path length 2. Path B has Local Preference 200 and AS path length 4. Path B wins because Local Preference is examined before AS path. A longer path does not overturn an earlier preference decision.
If both instead have Local Preference 100, compare AS path next. Each extra prepended AS in an AS_SEQUENCE increases its length; an AS_SET counts as one even if it contains several ASNs. Neither metric is an IGP hop count. For equal AS paths, IGP origin beats Incomplete; origin describes the route attribute rather than the current transport protocol.
MED Scope and Overrides
When two paths come from the same neighboring AS, a lower MED can choose the preferred entry into that AS. Paths from different neighboring ASs normally skip this comparison. set protocols bgp path-selection always-compare-med changes that behavior. A missing MED is treated as zero by the documented Junos procedure. The cisco-non-deterministic option changes ordering/grouping of comparisons; it is not the switch that disables the older-EBGP-path rule.
The stability preference has explicit exceptions, including path-selection external-router-id, identical peer router IDs, confederation peers, or neither path being the current active path. Use external-router-id when deliberately bypassing that stability preference; do not describe the rule as choosing the “lowest age,” which misleadingly suggests the newest path.
Route Reflection and Multipath
An unresolved next hop renders a path hidden regardless of a desirable Local Preference. Inspect show route hidden extensive and verify next-hop reachability before changing attributes. Hidden and inactive are different: an inactive route may be valid but lose to another route.
For reflected paths, compare originator IDs in place of peer router IDs, then cluster-list length before peer IP address. Otherwise, a router could select the wrong route in an exam scenario with identical originator IDs and different reflection paths. Equal-cost forwarding also requires applicable BGP multipath and forwarding installation; two received paths are not automatic proof that both carry traffic.
Official references checked 2026-10-18: Junos BGP defaults and selection.
How is the Multi-Exit Discriminator (MED) attribute officially classified under BGP RFC specifications, and what is its transit propagation behavior?
Well-known mandatory; must be passed across all autonomous systems to the destination
Well-known discretionary; propagated throughout the local autonomous system but stripped at the EBGP edge
Optional transitive; forwarded across all downstream autonomous systems even if unrecognized
Optional non-transitive; passed to an adjacent autonomous system but not propagated beyond that receiving AS
A Junos router has two reachable BGP paths for 10.100.0.0/16 with equal route preference. Path 1 has Local Preference 100, AS-path length 3 and Origin IGP. Path 2 has Local Preference 150, AS-path length 4 and Origin Incomplete. Which path wins and why?
Path 1 wins because it has a shorter AS-Path length (3 vs 4)
Path 2 wins because Local Preference is evaluated before AS-Path length and Origin code
Path 1 wins because Origin IGP takes absolute precedence over Local Preference
Path 2 wins because Origin Incomplete represents an internal redistributed route
Under default Junos BGP behavior, how are different MED values treated when two otherwise tied candidate paths have different neighboring AS numbers?
Junos immediately selects the path with the lower MED value regardless of originating AS
Junos drops both candidate paths and generates a path-selection error notification
Junos skips the MED comparison entirely and proceeds to the next tiebreaker (EBGP over IBGP)
Junos uses the average of the two MED values to compute equal-cost multipath forwarding
Sections you finish are checked off in the contents.