# OSPF

Stands for **Open Shortest Path First**

Uses the **Shortest Path First** algorithm of Dutch computer scientist Edsger Dijkstra (aka **Dijkstra's algorithm**).

Three versions:

* OSPFv1 (1989): deprecated, not in use anymore.
* OSPFv2 (1998): Used for IPv4.
* OSPFv3 (2008): Used for IPv6.

Routers store information about the network in LSAs (Link State Advertisements), which are organized in a structure called the LSDB (Link State Database).

Routers will **flood** LSAs until all routers in the OSPF *area* develop the same map of the network (LSDB).

## LSA Flooding

OSPF is enabled on R4's  G1/0 interface.

<figure><img src="https://1474932522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAgItg4KAZpnXjAFPWRf8%2Fuploads%2FsEYJNhTXAjSfnEiIQKlu%2FScreenshot%20from%202023-07-03%2012-33-57.png?alt=media&#x26;token=c8d4af8c-3e4d-47d7-ad4c-d1f879e37e5a" alt=""><figcaption></figcaption></figure>

R4 creates an LSA to tell it's neighbors about the network on G1/0.

<figure><img src="https://1474932522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAgItg4KAZpnXjAFPWRf8%2Fuploads%2F35yzrGkHXsCDK2Q4jmry%2FScreenshot%20from%202023-07-03%2012-34-24.png?alt=media&#x26;token=e8947f7b-13cf-4193-958f-c268d7080296" alt=""><figcaption></figcaption></figure>

The LSA is flooded throughout the network until all routers have received it.

<figure><img src="https://1474932522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAgItg4KAZpnXjAFPWRf8%2Fuploads%2F6pIXToIfeWnLal1bkQIk%2FScreenshot%20from%202023-07-03%2012-36-37.png?alt=media&#x26;token=f4d3d9b2-c436-496d-a689-e19b6ca5e9f0" alt=""><figcaption></figcaption></figure>

This results in all routers sharing the same LSDB.

<figure><img src="https://1474932522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAgItg4KAZpnXjAFPWRf8%2Fuploads%2FAJTvVo6CoxJFzBoLCZ2y%2FScreenshot%20from%202023-07-03%2012-37-21.png?alt=media&#x26;token=2c56c991-1dda-4f04-bd60-43371cbeca9e" alt=""><figcaption></figcaption></figure>

Each router then uses the SPF algorithm to calculate its best route to 192.168.4.0/24.

{% hint style="info" %}
Each LSA has an aging timer (30 min by default). The LSA will be flooded again after the timer expires.
{% endhint %}

## OSPF Steps

In OSPF, there are three main steps in the process of sharing LSAs and determining the best route to each destination in the network.

1. **Becoming neighbors** with other routers connected to the same segment.
2. **Exchange LSAs** with neighbor routers.
3. **Calculate the best routes** to each destination, and insert them into the routing table.
