BGP protocol (1)

table of Contents

1. BGP overview

2. BGP packets

3. BGP state machine

4. How BGP works

4.1 BGP routing information processing

4.2 Working process

4.3 Principles of interaction between peers

      Synchronization of IBGP and IGP


1. BGP overview

  • BGP is a dynamic routing protocol used between Autonomous Systems. It is mainly used to exchange reachable routing information between ASs, construct propagation paths between AS domains, prevent routing loops, and apply some routing strategies at the AS level. The currently used version is BGP-4 (RFC4271). As the Internet external routing protocol standard, BGP is widely used among ISPs.
  • BGP is an exterior gateway routing protocol (EGP), which is different from interior gateway routing protocols such as OSPF and RIP. It focuses not on automatically discovering the network topology, but on selecting the best route between ASs and controlling the propagation of routes.
  • BGP uses TCP as the transport layer protocol (monitoring port number is 179), which improves the reliability of the protocol, and does not require special mechanisms to ensure the controllability of the connection. BGP performs routing between domains, which requires the stability of the protocol. Very high, using the high reliability of the TCP protocol to ensure the stability of the BGP protocol.
  • The three-way handshake condition of TCP makes TCP only work based on unicast, while BGP needs to establish neighbors indirectly; BGP is based on IGP, first run IGP to make the IP between BGP devices reachable, and then BGP can establish indirect neighbors based on TCP relationship.
  • When routing updates, BGP only sends updated routes, which greatly reduces the bandwidth occupied by BGP to propagate routes, and is suitable for propagating a large amount of routing information on the Internet.
  • BGP avoids loops by design: between ASs, BGP uses AS path information to mark the AS that it passes through, and routes with local AS numbers will be discarded; within the AS, the routes learned by BGP within the AS are not Then notify other neighbors in the AS to avoid loops in the AS.
  • BGP has rich attributes to replace the metrics in the IGP protocol for routing; and it is not used for load balancing by default, and a best path is selected through various routing rules.

2. BGP packets

It works based on TCP port 179; therefore, all data packets in the BGP protocol are transmitted based on the TCP session after the TCP session is established and ensure reliability. The BGP protocol first finds neighbors through TCP's three-way handshake.

The operation of BGP is driven by messages. There are five message types: Open, Update, Notification, Keepalive, and Route-Refresh.

  • Open message: It is the first message sent after the TCP connection is established, and is used to establish the connection relationship between BGP neighbors. Normally, send and receive only once, carry Route-id, hold time (default 3min).
  • Update message: used to exchange router information between peers, carrying routing entries (target network number + various attributes). An Update message can advertise multiple pieces of reachable routing information with the same attributes, and can also cancel multiple pieces of unreachable routing information.
  • Keepalive message: Inquire whether the neighbor relationship exists every 1 minute; actually keep the TCP session alive.
  • Notification message: When BGP detects an error state, it sends a Notification message to the neighbor, and then the BGP connection is immediately terminated.
  • Route-Refresh message: Inform BGP Peer to support route refresh capability locally through OPEN message. When Route-Refresh is enabled on all BGP routers, if the ingress routing policy of BGP changes, the local BGP router will advertise a Route-Refresh message to the peer, and the peer that receives this message will refresh its routing information. Sent to the local BGP router. In this way, the BGP routing table can be dynamically refreshed and new routing policies can be applied without interrupting the BGP connection.

BGP uses TCP to establish a connection, and the local listening port is 179. Similar to TCP connection establishment, BGP connection establishment also goes through a series of dialogues and handshake. TCP advertises its port and other parameters through handshake negotiation. BGP handshake negotiation parameters include: BGP version, BGP connection retention time, local router ID (Router ID), authorization information, etc. This information is carried in the Open message.

After the BGP connection is established, if there is a route to be sent, an Update message is sent to notify the peer. When the Update message advertises a route, it also carries the route attributes of this route to help the peer BGP protocol select the optimal route. When the local BGP route changes, the BGP peer must be notified through the Update message.

After a period of routing information exchange, neither the local BGP nor the peer BGP has any new route announcements, which tends to be stable. At this time, KEEPALIVE messages should be sent regularly to maintain the validity of the BGP connection. For local BGP, if no BGP message from the peer is received within the hold time, the BGP connection is considered to have been interrupted, the BGP connection will be disconnected, and all BGP routes learned from the peer will be deleted .

When the local BGP finds an error during operation (such as the peer BGP version is not supported locally, the local BGP receives an Update message with an illegal structure, etc.), it must send a Notification message to notify the BGP peer. When the local BGP exits the BGP connection, it also needs to send a Notification message.

3. BGP state machine

State machine: BGP has 6 state machines: Idle, connect, active, opensent, openconfirm, Establish

The Idle state is the initial state of BGP. In the Idle state, BGP rejects the connection request sent by the neighbor. Only after receiving the start event of the device, BGP starts to try to establish a TCP connection with other BGP neighbors and transfers to the Connect state ( The start event is the process by which the administrator configures BGP, or resets an existing process, or is caused by software resetting BGP).

  • In the Connect state, BGP starts a connection retransmission timer (default 32 seconds), and waits for TCP to complete the connection.
  • At this stage, a TCP connection is actively initiated. If the TCP connection is successful, BGP sends an Open message to the peer and transfers to the opensent state; if the TCP connection fails, then BGP transfers to the Active state.
  • If the connection retransmission timer expires and BGP still does not receive a response from the peer, then BGP continues to try to establish a TCP connection with other peers and stays in the connect state.
  • If other events (operated by the system or administrator) occur, return to the idle state.

In the Active state, BGP is always trying to establish a TCP connection.

  • This stage is waiting for the other party to initiate a TCP connection. If the TCP connection is successful, BGP sends an Open message to the peer, closes the connection retransmission timer, and transitions to the opensent state; if the TCP connection fails, then BGP stays in the Active state.
  • If the connection retransmission timer expires and BGP still does not receive a response from the peer, then BGP switches to the Connect state.

In the Opensent state, BGP waits for the Open message from the peer and checks the AS number, version number, and authentication code in the open message received.

  • If the Open message is received correctly, BGP sends a keepalive message and goes to the Opencomfirm state; if it finds an error in the Open message, then BGP sends a Notification message to the peer and goes to the idle state

In the Establish state, BGP can exchange Update, Keepalive, route-refresh, and Notification messages with peers

  • If the correct Update and Keepalive packets are received, BGP considers that the peer is in normal operation and maintains the BGP connection; if it receives incorrect Update and Keepalive packets, BGP will send Notification packets to notify the peer. And go to idle state.
  • Route-refresh packets will not change the state of BGP.
  • If it receives a TCP disconnect request, then BGP disconnects and goes to the idle state.

4. How BGP works

4.1 BGP routing information processing

  • IP routing table (IP-RIB): global routing information base, including all IP routing information
  • BGP routing table (Loc-RIB): BGP routing information base, including routing information selected by the local BGP Speaker
  • Neighbor table: peer neighbor list list
  • Adj-RIB-In: The unprocessed routing information base announced by the peer to the local BGP Speaker
  • Adj-RIB-Out: The routing information base announced by the local BGP Speaker to the specified peer

When receiving update packets from the peer, the router will store these update packets in the Routing Information Base (RIB) and indicate which peer it comes from (Adj-RIB-In) . After these update packets are filtered by the policy engine, the router will execute a path selection algorithm to determine the best path for each prefix.

The derived best path is stored in the local BGP RIB (LOc-RIB) and then submitted to the local IP routing table (IP-RIB) for installation consideration.

In addition to the best path received from the peer, Loc-RIB will also contain the BGP prefix injected by the current router (called locally initiated route) and selected as the best path. The content in Loc-RIB must pass through the output policy engine before being advertised to other peers. Only those routes that successfully pass the output strategy engine will be installed in the output RIB (Adj-RIB-Out).

4.2 Working process

The administrator defines the neighbor's IP address, and the premise requires that the neighbor's IP is reachable (IGP reachable); after the BGP protocol is started, the target port is 179 for the three-way TCP handshake to establish a TCP session;

  • After the session is established, send and receive open messages to establish a neighbor relationship and generate a neighbor table ;
  • After the neighbor relationship is established, the neighbors use update to share routing entries. After routing information is sent and received , the B GP table is generated locally ; the Bgp table is loaded with all routing entries sent and received locally;
  • Then the router loads the optimal path in the BGP table (not necessarily the best route, only the best BGP parameters) into the routing table ;

Convergence is complete, only the keeplive period can be kept alive;

Structural mutation:

  1. New network segment-BGP update source device will use Update to inform all local neighbors
  2. Disconnected network segment-BGP update source device will use Update to inform all local neighbors
  3. Unable to communicate-disconnect the neighbor relationship and TCP session when the 3min hold time expires, and then delete all the information learned from the neighbor;

The BGP update source device is not necessarily directly connected to the device that is disconnected or newly added network segment, but the first router to advertise the route to the BGP protocol;

4.3 Principles of interaction between peers

  1. BGP routes obtained from IBGP peers, BGP devices only advertise to its EBGP peers
  2. BGP routes obtained from EBGP peers, BGP devices advertise to all EBGP and IBGP peers
  3. When there are multiple valid routes to the same destination address, the BGP device only advertises the optimal route to the peer
  4. When routing updates, BGP devices only send updated BGP routes
  5. Routes learned from IBGP neighbors will only be announced to EBGP peers when the same route exists in IGP

Synchronization of IBGP and IGP

Before adding an IBGP route to the routing table and advertising it to EBGP peers, the IGP routing table is checked first. Only when IGP also knows the route of this route, will it be added to the routing table and advertised to EBGP peers.

Synchronization refers to the synchronization between IBGP and IGP, and its purpose is to avoid misleading routers in external ASs.

R4 learns the 10.0.0.0/24 network announced by R1 through BGP. Before R4 announces the network to R5, it will first check whether the 10. 0.0.0/24 network already exists in its IGP routing table. If the local IGP routing table entry of R4 has a 10.0.0.0/24 network, the network will be advertised to R5; if the local IGP routing table entry of R4 does not have a 10.0.0.0/24 network, the network cannot be advertised to R5.


BGP attribute problem: https://blog.csdn.net/weixin_43997530/article/details/106741945 

Guess you like

Origin blog.csdn.net/weixin_43997530/article/details/108388652