BGP Protocol Fundamentals: Architecture, States, and Path Selection

Routes are generally categorized into two types:

Directly Connected Routes: These routes have a default preference value of 0, representing the highest priority.

Non-Directly Connected Routes: These are further divided into static routes (default preference 60) and dynamic routes. Dynamic routing protocols fall into two categories:

  • IGP (Interior Gateway Protocol): Includes Distance Vector protocols like RIP, IGRP, and EIGRP, as well as Link State protocols such as OSPF and IS-IS. OSPF operates at Layer 3, with routes derived from Type 1, 2, and 3 LSAs having a preference of 10, while Type 4, 5, and 7 LSAs yield routes with preference 150. IS-IS functions at Layer 2.
  • EGP (Exterior Gateway Protocol): BGP is the primary EGP protocol. It is a Distance Vector protocol operating at the application layer over TCP port 179, with a default route preference of 255.

Rationale for Deploying BGP

BGP is essential for inter-AS communication and offers three key advantages:

  1. Stability: Utilizes TCP for reliable transport, employing five message types and six state transitions for reliable route propagation.
  2. Scalability: Capable of handling massive routing tables through precise network injection and import meechanisms.
  3. Rich Policy Control: Provides granular routing policies with 11 distinct path selection criteria.

Autonomous System Numbers

An Autonomous System (AS) is a unique identifier representing a collection of routers under a single administrative domain. Key characteristics include:

  • AS numbers facilitate efficient routing decisions across the internet.
  • The Internet Assigned Numbers Authority (IANA) oversees AS number allocation.
  • AS numbers are classified as public (allocated by IANA) and private (allocated by Regional Internet Registries).
  • 4-byte AS numbers are managed by IANA and distributed through RIRs.

BGP Operational Mechanics

Core Function

BGP dynamically exchanges routing information between autonomous systems.

Neighbor Relationships

  • EBGP (External BGP): Established between routers in different ASs.
  • IBGP (Internal BGP): Established between routers within the same AS.

Key Characteristics

  • Operates at the application layer using TCP port 179.
  • Routers running BGP are referred to as BGP Speakers.
  • Connected BGP routers form a peer relationship.
  • Routing updates are incremental and triggered rather than periodic.
  • Designed to handle large-scale routing tables suitable for enterprise and ISP networks.

Message Types

BGP uses five distinct message types:

  1. Open Message: Initiates peer relationships and exchanges capabilities (analogous to a Hello packet).
  2. KeepAlive Message: Maintains the peer session. This is the only periodic message in BGP, sent every 60 seconds. If three consecutive KeepAlives are missed, a Notification is sent to terminate the session.
  3. Update Message: Carries routing information, including path attributes and reachable destinations. Also used to withdraw previously advertised routes.
  4. Notification Message: Reports errors and terminates BGP connections. Commonly triggered when attempting EBGP peering via loopback interfaces without proper configuration.
  5. Route-Refresh Message: Requests peers to resend routing advertisements. Triggered via command: ``` [RouterBGP] refresh bgp all import
    
    

Finite State Machine

BGP transitions through six states during neighbor establishment:

  1. Idle: Initial state where no TCP connection exists. Typically caused by Layer 3 reachability issues. Transitions to Connect when attempting TCP establishment.
  2. Connect: TCP connection attempt in progress. If successful, sends Open message and moves to OpenSent. If TCP fails, transitions to Active.
  3. Active: TCP connection failed. The router continues attempting TCP establishment. Upon success, moves to OpenSent.
  4. OpenSent: Open message has been sent. Awaiting response. Valid Open response triggers KeepAlive and moves to OpenConfirm. Invalid response results in Notification and return to Idle.
  5. OpenConfirm: Waiting for KeepAlive confirmation. Receipt of KeepAlive moves to Established. Receipt of Notification returns to Idle.
  6. Established: Peering is fully operational. Udpate messages can now be exchanged. Malformed Update or KeepAlive messages trigger Notification and return to Idle.

Connection Establishment Flow

  1. Establish Layer 3 reachability.
  2. Complete TCP three-way handshake.
  3. Form BGP neighbor relationship.
  4. Exchange routing information.

Attribute Categories

BGP path attributes fall into four categories:

  • Well-known Mandatory
  • Well-known Discretionary
  • Optional Transitive
  • Optional Non-transitive

Path Selection Algorithm

BGP evaluates routes sequentially through 11 criteria until a single best path is selected:

  1. Preference Value (PrefVal): Huawei-proprietary attribute, local to the router. Higher values are preferred. Default is 0.
  2. Local Preference (Loc_Pref): Well-known discretionary attribute. Higher values preferred. Default is 100.
  3. Locally Originated Routes: Routes originated locally take precedence over learned routes. Priority order: Manual aggregate > Automatic aggregate > Network command > Import.
  4. AS_Path Length: Shorter AS_Path is preferred. This attribute also prevents routing loops between EBGP peers.
  5. Origin Type: IGP (i) > EGP (e) > Incomplete (?). Network command yields IGP, while import yields Incomplete.
  6. MED (Multi-Exit Discriminator): Lower values indicate a better entry point into the AS. Analogous to IGP metric.
  7. EBGP vs IBGP: EBGP-learned routes are preferred over IBGP-learned routes.
  8. IGP Metric to Next-Hop: Lower IGP cost to reach the BGP next-hop is preferred.

If multiple paths remain equally preferred after these 8 criteria, load balancing can be enabled:

[Router-bgp] maximum load-balancing ibgp 2
  1. Cluster_List Length: Shorter length is preferred. Relevant in Route Reflector scenarios to prevent inter-cluster loops.
  2. Router ID / Originator ID: Lower Router ID is preferred. In RR scenarios, Originator ID is compared instead.
  3. Peer IP Address: Lowest peer IP address is selected as the tiebreaker.

Tags: BGP Border Gateway Protocol Routing Protocol Autonomous System Path Selection

Posted on Sat, 27 Jun 2026 17:16:57 +0000 by myshoala