OSPF Open-Shortest-Path-First (OSPF) is the most commonly used interior gateway routing protocol. It is a public routing protocol, while EIGRP is a Cisco proprietary protocol. OSPF is a complex link-state routing protocol. Link-state routing protocols generate routing updates only when a change occurs in the network topology. When a link changes state, the device that detected the change creates a link-state advertisement (LSA) concerning that link and sends to all neighboring devices using a special multicast address. Each routing device takes a copy of the LSA, updates its link-state database (LSDB), and forwards the LSA to all neighboring devices. OSPF routers use LSA to describe its link state.
OSPF supports the following features:
- The areas in OSPF are used to minimize the Central Processing Unit (CPU) and memory requirements.
- A simple cost metric that can operate to support up to six equal cost paths is used in OSPF.
- It uses authentication to make sure that the OSPF updates are secure and multicast updates to safeguard the bandwidth.
- OSPF provides faster convergence times, guaranteeing updates and propagating changes across the network.
- There are no limitations such as network diameter or hop count in OSPF.
- It provides the ability to tag OSPF information introduced from any autonomous systems.
- Variable-length subnet masking (VLSM) is also supported by OSPF.
OSPF packet formats:There are five different OSPF packet types. All of these packet types start with a standard 24-byte header. All OSPF packet types (other than the OSPF Hello packets) deal with lists of link state advertisements. For example, Link State Update packets employ the flooding of advertisements throughout the OSPF routing domain. All OSPF packets share a common protocol header. This header contains all the information necessary to determine whether the packet should be accepted for further processing.

The following descriptions summarize the header fields of an OSPF packet:
- Version number: Identifies the OSPF version used.
- Type: Identifies the OSPF packet type as one of the following:
- Hello: Establishes and maintains neighbor relationships.
- Database description: Describes the contents of the topological database. These messages are exchanged when an adjacency is initialized.
- Link-state request: Requests pieces of the topological database from neighbor routers. These messages are exchanged after a router discovers (by examining database-description packets) that parts of its topological database are outdated.
- Link-state update: Responds to a link-state request packet. These messages also are used for the regular dispersal of LSAs. Several LSAs can be included within a single link-state update packet.
- Link-state acknowledgment: Acknowledges link-state update packets.
- Packet length: Specifies the packet length, including the OSPF header, in bytes.
- Router ID: Identifies the source of the packet.
- Area ID: Identifies the area to which the packet belongs. All OSPF packets are associated with a single area.
- Checksum: Checks the entire packet contents for any damage suffered in transit.
- Authentication type: Contains the authentication type. All OSPF protocol exchanges are authenticated. The authentication type is configurable on per-area basis.
- Authentication: Contains authentication information.
- Data: Contains encapsulated upper-layer information.
The various OSPF routers are as follows:
- Internal router: All operational interfaces are maintained inside a single area in the internal router. It may belong to an OSPF area.
- Backbone router: It has at least one interface in area 0.
- The Area border router: One or more OSPF areas are connected to the backbone. So, at least one interface is in area 0 and the other is in a different area.
- Autonomous system boundary router: It injects external routing knowledge into an OSPF network.
OSPF is a nonproprietary link-state protocol. Like EIGRP, OSPF offers fast convergence and is a popular enterprise routing protocol.
OSPF data structures:OSPF uses four data structures as described in the following table:
| Data structure | Description |
| OSPF interface table | This table lists all the router interfaces that have been configured to participate in an OSPF routing process. |
| OSPF neighbor table | This table contains the OSPF neighbors that are learned via Hello packets. A neighbor is removed from this table if the neighbor has not been heard within the dead time interval or if the interface related to the neighbor goes down. |
| OSPF link-state database | This data structure contains topology information about the areas in which a router participates as well as about how to route traffic to networks located in other areas or autonomous systems. |
| OSPF Routing Information Base | The results of the OSPF shortest path first (SPF) calculations are stored in the OSPF Routing Information Base (RIB) stores. |
The OSPF link-state database contains the most ample set of information about the topology within a specific OSPF area. If a router is participating in more than one OSPF area, it will have more than one OSPF link-state database (one for each area). Because an OSPF link-state database contains the topology of an OSPF area, all the participating routers in that OSPF area should have identical OSPF link-state databases. Additionally, an OSPF router can store information about the redistributed routes in an OSPF link-state database.
An OSPF domain is divided into areas that are labeled with 32-bit area identifiers as follows:
- Backbone area: An OSPF backbone area consists of all networks in area ID 0.0.0.0, their attached routers, and all area border routers. The backbone itself does not have any area border routers.
- Stub area: A stub area is an area which does not receive route advertisements external to the autonomous system (AS) and routing from within the area is based entirely on a default route.
- Not-so-stubby area: A not-so-stubby area (NSSA) is a stub area that can import autonomous system (AS) external routes and can export them to the backbone. However, it cannot receive AS external routes from the backbone or other areas.
- Transit area: A transit area is used to pass the traffic from one adjacent area to the backbone (or to another area if the backbone is more than two hops away from an area).
- Totally stubby area: A totally stubby area (TSA) is similar to a stub area; however, this area does not allow summary routes in addition to the external routes.
- NSSA totally stubby area: NSSA totally stubby area is an additional standard functionality of an NSSA. It takes on the attributes of a totally stubby area.
OSPF operation:OSPF being a link-state protocol receives LSAs from the adjacent OSPF routers. The Dijkstra SPF algorithm takes the information contained in the LSAs to determine the shortest path to any destination within an area of the network. In a multiarea OSPF network, a backbone area (numbered area 0) must be present, and all the other areas must be connected to backbone area. A virtual link can be configured to connect a nonadjacent area with area 0 logically.
OSPF metric:OSPF uses the metric of
cost, which is a function of bandwidth. The cost metric can be calculated as follows:
cost = 100,000,000 / bandwidth (in kbps)
Let's discuss a scenario where OSPF has just been enabled on two routers, R1 & R2. Before sending Hello messages, they must first choose a router ID to tell their neighbors who they are.
A router ID is an IP address used to identify the router on the network. The router ID is selected in the following sequence:
- The highest IP address assigned to a loopback interface is selected as the router ID.
- If the loopback interface is not defined, the highest IP address of all active router's physical interfaces will be selected as the router ID.
- The router ID can be manually configured.
Suppose R1 has 2 loopback interfaces & 2 physical interfaces as given below:
- Loopback 0: 11.0.0.1
- Loopback 1: 10.0.0.1
- Fa0/0: 192.168.1.1
- Fa0/1: 200.168.1.1
Now you need to find out the router ID chosen by R1. As written above, the loopback interfaces are preferred to physical interfaces because they are never down, so the highest IP address of the loopback interfaces is chosen as the router-id. So R1 will choose the Loopback 2 IP address as the router-id, i.e., 11.0.0.1.
Suppose R2 has 2 physical interfaces as given below, but does not have any loopback interfaces:
- Fa0/0: 200.20.0.1 but it is shut down
- Fa0/1: 192.168.2.2 (is active)
Now you need to find the router ID for R2. In this case, the loopback interface is not defined, so the highest IP address of all active routers' physical interfaces will be selected as the router ID. You can see the Fa0/0 has a higher IP address, but the interface is shut down, so R2 will choose Fa0/1 as its router ID, i.e., 192.168.2.2.
Now both the routers have the router ID, and they can send Hello packets on all OSPF-enabled interfaces to determine if there are any neighbors on those links.
Key Points to Remember:
- OSPF works by using the Dijkstra algorithm.
The entire routing table is transmitted once every 30 minutes.
- HELLO messages are used to maintain adjacent neighbors.
- By default, OSPF routers send Hello packets every 10 seconds on multiaccess and point-to-point segments and every 30 seconds on non-broadcast multiaccess (NBMA) segments (like Frame Relay, X.25, ATM).
- OSPF is a classless routing protocol because it does not assume the default subnet masks are used. It sends the subnet mask in the routing update.
- OSPF supports VLSM and route summarization.
- OSPF uses COST as a metric which CISCO defines as the inverse of the bandwidth.