Open Shortest Path First (OSPF)

rebar hamarebar hama
10 min read
  • Open Shortest Path First (OSPF) is a link-state routing protocol that is used to find the best path between the source and the destination router using its own Shortest Path First.

  • The protocol recalculates routes when a link fails and the network topology changes, Using the Dijkstra(dike·struh) algorithm, and minimizes the routing protocol traffic that it generates.

  • It provides a multi-level hierarchy called “area routing” so that information about the topology within the defined area of the AS is hidden from routes outside this area. This enables an additional level of routing protection and reduction in routing protocol traffic.

  • All protocol exchanges can be authenticated so that only trusted routers can join in the routing exchanges for the AS

Benefits of OSPF:

  • Fast convergence.

  • Efficient use of network resources.

  • Support for large, complex networks.

  • Ability to route IPv4 and IPv6 traffic (OSPFv2 for IPv4, OSPFv3 for IPv6).

  • Redundancy and fault tolerance.

  • VLSM (Classless Routing) and route summarization

OSPF Concepts

Area

  • An area is a logical collection of OSPF networks, routers, and links that have the same area identification.

  • The most important area in OSPF is the backbone area, also known as area 0. The backbone area is the central area that interconnects all other areas.

  • In a large network, a single-area design can have negative effects:

  • The SFP algorithm takes more time to calculate routes and it causes the algorithm to require more processing power.

  • Any small change in the network causes every router to flood LSAs and run the SPF algorithm again.

  • By dividing a large OSPF network into several smaller areas, you can avoid the above negative effects.

Neighbour

  • Routers running OSPF need to establish a neighbour relationship before exchanging routing updates, Neighbours are dynamically discovered by sending Hello packets out of each OSPF-enabled interface.

  • Hello Packets:

    OSPF uses multicast addresses to communicate and exchange Hello Packets between routers

  • 224.0.0.5: All OSPF routers.

  • 224.0.0.6: All OSPF designated routers (DRs) and backup designated routers (BDRs).

  • Hello Interval:

    • The OSPF router sends a hello message on an interface. It is 10 seconds by default.
  • Dead Interval:

    • The Dead interval is four times the Hello interval, this means a Dead interval of 40 seconds

    • If a router does not receive at least one Hello packet from a neighbour within the Dead interval, the neighbour is considered down.

ospf_example_topology.jpg

ABR and ASBR

  • Area Border Router(ABR): a router that connects two or more OSPF areas, one of which must be the backbone area (area 0).

  • Autonomous System Border Router(ASBR): a router that connects an OSPF domain to an external network or another routable domain, it is responsible for importing and redistribution routes from non-OSPF sources into the OSPF routing source.

1729506083948.jpeg

Screenshot 2023-02-21 104354.png

Designated Router and Backup Designated Router

  • Designated Router (DR) and Backup Designated Router(BDR) is to act as a central point for exchanging of OSPF information between multiple routers on the same network. Each non-DR and non-BDR router only exchanges routing information with the DR and BDR, Instead of exchanging updates with every router on the segment. This significantly reduces the amount of OSPF updates sent across the network.

Screenshot 2023-02-21 110657.png

DR and BDR Election

  • Upon the segment, each router will go through an election process, to elect A DR and BDR.

There are two rules used to determine who is elected:

1- OSPF priority is a value between 0 and 255 that may be assigned to every router interface participating in OSPF. The default priority is 1. A priority of 0 means that the router is not eligible to become DR or BDR.

R1(config)#interface fastEthernet 0/0
R1(config-if)#ip ospf priority 200

2- Router ID is a 32-bit number that uniquely identifies every OSPF router.

  • Manual Configuration.

  • A highest IP address on a loopback address.

  • A highest IP address on a physical address.

  • OSPF Router ID should not be changed after the OSPF process has started and the OSPF neighborships have been established. If you change the OSPF Router ID, We need to either reload the IOS or use the command (clear ip ospf process), for OSPF Router ID change to take effect. reloading the IOS or using the command [clear ip ospf process] can cause a temporary network outage.

Router ID Selection algorithm works as below:

  1. If manually configured OSPF Router ID in OSPF process, it is selected as the OSPF Router ID.
R1# conf t 
R1#(config) router ospf 100(OSPF process number).
R1#(config-router)# router-id 1.1.1.1

Note: the router step-by-step checks each point if the router-id is configured manually other steps skipped

Loopback interface

  • Loopback interfaces are logical(virtual) interfaces. using loopback interfaces with OSPF configuration ensures that an interface is always active for OSPF processes.

  • It is always up/up (unless you manually shut it down).

  • It is not dependent on a physical interface.

  • They can be used for diagnostic purposes as well as OSPF configuration. The reason to configure a loopback interface on a router is because if you don’t. the highest active IP address on a router at the time of bootup will become that router’s RID, The RID is used to advertise the routes as well as elect the DR and BDR.

Loopback Interface Configuration

R1#conf t 
R1(config)#interface loopback 0 
R1(config-if)#ip address 10.0.0.1 255.255.255.0
R1(config-if)#exit

<aside> 💡

Always manually configure the Router ID using the router-id command for stability and control.

</aside>

OSPF Process ID

  • The process ID is the ID of the OSPF process to which the interface belongs. the process ID is local to the router, and two OSPF neighbouring routers can have different OSPF process IDs. (Not like EIGRP). Cisco IOS software can run multiple OSPF processes on the same router, The Router ID should be a positive integer, for example, the process ID is 1
  • LSA(Link State Advertisement) packets are sent between routers within the same area of origin and do not leave the area. An OSPF router uses LSA packets to describe its own interfaces but also carries information about its neighbours to adjacent routers in the same area.
LSA Type 1:Router LSA
LSA Type 2:Network LSA
LSA Type 3:Summary LSA
LSA Type 4:Summary ASBR LSA
LSA Type 5:Autonomous system external LSA
LSA Type 6:Multicast OSPF LSA
LSA Type 7:Not-so-stubby area LSA
LSA Type 8:External attribute LSA for BGP

OSPF Concepts: Main LSAs

LSA TypenameGenerated byDescription
LSA Type 1:Router LSAGenerated by each internal router within an area, per area linkFlooded within an single area only.
LSA Type 2:Network LSAGenerated by the DRFlooded within a single area only.
LSA Type 3:Summary LSAGenerated by the BDRDescribes inter-area routes
LSA Type 4:Summary ASBR LSAGenerated by the ABR.Describes the path to the ASBR.
LSA Type 5:Autonomous system external LSAGenerated by ASBR.Describes the redistributed routes that have been injected into the OSPF domain from an external AS by The ASBR
LSA Type 7:Not-so-stubby area(NSSAs) LSAGenerated by the ASBR, within a not-so-stubby area.Describes external routes. sent from ASBR to ABR and converted into a type 5 by the ABR, which then floods to its areas.

ospf wireshark .png

<aside> 💡

  • Hello messages are used for establishing and maintaining OSPF neighbour relationships.

  • LSAs are used to share detailed routing and topology information within the OSPF domain. </aside>

Cost

  • Open Shortest Path First(OSPF) uses cost as the value of metric and uses a reference bandwidth of 100 Mbps for cost calculation. The formula to calculate the cost is Reference Bandwidth divided by interface bandwidth. for example, in the case of 10 Mbps Ethernet, OSPF metric cost value is 100 Mbps / 10 Mbps.

image.png

Modify the reference bandwidth

R1(config-router) **auto-cost reference-bandwidth** megabits-per-second

Manually Configure the cost of an interface:

R1(config-if)**ip ospf cost** cost

Modify the interface bandwidth:

R1(config-if)**bandwith** kilobits-per-second

Which of these commands can be used to make a FastEthernet interface have an OSPF cost of 100?

  • R(config-router)# auto-cost reference bandwidth 1000

Reference bandwidth/Interface bandwidth = cost

10000/100=100

Example Scenario

Scenario: You have two paths from Router A to Router D:

  1. Path 1: A → B → D (10 Mbps and 100 Mbps links, respectively).

  2. Path 2: A → C → D (100 Mbps links only).

Default Cost Calculation:

  • Path 1: Cost = 10 (A → B) + 1 (B → D) = 11.

  • Path 2: Cost = 1 (A → C) + 1 (C → D) = 2.

Result:

  • OSPF chooses Path 2 because it has a lower total cost.

<aside> 💡

the SPF algorithm uses the cost of the outgoing interfaces toward the destination subnet, including the cost of the interface that connects to the subnet. The logic is illustrated in the following diagram.

</aside>

intra-area-adding-cost-logic.svg

Screenshot 2023-02-23 140910.png

Wild Card Mask

  • Wildcard masks are used to specify a range of network addresses. They are usually used with routing protocols (Such as OSPF) and access lists.

  • A Wildcard mask is 32-bit long. it is a sort of inverted subnet mask, with the zero bits indicate that the corresponding bit position must match the same bit position in the IP address.

Screenshot 2023-03-01 095726.png

Note: change all 0 to 255 and all 255 to 0, in the second one last number 255-192=063

OSPF States

  • Down State: OSPF is activated on the router, The router sends out Hello packets to the multicast address 224.0.0.5. It doesn’t know about any OSPF neighbours yet, so the current neighbour state is Down.

  • Init State: A Hello packet has been received from a neighbour, but the receiving router has not yet been listed in the neighbour's Hello Packet. At this stage, Communication is One-way.

image.png

  • 2-Way State: The Router Hello packet now includes the neighbour’s Router ID, and the neighbour’s Hello packets include the local router ID, Two-way communication is established.

image.png

  • ExStart State: The Master-slave relationship is negotiated, Where one router becomes the master and initiates databases. The routers with lower Router-ID will become the slave.

  • Exchange State: The routers exchange DBDs which contain a list of the LSAs in their LSDB.

  • Loading State: Routers send Link State Request(LSR) messages to request that their neighbours send them any LSAs they don’t have. LSAs are sent in Link State Update (LSU) messages.

  • Full State: The Routers are fully synchronized and have established an adjacent. they continue to send and listen for Hello Packets.

IDNamePurpose
1HelloNeighbor Discovery and Maintenance
2Database DescriptionSummary of the LSDB of the router.
3Link-State Request (LSR)Request specific LSAs from the neighbor.
4Link-State Update (LSU)Sends specific LSAs to the neighbor.
5Link -State Acknowledgement(LSAck)Used to acknowledge that the router received a massage.
R1(config)# router ospf 1
R1(config-router)# network 192.168.1.1 0.0.0.0 area 0

**VS**

R1(config)# router ospf 1
R1(config-router)# network 192.168.1.0 0.0.0.255 area 0
  • Use 192.168.1.0 0.0.0.255 when enabling OSPF on all interfaces within the 192.168.1.0/24 subnet.

  • Use 192.168.1.1 0.0.0.0 when enabling OSPF on a specific interface with the IP address 192.168.1.1.

Tip: To reduce manual configuration effort, use subnet-based configuration (192.168.1.0 0.0.0.255) for a larger network or dynamic environment. For specific control or precision, use interface-based configuration (192.168.1.1 0.0.0.0).

0
Subscribe to my newsletter

Read articles from rebar hama directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

rebar hama
rebar hama