New Batch Starts on 16th Oct.
Module: Network Fundamentals (L2 L3 Protocol Testing)
Timing: 07:00 AM to 08:00 AM IST (Weekdays)
Sign Up Now !

BGP Protocol Peering and States

BGP Peering Process:

The BGP peering process involves several steps that BGP routers take to create and maintain a secure and reliable connection for exchanging routing information. This process goes through various stages, known as “BGP states.” In this tutorial, we will discuss the step-by-step process BGP follows to complete the peering. This process forms the backbone of the internet’s global routing architecture, enabling different autonomous systems to share route information efficiently and effectively.

Table of Contents


Understanding the BGP Peering Process:

The BGP peering process involves several steps to ensure a reliable exchange of routing information between peers. Here’s how it works:

1. TCP Connection Establishment

BGP runs over TCP, using port 179. The first step in the peering process is to establish a TCP connection between the two BGP routers. This connection ensures that messages are exchanged reliably and sets the stage for a stable BGP session.

2. Exchange of OPEN Packets

Once the TCP connection is in place, both routers send an OPEN packet. This packet includes details like:

  1. BGP version
  2. Autonomous System (AS) number
  3. The hold time, which defines how long the connection stays active without receiving KEEPALIVE messages
  4. Password (Optional)

This exchange ensures that both routers are on the same page with session parameters.

3. Negotiation and Confirmation

After receiving the OPEN packet, each router checks the session details, such as the BGP version and hold time. If both routers agree on these parameters, they move forward. However, if there’s any mismatch like different versions or incompatible settings, a NOTIFICATION packet is sent and the connection is terminated.

4. BGP State Transitions

As BGP peers establish their session, they go through a series of states:

  1. Idle: The router is waiting to start the BGP process.
  2. Connect: The router is attempting to establish a TCP connection.
  3. Active: The router is actively trying to establish the connection.
  4. OpenSent: The OPEN packet has been sent to the peer.
  5. OpenConfirm: The router is waiting for confirmation of the OPEN packet.
  6. Established: The session is fully established, and routing information is ready to be exchanged.

Each state represents a different step in the process, and the goal is to reach the Established state where the session is live.

5. Exchange of Routing Information

Once in the Established state, the peers start exchanging UPDATE messages. These messages contain routing information—new routes, updates to existing routes, and even route withdrawals. This helps maintain up-to-date routing tables and ensures efficient paths are used.

6. Session Maintenance with KEEPALIVE Messages

To maintain the BGP session, routers exchange KEEPALIVE messages regularly. These packets confirm that both routers are reachable, keeping the session active. The interval for sending KEEPALIVE messages is determined by the hold time agreed upon during the OPEN packet exchange.

7. Error Handling with NOTIFICATION Messages

If any issues arise during the session, such as configuration errors or protocol violations, a NOTIFICATION message is sent. These messages are used to indicate problems and terminate the session if needed, ensuring the BGP session’s stability and security.


BGP Peering States

When BGP routers establish a connection, they transition through several states: Idle, Connect, Active, OpenSent, OpenConfirm, and Established. Each state represents a specific phase in the peering process.

A diagram showing different BGP states and packets during the BGP peering process
BGP Peering States

Idle State:

Initially, the router starts in the Idle state. In this phase, BGP doesn’t try to connect to its peer yet. Instead, it performs administrative tasks like resetting the connection if needed and waiting to begin the BGP process.

Connect State:

Next, the router moves to the Connect state. Here, it actively attempts to establish a TCP connection with the peer. If the TCP connection is successful, the router proceeds to the next state. However, if the connection fails, the router may retry or move to the Active state.

Active State:

In the Active state, the router continues trying to establish the TCP connection if the initial attempt failed. If successful, the router moves forward. If not, it might cycle back to the Connect state or stay in Active to retry.

OpenSent State:

Once the TCP connection is established, the router sends an OPEN message to the peer and transitions to the OpenSent state. In this state, the router waits for an OPEN message from the peer. This message contains crucial details like the BGP version, AS number, and hold time.

OpenConfirm State:

After both routers exchange OPEN messages and verify their compatibility, they enter the OpenConfirm state. Here, they send KEEPALIVE messages to confirm the connection and ensure everything is set up correctly.

Established State:

Finally, once the KEEPALIVE messages are successfully exchanged and acknowledged, the routers move to the Established state. In this phase, they can start exchanging UPDATE messages, which contain routing information. This exchange keeps the routing tables up-to-date, ensuring efficient and accurate routing across the network.

During these transitions, if any issues arise, such as mismatched parameters in the OPEN messages or errors detected, the routers send NOTIFICATION messages to indicate the problem and potentially terminate the connection to prevent flawed interactions.


Next >>> BGP Configuration Example 1: EBGP Peering

Previous >>> How BGP Works?

Further reading : RFC 4271


We’d love to hear your feedback and suggestions about this article. Feel free to reach out to us using the WhatsApp number below.

Sajith Achipra has been a trainer and testing consultant at Zframez Technologies since 2009. With 15+ years of experience, he specializes in networking, Python, development, and testing. He conducts online courses to help students and professionals enhance their skills. You can reach him on WhatsApp at +91 8884 884 844 for your training and testing requirements.