BGP sessions with neighbours may report one of six states:
Idle is the first stage in the BGP neighbour state. BGP tries to initiate a TCP connection to the BGP peer and also listens for any incoming connections.
If an error causes the BGP session to go the idle state, it must wait until the ConenctRetryTimer reaches zero from 60 seconds. If repeated failures occur it can cause the ConnectRetry to double in size from the previous timer.
In the Connect state, BGP is initiating the TCP connection to the neighbour. If the TCP three way handshake completes, the session resets the ConnectRetryTimer and sends an Open message to the neighbour before changing to the OpenSent state.
If a ConnectRetryTimer reaches zero before the Connect stage completes, a new TCP connection is attempted, the ConnectRetryTimer is reset and the state is moved to Active. If any other input is received, the state is changed to Idle.
In this stage, it is the router with the higher IP address that manages the connection. The router initiating the request will use destination port 179, but a randomised source port.
In this state, the BGP process starts a new three way TCP handshake. If a connection establishes an Open message to sent with a holder timer set to four minutes, and the overal state moves to OpenSent. If the TCP connection attempts the session moves back to the Connect state with a reset ConnectRetryTimer.
In the OpenSent state, an Open message had been sent from the source router which is awaiting a response from the destination router.
When an Open message is sent back to the original router, several examinations are made:
- The BGP versions must match
- The source IP address of the OPEN message must match the IP address that is configured for the neighbour
- The AS number in the OPEN message must be be identical to what is configured in the router
- BGP identifiers, or router IDs, must be unique.
- Security parameters such as password and TTL must be set.
If the OPEN message does not contain any issues, a hold time is negioated using the lower value between the two routers, with a KEEPALIVE being sent if the value is higher than zero.
The connection state is then moved to OpenConfirm. If an error is found, a NOTIFICATION is sent and the state is moved back to Idle.
In this state, BGP is awaiting a KEEPALIVE or NOTIFICATION message. If a KEEPALIVE message is received, the BGP state moves to Established. If a NOTIFICATION message is received, the state moves to Idle.
In the established state, it essentially means the BGP session has established. BGP neighbours will exchange routes using UPDATE messages. As UPDATE and KEEPALIVE messages are exchanged, the hold timer gets reset. If the hold timer expires, or an error is detected, the session moves back to an Idle state.