State machine of BGP
Idle state is the initial state of BGP. In idle state, BGP rejects the connection request sent by neighbors. Only after receiving the startup event of the device, BGP began to try to establish TCP connection with other BGP peers, and turned to the connection state.
In the connected state, BGP starts to retry the connection and waits for TCP to complete the connection.
If the TCP connection is successful, BGP sends an Open message to the peer and enters the OpenSent state.
If the TCP connection fails, BGP will enter the active state.
If the connection retransmission timer expires and BGP has not received a response from the BGP peer, BGP will continue to try to connect with other BGP peers and remain in the connected state.
In the active state, BGP always tries to establish a TCP connection.
If the TCP connection is successful, BGP sends an Open message to the peer, closes the connection retransmission timer, and turns to the OpenSent state.
If the TCP connection fails, BGP will remain active.
If the connection retransmission timer expires and BGP has not received a response from the BGP peer, BGP enters the connection state.
In the OpenSent state, BGP waits for the other party's Open message and checks the AS number, version number and authentication code in the received Open message.
If the received Open message is correct, BGP sends a Keepalive message and enters the OpenConfirm state.
If an error is found in the received Open message, BGP sends a notification message to the peer and turns to the idle state.
In the OpenConfirm state, BGP waits for Keepalive or notification message. If it receives the Keepalive message, it will enter the establishment state, and if it receives the notification message, it will enter the idle state.
In the established state, BGP can exchange update, keep alive, route refresh and notification messages with peers.
If the correct update or keep-alive message is received, BGP considers that the peer is in normal operation and will keep the BGP connection.
If an incorrect Update or Keepalive message is received, BGP sends a notification message to inform the opposite end and turns into an idle state.
The route refresh message does not change the BGP state.
If the notification message is received, BGP will enter the idle state.
If TCP disconnect notification is received, BGP will disconnect and enter an idle state.