BGP Message Types & FSM
In this tutorial we will discuss about different message types of BGP, BGP Peer Connection, BGP Finite State Machine. Before establishing BGP Peer Connection, two neighbor must perform TCP Three-Way-Handshake and open a connection to Port number 179. BGP is a Transport Layer Protocol, hence TCP provides fragmentation, acknowledgement, sequencing functions necessary for reliable connection. BGP Peer must be statically configured and a route must present in the routing table. All the BGP Messages are unicast over TCP Connection. BGP Uses five basic message.
- Route Refresh
All BGP Messages have a common header and encapsulated into a TCP Fragment. Header consists of Marker, Length and Type of the BGP Messages. A Keepalive message is nothing but a BGP Header. Open Message consists of version number of bgp, autonomous system number of the originating router, hold time, bgp identifier and optional parameters for capabilities negotiation. A Update Message consists of withdrawn routes, path attributes and NLRI. Notification message consists of error code and subcodes. The parameters inside a BGP Message are represented in a TLV format. TLV is a triplet of Type, Length and Value.
Encapsulation of BGP Messages
All BGP Messages are encapsulated in TCP using Port Number 179. BGP TCP Client uses a registered higher range port( 1024 to 49151 ) as Source Port and Port number 179 as destination port. BGP TCP Server use the port in the reverse way. IP Layer further encapsulate the TCP message using source IP as defined by update-source in the BGP configuration or the IP of the exit interface of the route pointing toward peer IP. It uses the peer IP configured as destination ip of the IP Packet. Refer the below diagram for further details.
BGP Neighborship and validation of Parameters
For very basic understanding we will discuss neighborship between two routers R1 and R2 residing in AS 1 & 2 accordingly. Before any BGP message would be sent, a TCP connection must open between R1 & R2. Once TCP connection is established, any of the routers can send the BGP open message to other neighbor.
In the above example, R1 sends a OPEN message to R2 once the TCP session is established. R2 then verify the parameters like AS numbers, RID, source IP ect comparing with the values configured in it. If it found the OPEN is valid, then it send a reply OPEN message to R1. R1 will also check the parameters. Once validation completed, R1 will reply with a KEEPALIVE. R1 now consider it in neighborship established with R2. Once R2 will receive the KEEPALIVE, it will change it state to established.
Some parameters must be checked to validate the TCP and BGP messages. These are D-IP, S-IP, TCP Ports, REMOTE AS, MY AS, RID.
The Destination IP(D-IP) would be the
as a neighbor and it must match the source IP(update-source) of the peer router. The Source IP(S-IP) would be either the interface IP configured as an update source or the IP of the exit interface pointing toward the route of the neighbor and it must match with the IP configured as neighbor in the peer router. The Source & Destination Port must open for successful TCP connection. Remote AS must match with the AS number of the peer that is the BGP instance number configured in the peer router. My AS(than is configured as BGP instance number) must match with the AS number configured as remote-as of the peer router. BGP Router ID(RID) must be a unique value.
BGP Finite State Machine
All the above signalling and states are controlled by BGP Finite State Machine(FSM). In BGP FSM, some Input Events(IE) and valid states are defined. The transition between finite states are governed by input events. There are 13 input events and 5 finite states are defined in bgp. In the following section, we will discuss that. The input events are locally triggered and it is based upon many inputs like manual configuration change, command input, arrival of different bgp messages, etc.
|3||BGP Transport connection open|
|4||BGP Transport connection closed|
|5||BGP Transport connection open failed|
|6||BGP Transport fatal error|
|7||ConnectRetry timer expired|
|8||Hold timer expired|
|9||Keepalive timer expired|
|10||Receive Open message|
|11||Receive Keepalive message|
|12||Receive Update message|
|13||Receive Notification message|
BGP forms a TCP session with neighbor routers called peers. BGP uses the Finite State Machine (FSM) to maintain a table of all BGP peers and their operational status. The BGP session may report in the following states:
From the OSI Model’s perspective, BGP is simply a networking application running on top of the the Session layer and everything below it. Thus, an ESTABLISHED BGP SESSION is required for BGP to begin exchanging routes.