User:RichiH/BGP

Finite state machine
In order to make decisions in its operations with other BGP peers, a BGP peer uses a simple finite state machine (FSM) that consists of six states: Idle, Connect, Active, OpenSent, OpenConfirm, and Established. For each peer-to-peer session, a BGP implementation maintains a state variable that tracks which of these six states the session is in. The BGP protocol defines the messages that each peer should exchange in order to change the session from one state to another. The first mode is the “Idle” mode. In this mode BGP initializes all resources, refuses all inbound BGP connection attempts, and initiates a TCP connection to the peer. The second state is “Connect”. In this state the router waits for the TCP connection to complete, transitioning to the "OpenSent" state if successful. If not, it resets the ConnectRetry timer and transitions to the "Active" state upon expiration. In the "Active" state, the router resets the ConnectRetry timer to zero, and returns to the "Connect" state. After "OpenSent," the router sends an Open message, and waits for one in return. Keepalive messages are exchanged next, and upon successful receipt, the router is placed in the “Established” state. Once established the router can now send/receive Keepalive, Update, and Notification messages to/from its peer.


 * Idle State:
 * Initializes resources for the BGP process.
 * Tries to establish a TCP connection with its configured BGP peer.
 * Listens for a TCP connection from its peer.
 * Changes its state to Connect.
 * If an error occurs at any state of the FSM process, the BGP session is terminated immediately, and returned to the Idle State. Some of the reasons why a router does not progress from the Idle state are:
 * TCP port 179 is not open.
 * A random TCP port over 1023 is not open.
 * Peer address configured incorrectly on either router.
 * AS number configured incorrectly on either router.
 * Connect State:
 * Wait for successful TCP negotiation with peer.
 * BGP does not spend much time in this state if the TCP session has been successfully established.
 * Sends OPEN message to peer and changes state to OpenSent.
 * If an error occurs, BGP moves to the ACTIVE state. Some reasons for the error are:
 * TCP port 179 is not open.
 * A random TCP port over 1023 is not open.
 * Peer address configured incorrectly on either router.
 * AS number configured incorrectly on either router.
 * Active State:
 * If the router was unable to establish a successful TCP session, then it ends up in the ACTIVE state.
 * The router will try to restart another TCP session with the peer and if successful, then it will send an OPEN message to the peer.
 * If it is unsuccessful again, the FSM is reset to the IDLE state.
 * Repeated failures may result in a router cycling between the IDLE and the ACTIVE states. Some of the reasons for this include:
 * TCP port 179 is not open.
 * A random TCP port over 1023 is not open.
 * BGP configuration error.
 * Network congestion.
 * Flapping network interface.
 * OpenSent State:
 * The router listens for an OPEN message from its peer.
 * Once the message has been received, the router checks the validity of the OPEN message.
 * If there is an error it is because one of the fields in the OPEN message don’t match between the peers, e.g. BGP version mismatch, MD5 password mismatch, the peering router expects a different My AS. The router will then send a NOTIFICATION message to the peer indicating why the error occurred.
 * If there is no error, a KEEPALIVE message is sent, various timers are set and the state is changed to OpenConfirm.
 * OpenConfirm State:
 * The peer is listening for a KEEPALIVE message from its peer.
 * If a KEEPALIVE message is received and no timer has expired before reception of the KEEPALIVE, BGP transitions to the Established state.
 * If a timer expires before a KEEPALIVE message is received, or if an error condition occurs, the router transitions back to the IDLE state.
 * Established State:
 * In this state, the peers send UPDATE messages to exchange information about each route being advertised to the BGP peer.
 * If there is any error in the UPDATE message then a NOTIFICATION message is sent to the peer, and BGP transitions back to the IDLE state