OSPF

Done

It was created by a Dutch scientist called Edsger Dijkstra.

💡
Because of this OSPF uses the Shortest Path First algorithm, or also called Dijkstra`s algorithm

There are three versions of OSPF:

Each router will create what is called a LSA (Link State Advertisement), which will be flooded to all its neighbors. Those other routers will store those LSAs containing information about the connected interface of the first router in their LSDB (Link State Data Base). This way the routers can create a “connectivity map” of the whole network and make individual decisions based on it.

💡
IMPORTANT: All the routers have the same LSDB in the end.

Each LSA have a aging timer of 30 minutes

Basically in OSPF the is three steps:

OSPF Areas

OSPF can be divided in areas (segments) to divide up the network. There is barely no benefit to divide it on a small network, however, in a large network with hundreds of routers and more than a thousand subnets a single area of OSPF can have some negative effects:

Requirements

Configure OSPF

First create the OSPF instance

configure terminal
router ospf {value}
💡
This value can be anything, and differently from EIGRP, it does not have to be the same in the routers in the same are. It is locally significant.

Then specify the interfaces to active OSPF, those interfaces will both:

network {subnet-id} {wildcard}
💡
REMEMBER: Wildcards are the inverse of the Subnet Masks

Disable OSPF messages in a given interface

By disabling the OSPF messages, it will still be advertised to the active neighbors, while not sending OSPF hello messages on that given interface. Usually this interface is connected to a subnet that has no other router.

passive-interface {interface}

Disable OSPF messages on ALL interfaces

passive-interface default

Then you can no passive-interface interface on each interface to enable OSPF messages on that given interface. Basically, it is the other way around.

Advertise the default route

default-information originate

Change Router ID

router-id {ip address like value}

Change the ECMP Maximum routes

maximum-path {number routes}

Directly active OSPF in an interface

configure terminal
interface g0/0
ip ospf {process-id} area {area-number}

Show Commands

View LSDB
show ip ospf database
View OSPF Neighbors
show ip ospf neighbor
View OSPF Interfaces
show ip ospf interface [interface]
show ip ospf interface brief

Cost

OSPF`s metric is called cost. It is calculated based on the bandwidth (speed) of the interface.

How do you calculate the cost of an individual interface?

It is done by dividing the reference bandwidth for the interface`s bandwidth. And, the reference bandwidth is 100 mbps by default.

For example, for a interface with speed of 10 Mbps we have: Cost=100/10=10Cost = 100/10 = 10 

For a interface with a bandwidth of 100 Mbps we have: Cost=100/100=1Cost = 100/100 = 1

For a Gigabit interface with a bandwidth of 1000 Mbps we have: Cost=100/1000=1Cost = 100/1000 = 1

And so on…

💡
IMPORTANT: In OSPF, any value lower than 1 will be converted to 1.
//This command allows for the reference bandwidth to be greater, so faster interfaces 
//can have lower costs compared to slower interfaces.
router ospf {value}
auto-cost reference-bandwidth {value-in-megabits-per-second}
💡
NOTE: This value should be configured for all the routers using OSPF.

How do you calculate the Total Cost?

The Total Cost is calculated by summing the cost of each outgoing/exit interface in the route for a destination

For example, the route from R1 to the subnet “192.168.4.0/24”, with a reference bandwidth of 100000 Mbps, is:

100(R1G0/0)+100(R2G1/0)+100(R4G1/0)=300100 (R1`G0/0)+100(R2`G1/0)+100(R4`G1/0) = 300
💡
IMPORTANT: Loopback interfaces have a cost of 1.

Another example, the cost to reach 2.2.2.2 (Loopback interface on R2) from R1, would be:

100(R1G0/0)+1(R2L0)=101100(R1`G0/0)+1(R2`L0) = 101

You can change a single interface cost

To do so, you must use the following options:

Option #1 - OSPF Cost
configure terminal
interface g0/0 //Enter interface configuration mode
ip ospf cost {value}

This setting will override the auto-calculation done by reference-bandwidth/interface-bandwidth

Option #2 - Change the interface`s bandwidth

By doing so it will alter the value of interface-bandwidth used in the OSPF auto-calculation of cost. HOWEVER, it will also change the value of other protocols calculations, so it is NOT RECOMMENDED.

💡
NOTE: Although the bandwidth often matches the value of speed, they are different terms, so altering the bandwidth will not change the operating speed of that given interface.
configure terminal
interface g0/0
bandwidth {value-in-Kb} //Often use "?" to check the unit of the value being entered

How to check the OSPF Cost in all interfaces

show ip ospf interface brief

OSPF Neighbors

Steps in Becoming Neighbors (Neighbor States)

  1. Down
    1. First router sends a OSPF Hello message with the multicast address of 224.0.0.5, containing the following fields (at least):
      1. Router ID: Their own Router`s ID as explained before
      1. Neighbor RID with the value of 0.0.0.0, because it doesn`t have that neighbor yet on the neighbors table
  1. Init
    1. Hello Packet received in R2, but its own Router ID is not specified in the Hello message.
    1. R2 adds the sender`s RID in its OSPF Neighbors table
    1. R2 will then send a Hello Message with its Router ID in the RID field and the original sender Router ID in the Neighbor RID field
  1. 2-Way
    1. Hello Packet received with it`s own Router ID on the Neighbor RID field. This happens with R1 and R2, both entering this state.
    1. R1 adds the R2 to its OSPF Neighbor table
    1. Conditions have been met to be OSPF Neighbors
    1. A DR (Designated Router) and a BDR (Backup Designated Router) may be selected at this point
  1. ExStart
    1. Decides, by DBD (Database Description) packets exchange, which one will be the Master, which will start the exchange of LSAs, and which one will be the Slave
    1. The Master is the one with the higher RID, and obviously, the Slave is the one with the lower RID.
  1. Exchange
    1. Routers then exchange what LSAs they have, being the Master the first one to send it, not in details, via DBDs to each other. Basically they say what they have in their LSDB without telling the full details.
    1. Routers in this phase will compare the LSAs in those DBDs with what they have in their LSDB, and see LSAs it doesn`t have so can ask later in the next phase.
  1. Loading
    1. After knowing what they neighbors have that they don`t, R2 (from his perspective for better understanding) asks for the LSAs via LSR (Link State Request).
    1. R1 then receives that LSR, making it send a LSU (Link State Update) containing the LSAs requested by their R2, its neighbor.
    1. Finally, after receiving that LSU, the R2 send back an LSAck (Link State Acknowledgment) notifying R1 that it received successfully the LSU.
  1. Full
    1. In this state, both routers have formed Adjacency and both have identical LSDBs
    1. Each one will continue to send OSPF Hello messages every 10 seconds (by default) to maintain their relationship
    1. The Dead Timer is the amount of time an interface can still not receive a OSPF Hello message from its neighbor before removing it from its OSPF Neighbors list.
    1. They continue to send LSAs to each other after every change in the network.

OSPF Network Types

It refers to the type of connection between OSPF Neighbors, and they can be:

DR, BDR and DROther

💡
Routers will exchange messages with the DR and BDR via multicast address 224.0.0.6
💡
IMPORTANT: When the DR fails, even with there is another router with a highest Router ID, only the already elected BDR will become the DR, and the router with the highest Router ID will become the BDR
💡
IMPORTANT: As said before, DROther routers will only have up to a 2-Way Neighbor relationship state with another DROther, since they will not exchange LSAs between each other.

Election of DR and BDR

In order of priority:

  1. Highest OSPF interface priority
  1. Highest Router ID
💡
IMPORTANT: All OSPF interfaces have a priority of 1 by default.

“First place” becomes the Designated Router (DR) and the “second place” becomes the Backup Designated Router.

Change an interface OSPF Priority

configure terminal
interface g0/0
ip ospf priority {0-255}

Change the Network Type of an interface

configure terminal
interface g0/0
ip ospf network {brodcast/non-broadcast/point-to-point/point-to-multipoint}

Change the Hello and Dead Timers

configure terminal
interface g0/0
ip ospf hello-interval {time-in-seconds}
ip ospf dead-interval {time-in-seconds}

Authentication setting

You can specify a password for routers to become neighbors

configure terminal
interface g0/0
ip ospf authentication-key {password}   //Specifies the OSPF password
ip ospf authentication                  //Enables OSPF Authentication

OSPF Neighbor Requirements

Types of LSAs