CCNA OSPF Database and Networks

Chapter 1 – Introduction

OSPFs job is to learn network routes, and select the best ones. In the last lesson, we saw that part of this is building neighbour relationships.

Another part is storing everything it learns in a database. OSPF is a link-state protocol, which means that it creates a map of the entire network area. All OSPF routers in this area have the same map.

In this lesson, we’ll see how OSPF builds and maintains the database, or map, of network information.

Chapter 2 – The OSPF Database

When the OSPF process starts, the router creates a database. This is the Link State Database, or LSDB.

This stores OSPF topology information. This means routers, and the links that join them. This is the ‘map’ of the network, with paths from one router to another.

The first thing the router adds is it’s own OSPF information, such as it’s router ID, and any connected routes. As neighbour relationships form, the router adds more information.

Let’s take a look at an LSDB. We can do this with the show ip ospf database command. Here we see the entries in the LSDB. Each piece of information is a link.

Router Link States is the first section. This is information about OSPF routers in the network. We have three routers in the topology, so there are three entries here.

Net Link States is the second section. These are the links that connect the routers. In our case there are three links, joining the three routers together.

In more complex networks, there would be more sections than only these two. But we won’t worry about those…

Let’s instead look at how OSPF synchronizes the database contents between routers.

A neighbour will come online and build neighbour relationships. When it does this, it triggers the synchronization process.

A router will advertise each link, that is, each entry in the database, to their neighbours. It does this using a message called a Link State Advertisement, or LSA.

OSPF has a few different packet types that it uses for communication. The LSA itself is the data structure within those packets.

One type of packet is the Database Descriptor, or DBD. This contains a summary of the database. This is a light way of telling a neighbour about each network, without burdening it with detail.

This is efficient, because the neighbour can ask for more information if it wants it, or leave it alone.

Upon receiving a DBD, a router will look at the summary, to see if there’s any networks it can learn about.

If there are networks it hasn’t yet learned about, it will ask for more information. It does this with a packet called a Link State Request, or LSR.

LSRs selectively ask for more information about specific networks, not the entire database.

The router that receives this request will send back Link State Update packets.

DBD packets only contain LSA headers to summarize network information. LSUs, though, contain full LSAs. That is, they contain detailed information about the requested links.

Routes, next hops, and their metrics go into a separate table.

And finally, routers need to acknowledge that they received this information. This uses a Link State Acknowledgement packet.

When the database is up to date, the router can run the Shortest Path First algorithm. This finds the best paths through the network. For each destination network, OSPF offers the best paths to the routing table.

There are two other uses for LSAs, other than building a new database. One is for any change in the network. For example, when adding or removing links.

The other is for an LSA refresh. Every 30 minutes the router sends LSA refresh messages to be sure that the OSPF databases are still in sync.

I’ve decided to throw a few tricky questions at you this time. If you need to, go back and review this section, but I’m sure you can work through them.

Chapter 3 – Network Types

Let’s think about OSPF neighbours again. As we’ve seen, there is a network between neighbours.

This could be a very small network. Only enough to connect two routers together, and nothing more.

Or, it could be a bigger network. This could be several routers connecting to a switch. There might even be other devices on the same switch.

From OSPF’s perspectives, that’s only two of the possible network types. In total, there are four network types:

  • Broadcast, like when routers connect to a switch
  • Point to point, like when two routers connect together directly
  • Point to multipoint
  • And, Non-Broadcast Multiaccess, or NBMA

At the CCNA level, we’re only worried about the first two. Broadcast, and point-to-point. So, you can ignore the other two for this series.

Point to point is the simplest one to understand. One router connects directly to another. This is more common over a WAN connection. That is, a connection from one site to another.

When one router sends a message, there’s only one other router that could possibly receive it. This is a nice uncomplicated model. On the downside, we can’t add more routers to the network. We can only create more networks, and add routers there.

The most common network protocol would have to be Ethernet. One key feature of Ethernet is that it uses broadcasts.

When an OSPF router connects with an Ethernet interface, it will be on a broadcast network. This includes connecting a router to a VLAN on a switch.

The key points for an Ethernet network are:

  • There can be more than one device on the network
  • When a router sends a message, other devices may see it
  • This scales well, as it’s easy to add more routers

There can be other devices on the VLAN, not only routers. How does a router know which of these devices are OSPF routers?

It would be fair to think that the router would send a broadcast message to everything. It is a broadcast network after all.

That’s not right though. OSPF doesn’t actually use broadcast messages. It uses multicast. This enables OSPF to send a hello message to, which is OSPFs special multicast address.

Other OSPF routers will listen for messages sent on this address. When they receive the hello message, they’re able to respond to the sender.

Let’s think about a problem that could occur on a broadcast network. We’ll then see how OSPF solves this.

When a router adds a new network, it floods an LSA to its neighbours. This is how it advertises this network. The neighbours would then request more information with an LSR message.

Once they learn the new route, they would tell their neighbours, and so on. That’s a lot of messages flying back and forth. Imagine how bad it would be if there were 20 or 30 routers here. This many messages has the potential to impact the network.

But OSPF is smarter than that. For every broadcast network, OSPF will elect one router to be the Designated Router, or DR. It will also elect one Backup Designated Router, or BDR. All other routers are DROthers.

Each OSPF router has a priority, which is set to 1 by default. Of course, we can change the priority if we want to. The router with the highest priority becomes the DR, and the next highest is the BDR.

If some routers have the same priority, like they do by default, the highest router ID breaks the tie.

If a DR fails, the BDR is promoted. Then one of the DROthers will be promoted to BDR.

How does that solve the problem? Well, when a router adds a new network, and it sends out the LSAs, they aren’t sent to every neighbour. 

Instead, they only go to the DR and BDR. This uses multicast address, which only DRs and BDRs listen to. They will then use an LSR to request more information as normal.

The DR will then distribute this information to the other routers, that’s the DROthers, on the network. This cuts down the number of OSPF messages on a broadcast network.

It’s easy to see what roles our neighbours have. On a router, we can look at the neighbours with show ip ospf neighbor. This is a topology with five routers, so we will see four neighbours.

In the State column, we can see that one of the routers is DR, one is BDR, and the other two are DROther. That makes this router a DROther as well.

What if we want to make this router the DR? To do this, we enter configuration mode, and then interface configuration mode. 

Remember that a DR and BDR are elected for each broadcast segment. That means that these settings can vary per interface. For example, our router could be DROther on this network, and BDR on some other network.

We need to change the priority to influence the election. The command is ip ospf priority. The default priority is 1. We’ll set this router to 100.

We could also set the priority to zero. This would mean that the router would never become DR or BDR.

If we take a look at our neighbours again, we see that nothing has changed. So what’s wrong? Nothing! It may be surprising to hear that this is actually what’s supposed to happen.

Let me explain… OSPF elections are not preemptive. That means that changing priority doesn’t trigger an election. So adding a router with a better priority will not immediately change the DR and BDR.

This means we need to force an election. We can do this by clearing the OSPF process. But, we don’t do it on the router we just configured. That won’t trigger an election. Instead, we need to do this on the current DR and BDR routers.

Let’s head over to R5, which is the current Designated Router. Here, we’ll clear the OSPF process, which causes the neighbours to drop, and reform.

Back on R1, we can look at the neighbours again. We see that router R5, that’s, is now a DROther. Router 4 has been promoted from BDR to DR.

So even though there’s an election process, R1 hasn’t become the DR. When the Designated Router drops out, the BDR gets a promotion. The routers hold an election to select the new BDR.

You’ll notice that there’s no BDR in the list here. That’s because R1, the router we’re logged into, is now the BDR.

For R1 to become the DR now, we would need to restart the OSPF process on R4.

Let’s take a step back, and think about this simple topology. What type of OSPF network is this? You might assume it’s point-to-point, but that’s not necessarily true.

These two routers could connect to a switch, and be in the same VLAN. That would be an Ethernet connection, and therefore a broadcast network.

Or, they could be directly connected together. But the interface type may still use Ethernet. That would still be a broadcast network as far as OSPF is concerned.

Even though there are only two routers, they would still need to elect a DR and BDR, and handle LSUs as we’ve been discussing.

Of course, that’s not very efficient. So, if we want to, we can change the OSPF network type.

Let’s go back to R1 and see how it’s done. From before we can see that there are a few routers here.

This is not a good topology to change network type, as there are five routers in the segment. But I want to show you how to make the change, as well as what happens if you use the wrong network type.

Once again, we configure this under the interface. We use the ip ospf network command. And here we can see the network types we can choose. We’ll set this interface to point-to-point.

Straight away, the neighbours drop. The key point here is that neighbours need to have the same network type.

Let’s look at the R5 router. The logs on the screen show us that the neighbour adjacency with R1 repeatedly forms and drops.

We can change the network type on this router too… It’s the same command as before.

Immediately the other neighbours fail. They keep trying to reconnect, but they’ll never be successful as long as the network types don’t match.

We’ll take a look at a better example of changing the network type when we get to the lab at the end of the video.

Before we move on, here’s a little review to help with Designated Routers and Backup Designated Routers.

Chapter 4 – Neighbour States

When a router forms an adjacency with another router, it goes through several states. The routers progress through these states as they learn more about each other.

The first state is DOWN. This means that an OSPF-enabled link is up, but no hello messages have been received by a neighbour yet. This is basically where the whole process starts.

We might also see a router in this state if something is wrong. For example, neighbours coming up, then immediately dropping like we saw a moment ago.

Next, you might see a state called Attempt. This only applies to routers with the NBMA network type, so it’s not something you need to know for CCNA. Just be aware that it exists.

This is where a router has sent a unicast hello packet to an adjacent router.  Remember that hellos are usually multicast. But, it hasn’t seen hello packets from these routers yet.

The Init state means that a hello packet has been received from an adjacent router. This router has introduced themselves, and shared their Router-ID.

The hello packet doesn’t include our router ID though. When a router sends hello messages, it includes a list of Router-ID’s of all neighbouring routers. That means that eventually a router should see it’s own Router ID in a hello packet from an adjacent router.

This state means that communication has started, but it’s not bidirectional yet.

The 2-Way state means that bidirectional communication has been established. Each router has sent hellos, and each router has seen their own Router-ID in the hello message.

Once routers are at this point, they’ve done their checks, and are happy to be neighbours. For a broadcast network, this is where DR and BDR elections take place.

Any routers that are DROthers will not move past this state. Unless of course, a DR or BDR fails, and they get promoted.

The 2-Way state is a key milestone in this process. The routers are essentially neighbours at this point.

Now the routers need to start sharing topology information. In the ExStart state, one router in each network segment is chosen to be the master. This is the router with the highest Router-ID, which is not necessarily the DR.

The master router is the one that gets to talk first. It initiates the exchange of routing information. It’s in charge of synchronizing databases with other routers.

The Exchange state is where neighbours exchange DBD packets. Remember, these contain LSA headers, which are summary information about the network. 

The point of this is to find out if either router has records missing from the database. It’s likely that there will be some updates required.

The Loading state is where the real database building happens. Based on the DBDs, the neighbours know what they need more information about.

They will then send LSRs and LSUs to request and share network information. The goal of course, is to synchronize their databases.

Once the databases are up to date, they run the SPF algorithm, and find the best paths through the network.

And finally the Full state. This is where the adjacency is complete, and databases are synchronized.

This is the other state that we would expect healthy routers to be in. The other of course, is 2-Way, for DROther routers.

Why don’t we take a look at a router going through these states? For this, I’m going to use the debug ip ospf command. In particular, we’re looking at adjacencies.

Don’t forget, if you’re connected with telnet or SSH, you also need the terminal monitor command to see the logs. This is not required when we’re on the console.

So now, I’m going to configure OSPF on this router. The connected router is already configured.

Router ospf 10 starts the process, and the network command enables OSPF on an interface.

First we see the interface comes up within the OSPF process…

Then a ton of messages. If we look back through we can see the logs we see the DR and BDR election. That happens during the 2-Way state.

There’s the EXSTART state, where the other router is chosen to be the master.

Then the EXCHANGE state, where DBDs are going back and forth. 

This is followed by LSRs and LSUs, being used to build the OSPF database. Remember, that’s the LOADING state.

And finally it transitions from LOADING to FULL. The process has finished.

Of course, we should always remember to turn off the debugs when we’re done.


Now we can see if you’ve been paying attention… We have a few problems here, which you should be able to work out by looking at the output. Can you answer these questions?

For the lab, you need to configure OSPF through this topology. The basic IP addressing is already done, you just need to do the OSPF parts. That includes setting up the router ID’s based on loopback interfaces.

You’ll know you’re done when every network is reachable from any other network.

If you get through that, try disabling DR elections between R1 and R2. Also, between R2, R3, and R4, change R4 to be the DR, and R3 to be the BDR.

We haven’t finished looking into OSPF yet. We’ve got one more video coming, where we look at the routes that OSPF learns. In particular, how OSPF makes path decisions, and how we can manipulate them.