OSPF Explained | Step by Step

Video Connections
48 followers
7 Video Views·Oct 28, 2022
Hey what's up guys, welcome to CertBros. In this video we're going to be talking about OSPF.
Okay so OSPF, what is it? Well OSPF is a widely used and widely supported routing protocol.
It's an open standard meaning pretty much any router will support it. It's an interior gateway
protocol meaning it's been designed to be used within a single autonomous system. OSPF is also
a link state protocol. So the goal of a routing protocol is of course to learn routes. Now the
way OSPF does this is by learning about every router and subnet within the entire network.
The result is every router has the same information about the network as each other.
The way routers learn this information is by sending out what's called link state advertisements
or LSAs. Now these LSAs contain information about the subnet, router and some other network
information. Once all LSAs have been flooded OSPF keeps all of this information in a link state
database. This is also known as an LSDB. The goal here is to have each router with the same
information in their LSDBs. So that's the general goal of OSPF. Let's take a deeper look at how this
actually works. There are three main steps to this process. First becoming OSPF neighbors.
This is where connecting routers running OSPF agree to form neighbor relationships. Next exchanging
database information. After becoming neighbors the routers will then exchange their LSDB information
and finally choosing the best routes. Once the LSDB information has been exchanged each router
will then choose the best routes to be added to the routing table. This is done by running a
calculation called SPF. First we'll look at how connecting routers form neighbor relationships.
Okay so the very first thing that needs to happen before a relationship is formed
is each router needs to choose a router ID. A router ID is a number that can be used to identify
an individual router. Kind of like an OSPF name. The router ID or RID is in the format of an IPv4
address but can be set to whatever you like. So there are a few ways that you can set a router ID.
You can either set it manually or you can let the router decide for itself.
So here's the logic that routers go through when choosing router IDs.
First check if it's been manually set. If it's been manually set that is the router ID.
If it's not been manually set then the router will choose the highest
up loopback IP address. If there are no loopback interfaces on the router it will then choose the
highest up non-loopback IP address. Essentially it will choose the highest IP address on the router.
Okay so let's take a look at two routers. Once OSPF is configured and we have our router IDs
the routers will reach out to potential neighbors with a friendly hello message.
This message contains some important information including the unique router ID and any already
known neighbors. The hello messages also let their existing neighbors know that they're still alive
and kicking. Once router 2 receives the hello message it runs some checks. It's important to
note here that there are some very strict requirements that need to be met when OSPF
forms neighbor relationships. If you run into problems with OSPF it's highly likely that the
problem will be with one of these. The area ID needs to be the same. This is used when scaling
up OSPF and will be covered in another video. The connecting links between the two routers
must be on the same subnet. The hello and dead timers must be the same. The dead timer is how
long a router will wait without hearing a hello message before it just assumes that neighbor is
dead. The default hello timer is every 10 seconds for point-to-point and broadcast networks.
If using authentication this must also match and the stub area flag must match as well.
Routers will also need unique router IDs. Okay so once the checks have been made and if all is good
then the routers can move to what's called the init state. Router 2 then sends a hello message
of its own. This message not only lists its own router ID but also router 1's ID as a known
neighbor. So when router 1 receives this hello message it sees itself as a known neighbor.
This allows router 1 to move to the two-way state. Router 1 then sends yet another hello message
listing router 2 as a known neighbor. This then allows router 2 to enter the two-way state as well
and after all of that we now have two neighboring routers. Before moving on to the step of exchanging
database information first we must look at designated routers or DRs and backup designated
routers or BDRs. DRs and BDRs are not elected on point-to-point connections so we need to take a
very quick detour. In this network we have six routers all connected on the same segment. Let's
we don't have any DRs or BDRs and all routers become full neighbors with each other. If one
link goes down the affected router will let all the other neighbors know what just happened.
Then each router that receives this update will then tell all of their neighbors. Very quickly
things begin to get a little bit out of control and this would happen every time a change occurs.
Instead a DR and BDR is elected. The election of a DR and BDR is done based on the highest OSPF
priority. Now the priority is set to one by default but this can be changed to influence
the election. If the priority ties then the election is based on the highest router ID.
When on the same segment routers will only become full neighbors with DRs and BDRs. The other
neighbors will remain in the two-way state we just looked at. This means every router will ignore
updates unless they come from the DR. So let's look what happens now. So the link goes down,
the router floods the updates and the other routers ignore it. Then the DR re-floods the update and
now the other routers pay attention. Ah look at that much better. Okay so back to our diagram.
Once the exchange process starts both routers enter the xstart state. At this point the routers
select a slave and master. This is based on the router ID. The master will control the sequence
numbers and start the exchange process. Thankfully we don't need to know much more than that. Now we
move on to the exchange state. Both routers send each other a list of their LSAs. This is called
a database description or DBD. Now on to the loading state. Each router will look over the
DBD and request any information it doesn't already have. The reason it does this is to prevent loops
by requiring the routers to request the information rather than just firing out updates. So as an
example router 1 sees that router 2 has the LSA for 192.168.3.0. So it says hmm can you send me
over the 3.0 network and then sends a request. This request is called a linked state request
or LSR. Router 2 responds with sure here you go and sends a linked state update or LSU.
Router 1 then sends over a linked state acknowledgement or LSAc. Now the same
happens again for router 2. Router 2 sends a request for the 1.0 subnet. Router 1 sends the LSU
and router 2 sends an LSAC. Once the exchange of LSAs has completed both routers enter the
full neighbor state. Now remember this is a point-to-point network. On a broadcast like
we saw earlier they will only form the full neighbor relationship with DRs and BDRs.
Okay so on to the last step adding the best routes to the routing table.
The way OSPF chooses the best routes is by using a metric called cost. OSPF cost is a value given
to a link based on the bandwidth of that interface. The sum to work out the cost is the reference
value which is set on the router itself and is a hundred thousand kilobits per second by default
divided by the interface bandwidth. Okay so don't worry too much about the sum just try and remember
these cost values. Serial interfaces 1544 kilobits per second this is a cost of 64. Ethernet 10 000
kilobits per second a cost of 10. Fast ethernet 100 000 kilobits per second this is a cost of 1.
Now anything faster than fast ethernet will also be a cost of 1. Now you might be thinking that
doesn't make much sense and you'd be right. The way to change this would be to change the reference
value in the sum we looked at earlier. This can be configured by you on the router itself. Let's go
through a quick cost example and see how this works. Okay so we have a five router network here.
In this example router one wants to add the route for 10.0.0.0 to its routing table. As you can see
it has three options. It can go through router 4, 2 or 5. To make this decision it will do some
simple math to calculate the cost of each one. First router 4. The first link is 1544 kilobits
per second so this is a cost of 64. The next link is also 1544 kilobits per second so another cost
of 64. Finally the last link is 10 megabits per second which is a cost of 10. So all of this means
the first route has a total cost of 138. Next router 2. The first link is 10 megabits per second
so a cost of 10. Again the next link is also 10 megabits per second and we already know the last
link is 10 megabits per second so this means router 2 gives us a total cost of 30. Last but
not least router 5. The first link is 100 megabits per second this time. This means a cost of 1.
The second link is also 100 megabits per second and the last link as we know is 10 megabits per
second. The total cost for router 5 is 12. So as I'm sure you've guessed already the lowest cost
is the best. So as router 5 has the best cost to the 10.0.0.0 subnet this route is the winner and
it is added to the routing table. Okay so that is it for OSPF. There's so much more we could talk
about but I think that's enough for one video. If you like this video then remember to like, comment
and subscribe. Oh and by the way if you're sat there thinking wait what the f*** is a router?
Well that's just the way us Brits like to say router. Thank you for watching.
