Tip

BGP vs. OSPF: When to use each protocol

BGP and OSPF are two of the most common routing protocols. While BGP excels with dynamic routing for large networks, OSPF offers more efficient path choice and convergence speed.

Border Gateway Protocol, or BGP, and Open Shortest Path First, or OSPF, are two of the most popular, standards-based dynamic routing protocols used around the world.

Although BGP and OSPF are both dynamic routing protocols and perform similar tasks, they calculate their routing decisions and advertise routes in different ways. Thus, some situations favor BGP as a protocol, while others prefer OSPF.

Let's learn more about how each routing protocol works and when one should be used over the other.

How does BGP work?

BGP is known as an exterior gateway protocol. It was designed to share routing information between disparate networks, known as autonomous systems (ASes). When multiple BGP-derived paths exist, the protocol chooses a path to send traffic based on several criteria, including the following:

  • the highest locally derived preference number, called a weight;
  • the path with the highest local preference;
  • path origin (network or aggregate);
  • shortest AS path to the destination network;
  • lowest multiexit discriminator; and
  • preferred paths coming from intra-AS, such as internal BGP, or extra-AS, such as external BGP.

A look at dynamic routing

With dynamic routing, a router creates and maintains a database of all routes the router knows about. The router calculates the optimal path to a remote network if two or more paths to the same network exist.

A router running a dynamic routing protocol shares its routing table information with neighboring routers that are configured to participate. The routers communicate using the same dynamic routing protocol and routing protocol instance.

Local administrators can manipulate many of these criteria to force traffic to a preferred path. However, when routers connect to neighbors in differing ASes, the local AS routers can't control which path neighboring routers will choose for inbound traffic. Thus, BGP has less control over manipulating traffic paths when communicating with external networks.

BGP is highly efficient and requires low compute and memory resources compared with most routing protocols. Therefore, it can handle dynamic routing for the largest networks. The internet, for example, uses BGP to interconnect ISPs and organizations that own a public AS and use multiple dynamic paths to the internet. This is useful if a primary ISP link fails because BGP will dynamically shift traffic destined to the internet to the secondary ISP link.

The following diagram shows an example company's internet architecture using AS 1010, which is connected to ISPs using AS 101 and AS 201. The router in AS 1010 runs BGP and has formed neighborships between the two ISPs. Depending on the path selection to remote networks on the internet, BGP will choose to send traffic out to ISP 1 or ISP 2. Additionally, if one of the two ISP links goes down, BGP will remove the downed path from the routing table and forward all traffic to the remaining active and healthy path.

diagram of BGP for internet redundancy
This diagram depicts how BGP can be used for redundancy when traffic travels to the internet.

BGP use cases

BGP is not only commonly deployed at the corporate internet edge, but also other network edge locations, such as the WAN or links between the corporate network and IaaS clouds. This is because BGP scales well, uses a deterministic path selection process and is the de facto standard when dynamically routing between networks that are owned and operated by separate organizations.

How does OSPF work?

Unlike BGP, OSPF is an interior gateway protocol that is most often used within a company's private LAN. OSPF is generally considered easier to deploy and manage compared with BGP and requires little manual adjustment to operate in most corporate settings.

OSPF maintains a database of locally derived and learned networks. If multiple OSPF paths to remote networks exist, OSPF chooses a path based on the lowest calculated cost or metric. The path cost to a remote network is based on the total calculated reference bandwidth divided by interface bandwidth. Reference bandwidth is a number used within OSPF to quantify the speed of a link.

How to calculate path cost

Path cost = total reference bandwidth / interface bandwidth

The lower the number, the faster the connection. For example, a 100 Mbps link has an OSPF reference bandwidth of 10, while a 1 Gbps link has a reference bandwidth of 1. Network admins can adjust this calculation as needed.

The bottom line is that OSPF uses path bandwidth as a major factor when determining path selection. Thus, it's more likely to choose the optimal path based on network performance when compared with BGP.

OSPF use cases

Unlike BGP, OSPF is fairly CPU- and memory-intensive to operate. As such, it isn't ideal for extremely large networks. While OSPF can scale to handle large networks with hundreds of routes, administrators must take care to reduce processing and memory overhead using manual adjustments, more so than with BGP.

OSPF has faster convergence times than BGP. Network convergence is the speed at which a router can adjust the path used to a destination network if a network outage occurs. Because of its convergence speed and ability to choose paths based on network performance, OSPF is a better choice within corporate LANs and private data centers.

In some situations, OSPF can also be used for dynamically learned WAN routes and connectivity to IaaS clouds. However, the following issues lend to the idea that OSPF is best used within the confines of a singularly managed corporate LAN:

  • a lack of multicast communication;
  • higher memory and CPU needs; and
  • a general lack of intercompany dynamic routing capabilities.

Where should BGP and OSPF be used in the enterprise?

While some exceptions exist, BGP is most often used for internet redundancy, WAN and IaaS environments. OSPF is primarily used for the LAN and data center but can also occasionally work in WAN and IaaS environments.

BGP vs. OSPF use case comparison
BGP is most often used for internet redundancy, WAN and IaaS environments, while OSPF is primarily used for the LAN and data center.

Next Steps

BGP tutorial: How the routing protocol works

BGP vs. EIGRP: What's the difference?

Dig Deeper on Network infrastructure

Unified Communications
Mobile Computing
Data Center
ITChannel
Close