Border Gateway Protocol (BGP)

The path-vector EGP that powers the Internet, based on path attributes and policies.

Introduction: From Internal Roads to International Treaties

The routing protocols we have discussed so far, such as RIP, OSPF, and EIGRP, are known as . They are designed to manage traffic flow within a single organization's network. Think of an IGP as the internal road management system for a single country. It knows all the local roads, highways, and the best ways to get from London to Manchester. It is optimized for speed, efficiency, and rapid reaction to traffic jams (link failures).

But what happens when a packet needs to travel from London to a server in Tokyo? That packet must cross international borders, passing through networks managed by different companies, organizations, and countries. The internal road map of the United Kingdom is useless for navigating the internal road map of Japan. A different kind of protocol is needed: one that operates not on speed, but on agreements, policies, and trust between these massive, independent networks.

This is the world of BGP (Border Gateway Protocol). BGP is the sole that makes the global internet function. It is not concerned with finding the fastest path, but with finding a valid, policy-compliant path through a global web of interconnected networks. It is the language of international diplomacy for the internet.

Autonomous Systems: The Nations of the Internet

To understand BGP, one must first understand its fundamental building block: the Autonomous System (AS). The internet is not one giant network; it is a "network of networks." Each of these independent networks is an AS.

An can be thought of as a country.

  • It has its own internal government and road system (its own internal network run with an IGP like OSPF).
  • It is managed by a single organization (like an Internet Service Provider such as Comcast or BT, a tech giant like Google, or a large university).
  • It has clearly defined borders and border crossings (its "border" routers).
  • It has diplomatic relations (peering agreements) with its neighboring countries (other ASes).

Every AS is assigned a unique number, the Autonomous System Number (ASN), by a regional internet registry. BGP's entire job is to exchange information about which networks are reachable through which sequence of ASes.

Path Vector: Routing by Itinerary, Not Rumor

BGP uses a unique routing algorithm called Path Vector. This is an evolution of the Distance Vector algorithm used by RIP, but with a critical enhancement that makes it infinitely more scalable and robust.

While a Distance Vector protocol like RIP only tells its neighbors a destination and a metric ("I can reach network X in 3 hops"), a Path Vector protocol provides the full itinerary. It advertises a destination network along with the entire list of ASes that a packet must traverse to reach it. This list is known as the AS_PATH attribute.

Example: The Journey of a Route Advertisement

  1. A router in AS 65100, where the servers for example.com reside, advertises its network 203.0.113.0/24203.0.113.0/24. The advertisement contains an AS_PATH of (65100).
  2. 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 203.0.113.0/24203.0.113.0/24 with an AS_PATH of (65200, 65100).
  3. 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).

At each step, any router receiving this update sees not just where the network is, but the exact sequence of "countries" the message has traveled through to get there.

Built-in Loop Prevention

This mechanism provides a simple and completely effective way to prevent routing loops on a global scale. The rule is simple: if a router receives a BGP update and sees its own AS number already in the AS_PATH attribute, it immediately discards the update. This means a route advertisement can never loop back to an AS it has already visited, completely eliminating the "counting to infinity" problem that plagued RIP.

BGP Communication: Reliable Sessions Between Peers

Unlike IGPs that often broadcast or multicast their information, BGP establishes highly controlled, one-to-one communication sessions. Routers running BGP are manually configured by administrators to form relationships, called peering sessions, with other specific routers. These routers are known as BGP neighbors or peers.

BGP insists on reliability. For this reason, all BGP sessions run over the Transmission Control Protocol (TCP) on port 179179. Using TCP ensures that every routing update is delivered correctly, in sequence, and without errors. The stability of the entire internet depends on this reliability.

External vs. Internal BGP (eBGP vs. iBGP)

BGP sessions come in two flavors, depending on where the peers are located:

  • eBGP (External BGP):

    This is a session between routers in different Autonomous Systems. This is the core function of BGP: exchanging routes between providers, companies, and countries. The peers are typically directly connected. When a route is advertised over an eBGP session, the router prepends its own ASN to the AS_PATH.

  • iBGP (Internal BGP):

    This is a session between routers within the same Autonomous System. This might seem strange: why use an external protocol internally? The reason is consistency. Once a route is learned from an external neighbor via eBGP, that information must be distributed to all other routers within that AS, so they all know how to reach that external network. iBGP is the mechanism for this internal distribution. When a route is advertised over an iBGP session, the AS_PATH is not modified.

BGP Message Types

BGP peers communicate using four primary message types, all sent over their reliable TCP connection.

  • OPEN Message: This is the first message sent after the TCP connection is established. It's the BGP handshake. The routers use it to identify themselves, agree on parameters like their ASN, and set the Hold Timer (how long to wait without a message before declaring the neighbor dead). If both sides agree, the session moves to the next state.
  • UPDATE Message: This is the workhorse of BGP. It is used to advertise new routes, withdraw old routes that are no longer valid, or both. A single UPDATE message can carry reachability information for multiple networks that share the same path attributes. This message is where all the policy information (the AS_PATH and other attributes) is contained. Unlike IGPs, updates are sent only when something changes.
  • KEEPALIVE Message: If a router has no updates to send for a while, it can't remain silent, as its neighbor's Hold Timer might expire. To prevent this, routers periodically send a very small KEEPALIVE message, which acts as a heartbeat, telling the neighbor "I'm still here and the connection is healthy." By default, this is sent every 60 seconds.
  • NOTIFICATION Message: If a router detects an error, such as an invalid message or an expiring Hold Timer, it sends a NOTIFICATION message to its peer, indicating the reason for the error. Immediately after sending this message, it closes the BGP session. This is BGP's mechanism for error handling.

Conclusion: The Slow, Deliberate, and Essential Protocol

BGP is fundamentally different from the IGPs we have studied. It is not designed for speed. Its convergence can be measured in minutes, not seconds. It doesn't find the "shortest" path in a technical sense. Instead, BGP is designed for scalability, stability, and policy control.

Its Path Vector algorithm, reliable TCP transport, and manual peering configuration create a robust system that can manage a global routing table with hundreds of thousands of routes without collapsing into loops. Its power comes from its rich set of path attributes, which allow network operators to implement complex business and technical policies, turning routing from a simple metric calculation into a form of programmable traffic engineering. BGP is the indispensable protocol that holds the fabric of the global internet together.

    Border Gateway Protocol (BGP) | Teleinf Edu