In order to facilitate the management of the expanding network, the network is divided into different ASs (Autonomous System). In the early days, EGP (Exterior Gateway Protocol) was used to dynamically exchange routing information between ASs. However, EGP is designed to be relatively simple. It only publishes the routing information that is reachable on the network, and does not optimize the routing information. At the same time, it does not consider loop avoidance and other issues, so it will soon fail to meet the requirements of network management.
BGP is another exterior gateway protocol designed to replace the original EGP. Different from the original EGP, BGP can perform route optimization, avoid routing loops, transmit routes more efficiently and maintain a large amount of routing information.
- IGP routing protocols such as OSPF and IS-IS are widely used in organizational networks. With the expansion of network scale, the number of routes in the network continues to grow, and IGP can no longer manage large-scale networks. The concept of AS was born.
- AS refers to a set of devices that use a unified route selection policy under the management of the same organization.
- Different ASs are distinguished by their AS numbers, which are represented in 16-bit and 32-bit modes. IANA is responsible for the distribution of AS numbers.
- When communication between different ASs is required, which routing protocol should be used to transmit routes between ASs?
- BGP uses TCP as the transport layer protocol, and the TCP port number is 179. BGP sessions between routers are established based on TCP connections.
- A router running BGP is called a BGP speaker, or BGP router.
- Two routers that establish a BGP session are peers with each other, and the BGP peers exchange BGP routing tables.
- BGP routers only send incremental BGP routing updates, or perform triggered updates (not periodic updates).
- BGP can carry a large number of routing prefixes and can be applied in large-scale networks.
- BGP is named as the Path-Vector Routing Protocol.
- Each BGP route carries multiple path attributes. BGP can control path selection through these path attributes. Unlike IS-IS and OSPF, which can only control path selection through Cost, BGP has rich path selection. The most suitable path control method can be selected in different scenarios.
Different from protocols such as OSPF and IS-IS, BGP sessions are established based on TCP. The two routers that establish a BGP peer relationship are not required to be directly connected.
There are two types of peer relationships in BGP: EBGP and IBGP:
EBGP (External BGP): BGP peer relationship between BGP routers located in different autonomous systems. To establish an EBGP peer relationship between two routers, two conditions must be met:
- The ASs of the two routers are different (that is, the AS numbers are different).
- When configuring EBGP, the peer IP address specified by the peer command requires that the route is reachable and the TCP connection can be established correctly.
IBGP (Internal BGP): BGP adjacency between BGP routers located in the same autonomous system.
BGP State Machine
After configuring BGP peers, the device will attempt to establish a TCP connection. The router will work according to the state machine shown in the following figure.
- 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 peers, and goes to the connect state.
- In the Connect state, BGP starts the Connect Retry timer and waits for TCP to complete the connection.
–> If the TCP connection is successful, then BGP sends an open message to the peer and goes to the opensent state.
-> If the TCP connection fails, then BGP goes to the Active state and tries to connect repeatedly.
–> If the connection retransmission timer expires and BGP still does not receive a response from the BGP peer, then BGP continues to try to establish a TCP connection with other BGP peers and stays in the Connect state.
- In the Active state, BGP is always trying 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 goes 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 BGP peer, then BGP goes to the Connect state.
- In the OpenSent state, BGP waits for the peer’s Open message, and checks the AS number, version number, authentication code, etc. in the received Open message.
–> If the received open message is correct, then BGP sends a Keepalive message and goes to the OpenConfirm state
–> If the received Open message is found to be wrong, then BGP sends a Notification message to the peer and goes to the Idle state
- In the OpenConfirm state, BGP waits for Keepalive or Notification packets.
–> If a keepalive message is received, go to the Established state,
–> If a Notification message is received, go to the Idle state.
- In the Established state, BGP can exchange Update, Keepalive, Route-refresh and Notification packets with peers.
–> If the correct Update or keepalive message is received, then BGP considers that the peer is in a normal operation state and will maintain the BGP connection.
–> If an incorrect Update or Keepalive message is received, BGP sends a Notification message to notify the peer and goes to the Idle state.
–> If a Notification message is received, then BGP goes to the Idle state.
–> If a TCP disconnection notification is received, then BGP disconnects and goes to the Idle state.
–>Route-refresh packets do not change the BGP state.
Generation of BGP Routing Table
Different from the IGP routing protocol, BGP itself does not discover, calculate or generate routes. BGP injects the routes in the IGP routing table into the BGP routing table and transmits them to BGP peers through Update packets.
Interaction principles between BGP peers: (9 principles)
The BGP device adds the optimal route to the BGP routing table to form a BGP route. After a BGP device establishes a neighbor relationship with a peer, it adopts the following interaction principles:
- The BGP route obtained from the IBGP peer, the BGP device only advertises it to its EBGP peer
- The BGP route obtained from the EBGP peer, the BGP device advertises to all its EBGP and IBGP peers
- When there are multiple valid routes to the same destination address, the BGP device only advertises the optimal route to peers
- When the route is updated, the BGP device only sends the updated BGP route
- All routes sent by peers will be received by BGP devices
- The next hop of all EBGP peers changes during the transfer process
- The next hop of all IBGP peers remains unchanged during the transfer process
- The default TTL value for EBGP delivery is 1
- The default TTL value for IBGP delivery is 255