BGP finite state machine
The six-state FSM that governs BGP session lifecycle — from Idle through Established, with events and transitions.
Contents
States
Each configured peer has an independent FSM instance. The six states:
| State | Description |
|---|---|
| Idle | No resources allocated. Refuses all incoming connections. Waits for ManualStart or AutomaticStart. |
| Connect | TCP connection attempt in progress. ConnectRetryTimer running. |
| Active | Listening for incoming TCP connection (passive mode). ConnectRetryTimer running. |
| OpenSent | TCP connected. OPEN message sent. Waiting for peer’s OPEN. |
| OpenConfirm | OPEN received and validated. KEEPALIVE sent. Waiting for peer’s KEEPALIVE. |
| Established | Session fully operational. UPDATE and KEEPALIVE messages exchanged. |
Session attributes
Mandatory
Every FSM instance maintains:
| Attribute | Purpose |
|---|---|
| State | Current FSM state |
| ConnectRetryCounter | Number of connection attempts |
| ConnectRetryTimer | Time before retrying TCP connection |
| HoldTimer | Deadman timer — peer must send KEEPALIVE/UPDATE before expiry |
| HoldTime | Negotiated hold interval (initial value from configuration) |
| KeepaliveTimer | Interval for sending KEEPALIVE messages |
| KeepaliveTime | Initial value (typically HoldTime/3) |
Optional
| Attribute | Purpose |
|---|---|
| DampPeerOscillations | Back off when peer flaps repeatedly |
| IdleHoldTime / IdleHoldTimer | Hold in Idle state after flap (exponential backoff) |
| DelayOpen / DelayOpenTimer | Delay sending OPEN to allow peer to go first |
| PassiveTcpEstablishment | Listen only, do not initiate TCP |
| SendNOTIFICATIONwithoutOPEN | Allow NOTIFICATION before OPEN exchange |
| CollisionDetectEstablishedState | Process collisions in Established state |
Events
Events drive state transitions. They fall into five categories.
Administrative events (1-8)
| Event | Name | Status |
|---|---|---|
| 1 | ManualStart | Mandatory |
| 2 | ManualStop | Mandatory |
| 3 | AutomaticStart | Optional |
| 4 | ManualStart with PassiveTcpEstablishment | Optional |
| 5 | AutomaticStart with PassiveTcpEstablishment | Optional |
| 6 | AutomaticStart with DampPeerOscillations | Optional |
| 7 | AutomaticStart with DampPeerOscillations and PassiveTcp | Optional |
| 8 | AutomaticStop | Optional |
Timer events (9-13)
| Event | Name | Status |
|---|---|---|
| 9 | ConnectRetryTimer_Expires | Mandatory |
| 10 | HoldTimer_Expires | Mandatory |
| 11 | KeepaliveTimer_Expires | Mandatory |
| 12 | DelayOpenTimer_Expires | Optional |
| 13 | IdleHoldTimer_Expires | Optional |
TCP events (14-18)
| Event | Name | Status |
|---|---|---|
| 14 | TcpConnection_Valid | Optional |
| 15 | Tcp_CR_Invalid | Optional |
| 16 | Tcp_CR_Acked | Mandatory |
| 17 | TcpConnectionConfirmed | Mandatory |
| 18 | TcpConnectionFails | Mandatory |
BGP message events (19-28)
| Event | Name | Status |
|---|---|---|
| 19 | BGPOpen | Mandatory |
| 20 | BGPOpen with DelayOpenTimer running | Optional |
| 21 | BGPHeaderErr | Mandatory |
| 22 | BGPOpenMsgErr | Mandatory |
| 23 | OpenCollisionDump | Optional |
| 24 | NotifMsgVerErr | Mandatory |
| 25 | NotifMsg | Mandatory |
| 26 | KeepAliveMsg | Mandatory |
| 27 | UpdateMsg | Mandatory |
| 28 | UpdateMsgErr | Mandatory |
State transitions in detail
Idle state
Connect state
TCP initiation is in progress. Three outcomes:
- TCP succeeds (Event 16/17) — clear ConnectRetryTimer, send OPEN, start HoldTimer → OpenSent
- TCP fails (Event 18) — restart ConnectRetryTimer, continue listening → Active
- ConnectRetryTimer expires (Event 9) — drop TCP, restart timer, initiate new TCP → Connect
Any error or ManualStop → close connection, release resources → Idle
Active state
Passively waiting for inbound TCP. Key transitions:
- TCP succeeds (Event 16/17) — clear ConnectRetryTimer, send OPEN → OpenSent
- ConnectRetryTimer expires (Event 9) — attempt active TCP connection → Connect
- TCP fails (Event 18) — restart timer, increment counter → Idle
OpenSent state
OPEN sent, waiting for peer’s OPEN. The large initial HoldTimer (4 minutes) runs.
- Valid OPEN received (Event 19) — negotiate Hold Time, set HoldTimer, send KEEPALIVE → OpenConfirm
- Error in OPEN (Event 22) — send NOTIFICATION → Idle
- TCP fails (Event 18) — close, restart ConnectRetryTimer → Active
- Connection collision (Event 23) — resolve per BGP Identifier comparison
OpenConfirm state
Both OPENs exchanged. Waiting for the confirming KEEPALIVE.
- KEEPALIVE received (Event 26) — start negotiated HoldTimer → Established
- NOTIFICATION received (Event 24/25) → Idle
- HoldTimer expires (Event 10) — send NOTIFICATION (Hold Timer Expired) → Idle
Established state
Session operational. Normal processing:
- UpdateMsg (Event 27) — process UPDATE, restart HoldTimer
- KeepaliveTimer expires (Event 11) — send KEEPALIVE
- KeepAliveMsg (Event 26) — restart HoldTimer
- HoldTimer expires (Event 10) — send NOTIFICATION → Idle
- UpdateMsgErr (Event 28) — send NOTIFICATION → Idle
- ManualStop (Event 2) — send Cease NOTIFICATION → Idle
Connection collision detection
When both peers initiate TCP simultaneously, two connections form. Resolution:
Collision detection happens upon receiving an OPEN when another connection to the same peer is in OpenConfirm state. The loser gets a Cease NOTIFICATION.
Peer oscillation damping
Implementations track the ConnectRetryCounter. After repeated flaps, the IdleHoldTime increases (commonly doubling up to a cap like 120 seconds). This prevents tight reconnection loops from consuming resources across the network.