BGP

Blog Series: Mastering BGP – Part 2: How BGP Works (State Machine, RIBs, Path Attributes, and Best-Path Selection)

At its core, BGP is about establishing and maintaining peering relationships between routers. Before any routing information is exchanged, both routers must progress through a defined sequence of connection states, managed by the BGP state machine.
Blog Series: Mastering BGP – Part 2: How BGP Works (State Machine, RIBs, Path Attributes, and Best-Path Selection)

On this page

Welcome back to our BGP series! In Part 1, we took a journey through the origins of Border Gateway Protocol (BGP) and uncovered why it’s the powerhouse behind the modern Internet. Today, we’re diving deeper into the nuts and bolts of BGP—breaking down how it works, from the state machine that gets things rolling to the decision-making process that determines how data travels across the globe. Let’s get into it!

Inside the BGP State Machine

At its core, BGP is about establishing and maintaining peering relationships between routers. Before any routing information is exchanged, both routers must progress through a defined sequence of connection states, managed by the BGP state machine. This process ensures that sessions are only established when both sides are fully prepared, reducing the risk of misconfiguration and instability.

Here’s how the BGP state machine operates:

  • Idle: The initial state. The router is not yet attempting to connect, but is ready to begin the process when triggered.
  • Connect: The router initiates a TCP session to its peer on port 179. If the connection is successful, the process moves forward; if not, the router either retries or returns to Idle.
  • Active: If the TCP connection attempt fails, the router continues to attempt to establish the session. This state reflects ongoing connection efforts.
  • OpenSent: After a successful TCP handshake, the router sends an OPEN message to its peer, which includes its AS number, BGP version, and timer values.
  • OpenConfirm: The router waits for an OPEN message in response from its peer. If received and validated, the session progresses; otherwise, the process resets.
  • Established: The session is fully operational. Routers now exchange UPDATE messages and share routing information.

This structured handshake sequence is fundamental to BGP’s reliability, ensuring that only properly established sessions are used for exchanging routes.

The Routing Information Bases (RIBs)

With the session up, BGP routers must manage vast volumes of route information. This is handled through three key tables, collectively known as Routing Information Bases (RIBs):

  • Adj-RIB-In: Stores all routes received from peers—raw and unfiltered, like an inbox.
  • Loc-RIB: Routes are filtered and policy is applied here. This table contains the best routes the router will actually use. Consider it the “brain” of BGP’s route selection.
  • Adj-RIB-Out: Prepares routes to be advertised to peers. Only the best, policy-compliant routes make it out—like an outbox.

These tables keep BGP organized and scalable, even as the global routing table explodes in size.

This post is for subscribers only

Subscribe to LevelUp I.T. newsletter and stay updated.

Don't miss anything. Get all the latest posts delivered straight to your inbox. It's free!
Great! Check your inbox and click the link to confirm your subscription.
Error! Please enter a valid email address!