How Does BGP Work?

BGP uses TCP port 179 for communication. BGP is considered a path-vector protocol, containing end-to-end path descriptions for destinations. BGP neighbors can either be internal (iBGP) or external (eBGP):

Paths are advertised in UPDATE messages that are tagged with various path attributes. AS_PATH and NEXT_HOP are the two most important attributes that describe the path of a route in a BGP update message.

BGP Finite State Machine

RFC 1771, which defines BGP, describes the operation of BGP in terms of the following state machine. The table following BGP Finite State Machine provides additional information on the various states.

BGP Finite State Machine

 

BGP Finite State Machine: States

State

Description

Idle

Waiting for Start event, after establishing new BGP session or resetting an existing session. In the event of errors, falls back to the Idle state. After a Start event, BGP initializes, resets connect retry timer, initiates TCP transport connection, and listens for connections

Connect

Once the TCP layer is up, transition to OpenSent, and send OPEN. If no TCP, transition to Active. If the connect retry timer expires, remain in Connect, reset the timer, and initiate a transport connection. Otherwise, transition back to Idle.

Active

Try to establish TCP connection with peer. If successful, transition to OpenSent and send OPEN. If connect retry expires, restart the timer and fall back to the Connect state. Also actively listen for connection by another peer. Go back to Idle in case of other events.

Connect to Active flapping indicates a TCP transport problem, for example, TCP retransmissions or unreachability of a peer.

OpenSent

Waiting for OPEN message from peer. Validate on receipt. On validation failure, send NOTIFICATION and go to Idle. On success, send KEEPALIVE and reset the keepalive timer. Negotiate hold time, smaller value wins. If zero, hold timer and keepalive timer are not restarted.

OpenConfirm

Wait for KEEPALIVE or NOTIFICATION. If KEEPALIVE is received, transition to Established. If UPDATE or KEEPALIVE is received, restart the hold timer (unless the negotiated hold time is zero). If NOTIFICATION is received, transition to Idle.

Periodic KEEPALIVE messages are sent. If TCP layer breaks, transition to Idle. If an error occurs, send a NOTIFICATION with error code, transition to Idle.

Established

Session up, exchange updates with peers. If a NOTIFICATION is received, transition to Idle. Updates are checked for errors. On error, send NOTIFICATION, and transition to Idle. In case of hold time expiration, disconnect TCP.

BGP Messages

BGP communication includes the following types of messages

Open – The first message between BGP peers after TCP session establishment. Contains the necessary information to establish a peering session, for example, ASN, hold time, and capabilities such as multi-product extensions and route-refresh.
Update – These messages contain path information, such as route announcements or withdrawals.
Keepalive – Periodic messages to keep TCP layer up, and to advertise liveliness.
Notification – A request to terminate the BGP session. Non-fatal notifications contain the error code “cease”. Subcodes provide further detail:
 

Notification Subcodes

Subcode

Description

1 – Maximum number of prefixes reached

The configured “neighbor maximum-prefix” value was exceeded

2 – Administratively shutdown

Session was administratively shutdown

3 – Peer unconfigured

Peer configuration has been removed

4 – Administratively reset

Session was administratively reset

5 – Connection rejected

Rejection (sometimes temporary) of BGP session

6 – Other configuration change

Session was administratively reset for some reason

Route-refresh – A request for the peer to resend its routes.
BGP Attributes

BGP update messages can include the following attributes:

 

BCP Attributes

Value

Code

1

ORIGIN

2

AS_PATH

3

NEXT_HOP

4

MULTI_EXIT_DISC

5

LOCAL_PREF

6

ATOMIC_AGGREGATE

7

AGGREGATOR

8

COMMUNITY

9

ORIGINATOR_ID

10

CLUSTER_LIST

11

DPA

12

ADVERTISER (Historic)

13

RCID_PATH / CLUSTER_ID (Historic)

14

MP_REACH_NLRI

15

MP_UNREACH_NLRI

16

EXTENDED COMMUNITIES

17

AS4_PATH

18

AS4_AGGREGATOR

19

SAFI Specific Attribute (SSA) (deprecated)

20

Connector Attribute (deprecated)

21

AS_PATHLIMIT (deprecated)

22

PMSI_TUNNEL

23

Tunnel Encapsulation Attribute

24

Traffic Engineering

25

IPv6 Address Specific Extended Community

26

AIGP (TEMPORARY - expires 2011-02-23)

27-254

Unassigned

255

Reserved for development

For more information on BGP attributes, see: http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xml.