OSPF
- OSPFv2 is used for IPv4 networks.
- OSPFv3 is used for IPv6 networks.
- There is both single-area and multiarea OSPF.
- OSPF has faster convergence and scales better than RIP.
- With OSPF, the routing domain is divided into distinct areas.
- A link can be:
- An interface on a router.
- A network segment that connects two routers.
- A stub network.
- Information about the state of a link is known as a link-state.
- All link-state information includes the network prefix, prefix length, and cost.
Single-Area OSPFv2
Components of OSPF
Routing Protocol Messages
- Hello packet.
- Database description packet.
- Link-state request packet.
- Link-state update packet.
- Link-state acknowledgment packet.
Data Structures
These tables contain a list of neighboring routers to exchange routing information. The tables are kept and maintained in RAM.
- Adjacency database - This creates the neighbor table.
- List of all neighbor routers to which a router has established bidirectional communication.
- This table is unique for each router.
- Can be viewed using the
show ip ospf neighborcommand.
- Link-state database (LSDB) - This creates the topology table.
- Lists information about all other routers in the network.
- This database represents the network topology.
- All routers within an area have identical LSDB.
- Can be viewed using the
show ip ospf databasecommand.
- Forwarding database - This creates the routing table.
- List of routes generated when an algorithm is run on the link-state database.
- The routing table of each router is unique and contains information on how and where to send packets to other routers.
- Can be viewed using the
show ip routecommand.
Algorithm
- Used Dijkstra shortest-path first (SPF) algorithm.
- The SPF algorithm creates an SPF tree by placing each router at the root of the tree and calculating the shortest path to each node.
- The SPF tree is then used to calculate the best routes.
- OSPF places the best routes into the forwarding database, which is used to make the routing table.
Link-State Operation
- To maintain routing information, OSPF routers complete a generic link-state routing process to reach a state of convergence.
- Each link between routers is labeled with a cost value.
- In OSPF, cost is used to determine the best path to the destination.
Link-State Routing Steps
-
Establish Neighbor Adjacencies
-
OSPF-enabled routers must recognize each other on the network before they can share information.
-
An OSPF-enabled router sends Hello packets out all OSPF-enabled interfaces to determine if neighbors are present on those links.
-
If a neighbor is present, the OSPF-enabled router attempts to establish a neighbor adjacency with that neighbor.
-
-
Exchange Link-State Advertisements
-
After adjacencies are established, routers then exchange link-state advertisements (LSAs).
-
LSAs contain the state and cost of each directly connected link.
-
Routers flood their LSAs to adjacent neighbors.
-
Adjacent neighbors receiving the LSA immediately flood the LSA to other directly connected neighbors, until all routers in the area have all LSAs.
-
-
Build the Link State Database
-
After LSAs are received, OSPF-enabled routers build the topology table (LSDB) based on the received LSAs.
-
This database eventually holds all the information about the topology of the area.
-
-
Execute the SPF Algorithm
-
Routers then execute the SPF algorithm.
-
The SPF algorithm creates the SPF tree.
-
-
Choose the Best Route
-
After the SPF tree is built, the best paths to each network are offered to the IP routing table.
-
The route will be inserted into the routing table unless there is a route source to the same network with a lower administrative distance, such as a static route.
-
Routing decisions are made based on the entries in the routing table.
-
Single-Area and Multiarea OSPF
-
To make OSPF more efficient and scalable, OSPF supports hierarchical routing using areas.
-
An OSPF area is a group of routers that share the same link-state information in their LSDBs.
-
OSPF can be implemented in one of two ways, as follows:
-
Single-Area OSPF - All routers are in one area. Best practice is to use area 0.
-
Multiarea OSPF - OSPF is implemented using multiple areas, in a hierarchical fashion. All areas must connect to the backbone area (area 0). Routers interconnecting the areas are referred to as Area Border Routers (ABRs).
-
Multiarea OSPF
-
With multiarea OSPF, one large routing domain can be divided into smaller areas, to support hierarchical routing.
-
Routing still occurs between the areas (interarea routing).
-
While many of the processor intensive routing operations, such as recalculating the database, are kept within an area.
Multiarea OSPF and area changes
-
Any time a router receives new information about a topology change within the area (including the addition, deletion, or modification of a link) the router must rerun the SPF algorithm, create a new SPF tree, and update the routing table.
-
The SPF algorithm is CPU-intensive and the time it takes for calculation depends on the size of the area.
-
Note: Routers in other areas receive updates regarding topology changes, but these routers only update the routing table, not rerun the SPF algorithm.
-
Too many routers in one area would make the LSDBs very large and increase the load on the CPU.
-
Therefore, arranging routers into areas effectively partitions a potentially large database into smaller and more manageable databases.
Advantages of OSPF hierarchical-topology desing
- Smaller routing tables.
- This is because network addresses can be summarized between areas.
- Route summarization is not enabled by default.
- Reduced link-state update overhead.
- Smaller areas minimizes processing and memory requirements.
- Reduced frequency of SPF calculations.
- Multiarea OSPF localize the impact of a topology change within an area.
OPSFv3
-
OSPFv3 is the OSPFv2 equivalent for exchanging IPv6 prefixes.
-
Note: With the OSPFv3 Address Families feature, OSPFv3 includes support for both IPv4 and IPv6.
-
OSPFv2 runs over the IPv4 network layer, communicating with other OSPF IPv4 peers, and advertising only IPv4 routes.
-
OSPFv3 has the same functionality as OSPFv2, but uses IPv6 as the network layer transport, communicating with OSPFv3 peers and advertising IPv6 routes.
-
OSPFv3 has separate processes from its IPv4 counterpart.
-
The processes and operations are basically the same as in the IPv4 routing protocol, but run independently.
-
OSPFv2 and OSPFv3 each have separate adjacency tables, OSPF topology tables, and IP routing table.
OSPF Packets
Types of OSPF Packets
-
Link-state packets are the tools used by OSPF to help determine the fastest available route for a packet.
-
OSPF uses the following link-state packets (LSPs) to establish and maintain neighbor adjacencies and exchange routing updates.
-
Type 1: Hello packet - This is used to establish and maintain adjacency with other OSPF routers.
-
Type 2: Database Description (DBD) packet - This contains an abbreviated list of the LSDB of the sending router and is used by receiving routers to check against the local LSDB. The LSDB must be identical on all link-state routers within an area to construct an accurate SPF tree.
-
Type 3: Link-State Request (LSR) packet - Receiving routers can then request more information about any entry in the DBD by sending an LSR.
-
Type 4: Link-State Update (LSU) packet - This is used to reply to LSRs and to announce new information. LSUs contain several different types of LSAs.
-
Type 5: Link-State Acknowledgment (LSAck) packet - When an LSU is received, the router sends an LSAck to confirm receipt of the LSU. The LSAck data field is empty.
-
Link-State Updates
-
Routers initially exchange Type 2 DBD packets, which is an abbreviated list of the LSDB of the sending router. It is used by receiving routers to check against the local LSDB.
-
A Type 3 LSR packet is used by the receiving routers to request more information about an entry in the DBD.
-
The Type 4 LSU packet is used to reply to an LSR packet.
-
A Type 5 packet is used to acknowledge the receipt of a Type 4 LSU.
-
LSUs are also used to forward OSPF routing updates, such as link changes.
-
An LSU packet can contain 11 different types of OSPFv2 LSAs.
-
OSPFv3 renamed several of these LSAs and also contains two additional LSAs.
-
Note: The difference between the LSU and LSA terms can sometimes be confusing because these terms are often used interchangeably. However, an LSU contains one or more LSAs.
Types of LSAs
LSAs contain route information for destination networks.
- 1 - Router LSAs.
- 2 - Network LSAs.
- 3 or 4 - Summary LSAs.
- 5 - Autonomous System External LSAs.
- 6 - Mulicast OSPF LSAs.
- 7 - Defined for Not-So-Stubby Areas.
- 8 - External Attributes LSA for Border Gateway Patrol (BGPs).
Hello Packets
-
Discover OSPF neighbors and establish neighbor adjacencies.
-
Advertise parameters on which two routers must agree to become neighbors.
-
Elect the Designated Router (DR) and Backup Designated Router (BDR) on multiaccess networks like Ethernet. Point-to-point links do not require DR or BDR.
OSPF Hello Packet Content

OSPF Packet Headers
-
Type - This identifies the type of packet. A value 1 indicates a Hello packet. A value 2 identifies a DBD packet, 3 an LSR packet, 4 an LSU packet, and 5 an LSAck packet.
-
Router ID - A 32-bit value expressed in dotted decimal notation (like an IPv4 address) is used to uniquely identify the originating router.
-
Area ID - This is the number of the area from which the packet originated.
OSPF Hello Packets
-
Network Mask - This is the subnet mask associated with the sending interface.
-
Hello Interval - This specifies the frequency, in seconds, at which a router sends Hello packets. The default Hello interval on multiaccess networks is 10 seconds. This timer must be the same on neighboring routers; otherwise, an adjacency is not established.
-
Router Priority - This is used in a DR/BDR election. The default priority for all OSPF routers is 1, but can be manually altered from 0 to 255. The higher the value, the more likely the router becomes the DR on the link.
-
Dead Interval - This is the time, in seconds, that a router waits to hear from a neighbor before declaring the neighboring router out of service. By default, the router Dead Interval is four times the Hello interval. This timer must be the same on neighboring routers; otherwise, an adjacency is not established.
-
Designated Router (DR) - This is the router ID of the DR.
-
Backup Designated Router (BDR) - This is the router ID of the BDR.
-
List of Neighbors - This list identifies the router IDs of all adjacent routers.
OSPF Operation
OSPF Operational States
When an OSPF router is initially connected to a network, it attempts to:
- Create adjacencies with neighbors.
- Exchange routing information.
- Calculate the best routes.
- Reach convergence.
Description of Operational States
-
Down State.
- No Hello packets received = Down.
- Router sends Hello packets.
- Transition to Init state.
-
Init State.
- Hello packets are received from the neighbor.
- They contain the Router ID of the sending router.
- Transition to Two-Way state.
-
Two-Way State.
- In this state, communication between the two routers is bidirectional.
- On multiaccess links, the routers elect a DR and a BDR.
- Transition to ExStart state.
-
ExStart State.
- On point-to-point networks, the two routers decide which router will initiate the DBD packet exchange and decide upon the initial DBD packet sequence number.
-
Exchange State.
- Routers exchange DBD packets.
- If additional router information is required then transition to Loading; otherwise, transition to the Full state.
-
Loading State.
- LSRs and LSUs are used to gain additional route information.
- Routes are processed using the SPF algorithm.
- Transition to the Full state.
-
Full State.
- The link-state database of the router is fully synchronized.
Establish Neighbour Adjacencies
-
When OSPF is enabled on an interface, the router must determine if there is another OSPF neighbor on the link.
-
To accomplish this, the router sends a Hello packet that contains its router ID out all OSPF-enabled interfaces.
-
The Hello packet is sent to the reserved All OSPF Routers IPv4 multicast address 224.0.0.5.
-
Only OSPFv2 routers will process these packets.
-
The OSPF router ID is used by the OSPF process to uniquely identify each router in the OSPF area.
-
A router ID is a 32-bit number formatted like an IPv4 address and assigned to uniquely identify a router among OSPF peers.
-
When a neighboring OSPF-enabled router receives a Hello packet with a router ID that is not within its neighbor list, the receiving router attempts to establish an adjacency with the initiating router.
Synchronizing OSPF Databases
-
After the Two-Way state, routers transition to database synchronization states.
-
While the Hello packet was used to establish neighbor adjacencies, the other four types of OSPF packets are used during the process of exchanging and synchronizing LSDBs.
This is a three step process, as follows:
- Decide first router.
- In the ExStart state, the two routers decide which router will send the DBD packets first.
- The router with the higher router ID will be the first router to send DBD packets during the Exchange state.
- In the ExStart state, the two routers decide which router will send the DBD packets first.
- Exchange DBDs.
- In the Exchange state, the two routers exchange one or more DBD packets.
- A DBD packet includes information about the LSA entry header that appears in the LSDB of the router.
- The entries can be about a link or about a network.
- Each LSA entry header includes information about the link-state type, the address of the advertising router, the cost of the link, and the sequence number.
- The router uses the sequence number to determine the newness of the received link-state information.
- Send an LSR.
- A router compares the information received with the information in its own LSDB.
- If the DBD packet has a more current link-state entry, the router transitions to the Loading state.
- After all LSRs have been satisfied for a given router, the adjacent routers are considered synchronized and in a full state.
- Updates (LSUs) are sent only to neighbors in the following conditions:
- When a change is perceived (incremental updates).
- Every 30 minutes.
The Need for a DR
Why is a DR and BDR election necessary?
Multiaccess networks can create two challenges for OSPF regarding the flooding of LSAs, as follows:
-
Creation of multiple adjacencies - Ethernet networks could potentially interconnect many OSPF routers over a common link. Creating adjacencies with every router is unnecessary and undesirable. It would lead to an excessive number of LSAs exchanged between routers on the same network.
-
Extensive flooding of LSAs - Link-state routers flood their LSAs any time OSPF is initialized, or when there is a change in the topology. This flooding can become excessive.
-
To understand the problem with multiple adjacencies, we must study a formula:
-
For any number of routers (designated as n) on a multiaccess network, there are n (n – 1) / 2 adjacencies.
-
As n increases, the number of adjacencies increases rapidly to a quantity that would negatively impact router performance.
LSA Flooding With a DR
- A dramatic increase in the number of routers also dramatically increases the number of LSAs exchanged between the routers.
Flooding LSAs
-
This flooding of LSAs significantly impacts the operation of OSPF.
-
If a router sends out an LSA, this triggers every other router to also send out an LSA.
-
If every router in a multiaccess network had to flood and acknowledge all received LSAs to all other routers on that same multiaccess network, the network traffic would become quite chaotic.
LSAs and DR
-
The solution to managing the number of adjacencies and the flooding of LSAs on a multiaccess network is the DR.
-
On multiaccess networks, OSPF elects a DR to be the collection and distribution point for LSAs sent and received.
-
A BDR is also elected in case the DR fails.
-
All other routers become DROTHERs.
-
A DROTHER is a router that is neither the DR nor the BDR.
-
Note: The DR is only used for the dissemination of LSAs. The router will still use the best next-hop router indicated in the routing table for the forwarding of all other packets.
Single-Area OSPv2 Configuration
- Enable OSPFv2:
router ospf PROCESS_ID PROCESS_IDis an arbitrary number between 1 and 65,535.- It does not have to be the same on all adjacent OSPF routers to establish adjacencies.
- However, using the same
PROCESS_IDon all OSPF routers is considered best practice.
OSPF Router ID
- An OSPF router ID is a 32-bit value, represented as an IPv4 address.
- The router ID is used to uniquely identify an OSPF router.
- All OSPF packets include the router ID of the originating router.
- Every router requires a router ID to participate in an OSPF domain.
- The router ID can be defined by an administrator or automatically assigned by the router.
- To see the router ID:
show ip protocols | include Router ID. -
The router ID is used by an OSPF-enabled router to do the following:
-
Participate in the synchronization of OSPF databases – During the Exchange State, the router with the highest router ID will send their database descriptor (DBD) packets first.
-
Participate in the election of the designated router (DR) - In a multiaccess LAN environment, the router with the highest router ID is elected the DR. The routing device with the second highest router ID is elected the backup designated router (BDR).
-
Router ID Order of Precedence
- The router ID is explicitly configured using the OSPF
router-id RID. This is recommended. - The router chooses the highest IPv4 address of any of configured loopback interfaces. Next best.
- If no loopback interfaces are configured, then the router chooses the highest active IPv4 address of any of its physical interfaces.
Configure a Loopback Interface as the Router ID
-
Typically, the IPv4 address for this type of loopback interface should be configured using a 32-bit subnet mask (255.255.255.255).
-
This effectively creates a host route. A 32-bit host route would not get advertised as a route to other OSPF routers.
-
Note: OSPF does not need to be enabled on an interface for that interface to be chosen as the router ID.
Explicitly Configure a Router ID
router ospf PROCESS_ID
router-id RID
end
show ip protocols | include Router ID
Modify a Router ID
-
After a router selects a router ID, an active OSPF router does not allow the router ID to be changed until the router is reloaded or the OSPF process is reset.
-
An active OSPF router is one with adjacencies.
-
Use the
clear ip ospf processcommand to reset the adjacencies. -
Verify:
show ip protocols | include Router ID.
Point-to-Point OSPF Networks
-
You can specify the interfaces that belong to a point-to-point network by configuring the
networkcommand. -
You can also configure OSPF directly on the interface with the
ip ospfcommand. -
Both commands are used to determine which interfaces participate in the routing process for an OSPFv2 area.
- The basic syntax is:
network NETWORK_ADDRESS WILDCARD_MASK area AREA_ID -
NETWORK_ADDRESS WILDCARD_MASKsyntax is used to enable OSPF on interfaces. -
Any interfaces on a router that match the network address in the network command are enabled to send and receive OSPF packets.
-
area AREA_IDsyntax refers to the OSPF area. -
When configuring single-area OSPFv2, the network command must be configured with the same area-id value on all routers.
-
Although any area ID can be used, it is good practice to use an area ID of 0 with single-area OSPFv2.
- This convention makes it easier if the network is later altered to support multiarea OSPFv2.
The Wildcard Mask
-
The wildcard mask is typically the inverse of the subnet mask configured on that interface.
-
The easiest method for calculating a wildcard mask is to subtract the network subnet mask from 255.255.255.255.
Configure OSPF Using the network Command
-
Within routing configuration mode, there are two ways to identify the interfaces that will participate in the OSPFv2 routing process.
-
Method 1: use the
networkcommand with a wildcard mask.- Any active interface that is configured with an IPv4 address belonging to that network will participate in the OSPFv2 routing process.
-
Method 2: use the
networkcommand with a quad zero wildcard mask. The network address should correspond to the address of an interface.- This tells the router to enable OSPv2 on the interface corresponding to this network address.