Introduction: BGP between autonomous systems
Routing protocols such as RIP, OSPF, and EIGRP are known as . They manage traffic flow within one AS. Routers exchange information about reachable prefixes, costs, and link state, then calculate routes according to the rules of that IGP.
When a packet must cross several independent networks, routers need reachability information for prefixes in other ASes. One operator's IGP does not describe the complete inter-AS path. A protocol is needed that exchanges reachability while considering policies and relationships between operators.
This role is provided by BGP (Border Gateway Protocol). BGP is an used to exchange reachability between ASes. Its decisions do not reduce to one metric; local policy selects a permitted path that meets the operator's requirements across interconnected ASes.
BGP exchanges IP prefixes and attributes that describe their paths. A router stores information received from peers, applies local policy, selects a route for use, and advertises permitted information according to export policy. BGP decisions concern destination-based forwarding.
Autonomous systems and ASNs
The basic scope of BGP is the Autonomous System (AS). The Internet consists of independent networks that present their routing policies to other operators.
An contains IP networks and routers under one administration.
- It operates an internal network, commonly with an IGP such as OSPF.
- It is managed by one organization, such as an ISP, a technology company, or a university.
- It has border routers that connect it to other ASes.
- It establishes relationships with neighboring ASes, including peering and transit agreements.
Each AS has a unique Autonomous System Number (ASN), assigned through the Internet registry system. BGP exchanges prefixes and the AS sequence through which an advertisement has passed.
AS boundaries follow administration and routing policy, so one operator can use several IGPs or metric sets. To external peers it still presents a coherent reachability plan. The ASN lets routers identify that domain in AS_PATH.
Path vector and AS_PATH
BGP uses a path-vector routing algorithm. An advertisement contains the prefix and information about the autonomous systems through which the route information has passed, allowing loops to be detected at the AS level.
A distance-vector protocol such as RIP tells neighbors a destination and a metric. BGP advertises a prefix together with the sequence of AS numbers through which the route information has passed. This information is stored in the AS_PATH attribute.
Example: route advertisement propagation
- A router in AS 65100, where the servers for example.com reside, advertises its network . The advertisement contains an AS_PATH of (65100).
- Its neighbor, a router in AS 65200 (a transit provider), receives this advertisement. To share it with its own neighbors, it prepends its own number to the path. It now advertises network with an AS_PATH of (65200, 65100).
- Its other neighbor, a router in AS 65300, receives this. To advertise it further, it prepends its number again, advertising the route with an AS_PATH of (65300, 65200, 65100).
Each router receiving the UPDATE sees the prefix and the AS sequence in AS_PATH. It can use that sequence to compare path length and check whether its own ASN already occurs in the path.
An UPDATE can contain reachable prefixes, withdrawn prefixes, and shared path attributes. A router does not automatically advertise every learned route; import and export rules for the specific peer constrain its decision.
Loop detection with AS_PATH
A router checks AS_PATH before selecting a route. If its own ASN already occurs in the attribute, the route is excluded from the decision process. This limits loops between ASes and differs from the counting-to-infinity behavior associated with simple distance-vector protocols.
BGP sessions between peers
BGP exchanges information through controlled, point-to-point sessions. Administrators configure routers to form peering sessions with specific routers. These routers are known as BGP neighbors or peers.
BGP uses the Transmission Control Protocol (TCP) on port . TCP provides ordered transport, retransmission, and acknowledgements, so BGP does not need to define those functions in its routing-update messages.
After the session is formed, peers exchange an initial set of routes allowed by export policy and then send incremental updates when information changes. BGP does not require periodic transmission of the complete routing table. KEEPALIVE messages and the Hold Time detect a lost session.
External vs. Internal BGP (eBGP vs. iBGP)
BGP sessions have two basic forms, depending on the peers' AS membership:
- eBGP (External BGP):
This is a session between routers in different Autonomous Systems. It exchanges routes between independent operators and networks. The peers are often directly connected, but a multihop eBGP session is also possible. When advertising to an external peer, the router adds its own ASN to AS_PATH.
- iBGP (Internal BGP):
This is a session between routers within the same Autonomous System. After a route is learned through eBGP, iBGP distributes it to other routers in that AS under local policy. The classic model uses a full iBGP mesh, while route reflectors reduce the number of sessions. When a route is advertised over iBGP, the AS_PATH is not modified.
BGP message types
BGP peers communicate using four message types over their TCP connection.
- OPEN Message: This is sent after the TCP connection is established. It contains the BGP identifier, ASN, and session parameters including the Hold Time value. After both sides accept OPEN, they can exchange UPDATE messages.
- UPDATE Message: It advertises new routes, withdraws routes, or performs both operations in one message. A single UPDATE can carry multiple prefixes with the same path attributes. It carries AS_PATH and other attributes used by local policy. BGP sends incremental updates when information changes instead of periodically refreshing the complete table.
- KEEPALIVE Message:If a router has no other messages to send, it periodically sends a small KEEPALIVE so that the neighbor's Hold Time value does not expire. The interval follows the negotiated Hold Time and is normally no more than one third of that value. When Hold Time is zero, periodic KEEPALIVE messages are not sent.
- NOTIFICATION Message: If a router detects an error, such as an invalid message or an expired Hold Time, it sends a NOTIFICATION with an error code and reason. It then closes the BGP session.
BGP route selection
BGP does not select a route with one metric. The decision process first applies local policy and assigns a degree of preference, then compares path attributes and resolves ties. Important criteria include:
A route must have a resolvable NEXT_HOP before it can be selected for the local routing table. After local preference, the standard process compares AS_PATH and ORIGIN, while MED is compared only between routes learned from the same neighboring AS. An implementation can extend the process with its own criteria.
- AS_PATH length: After preference has been considered, BGP prefers a shorter AS_PATH, meaning a route that crosses fewer ASes.
- Local preference (LOCAL_PREF): An attribute used within one AS to indicate the preferred exit for traffic.
- Origin code (ORIGIN): Indicates how the route information was introduced into BGP, for example as internal information or through redistribution.
Conclusion: BGP's role
BGP differs from IGPs in scope and route-selection method. Convergence time depends on topology, policy, timers, and implementation, so it has no single universal value. BGP supports scalability, stability, and policy control.
The path-vector algorithm, TCP transport, and configured peer relationships support global prefix exchange. Path attributes let operators implement business and technical policies, so route selection depends on both path information and local rules. BGP is the main protocol for exchanging routes between independent ASes on the Internet.
Correct operation requires consistent import and export rules, resolvable next-hop addresses, and current session state. A policy change can select a different route without a topology change because BGP decisions also depend on attributes and configuration.