OSPF (Open Shortest Path First) is an Interior Gateway Protocol (IGP). It is a link-state routing protocol that uses the Shortest Path First (SPF) algorithm to calculate the best route. OSPF routing protocol is an open standard, so various network vendors implement it.
Here are the most important features of OSPF:
- A classless routing protocol
- Supports VLSM, CIDR, manual route summarization, equal cost load balancing
- Incremental updates are supported
- Uses only one parameter as the metric – the interface cost.
- The administrative distance of OSPF routes is, by default, 110.
- Uses multicast addresses 126.96.36.199 and 188.8.131.52 for routing updates.
Routers running OSPF protocol have to establish neighbor relationships before exchanging routes. Because OSPF is a link-state routing protocol, neighbors don’t exchange routing tables. Instead, they exchange information about network topology. Each OSPF router then runs SPF or Dijkstra algorithm to calculate the best routes and adds those to the routing table. Because each router knows the entire topology of a network, the chance for a routing loop to occur is minimal.
Each OSPF router stores routing and topology information in three tables:
- Neighbor table – stores information about OSPF neighbors
- Topology table – stores the topology structure of a network
- Routing table – stores the best routes
OSPF routers need to establish a neighbor relationship before exchanging routing updates. OSPF neighbors are dynamically discovered by sending Hello packets from each OSPF-enabled interface on a router. Hello packets are sent to the multicast IP address of 184.108.40.206.
The process is explained in the following figure:
Routers R1 and R2 are directly connected. After OSPF is enabled, both routers send Hellos to establish a neighbor relationship. You can verify that the neighbor relationship has been established by typing the ‘show ip ospf neighbors’ command.
R1#show ip ospf neighbor Neighbor ID Pri State Dead Time Address Interface 220.127.116.11 1 FULL/DR 00:00:30 192.168.0.2 FastEthernet0/0
In the example above, you can see that the router-id of R2 is 18.104.22.168. Each OSPF router is assigned a router ID. A router ID is determined by using one of the following:
1. Using the router-id command under the OSPF process.
2. Using the highest IP address of the router’s loopback interfaces.
3. Using the highest IP address of the router’s physical interfaces.
The following fields in the Hello packets must be the same on both routers in order for routers to become neighbors:
- area id
- hello and dead interval timers
- area stub flag
By default, OSPF sends hello packets every 10 seconds on an Ethernet network (Hello interval). A dead timer is four times the value of the hello interval, so if a router on an Ethernet network doesn’t receive at least one Hello packet from an OSPF neighbor for 40 seconds, the router declares that neighbor to be down.
OSPF Neighbor States
Before establishing a neighbor relationship, OSPF routers need to go through several state changes. These states are explained below:
1. Init state – a router has received a Hello message from the other OSPF router
2. 2-way state – the neighbor has received the Hello message and replied with a Hello message of his own
3. Exstart state – beginning of the Link State Database (LSDB) exchange between both routers. Routers are starting to exchange link state information.
4. Exchange state – DBD (Database Descriptor) packets are exchanged. DBDs contain LSAs headers. Routers will use this information to see what LSAs need to be exchanged.
5. Loading state – one neighbor sends LSRs (Link State Requests) for every network it doesn’t know about. The other neighbor replies with the LSUs (Link State Updates), which contain information about requested networks. After all the requested information have been received, other neighbor goes through the same process
6. Full state – both routers have the synchronized database and are fully adjacent to each other.
OSPF Routing Protocol Areas
OSPF uses the concept of areas. An area is a logical grouping of contiguous networks and routers. All routers in the same area have the same topology table, but they don’t know about routers in the other areas. The main benefits of creating areas are that the size of the topology and the routing table on a router is reduced, less time is required to run the SPF algorithm, and routing updates are also reduced.
Each area in the OSPF network has to connect to the backbone area (area 0). All routers inside an area must have the same area ID to become OSPF neighbors. A router with interfaces in more than one area (area 0 and area 1, for example) is called Area Border Router (ABR). A router that connects an OSPF network to other routing domains (EIGRP network, for example) is called Autonomous System Boundary Router (ASBR).
To better understand the concept of OSPF areas, consider the following example.
All routers are running OSPF. Routers R1 and R2 are inside the backbone area (area 0). Router R3 is an ABR because it has interfaces in two areas, namely Area 0 and Area 1. Routers R4 and R5 are inside Area 1. Router R6 is an ASBR because it connects the OSPF network to another routing domain (an EIGRP domain in this case). If the R1’s directly connected subnet fails, router R1 sends the routing update only to R2 and R3 because all routing updates are localized inside the area.
LSA, LSU, and LSR
OSPF routers use the LSAs (Link-State Advertisements) to exchange topology information. Each LSA contains routing and topology information to describe a part of an OSPF network. When two neighbors decide to exchange routes, they send each other a list of all LSAs in their respective topology databases. Each router then checks its topology database and sends a Link State Request (LSR) message requesting all LSAs not found in its topology table. The other router responds with the Link State Update (LSU) containing all LSAs the other neighbor requested.
The concept is explained in the following example:
After configuring OSPF on both routers, routers exchange LSAs to describe their topology database. Router R1 sends an LSA header for its directly connected network 10.0.1.0/24. Router R2 checks its topology database and determines that it doesn’t have information about that network. Router R2 then sends a Link State Request message requesting further information about that network. Router R1 responds with Link State Update, which contains information about subnet 10.0.1.0/24, such as next hop address, cost, etc.
Download our Free CCNA Study Guide PDF for complete notes on all the CCNA 200-301 exam topics in one book.
We recommend the Cisco CCNA Gold Bootcamp as your main CCNA training course. It’s the highest rated Cisco course online with an average rating of 4.8 from over 30,000 public reviews and is the gold standard in CCNA training: