SPF Algorithm and OSPF Router ID

SPF Algorithm

Where I live we use kilometers for measuring. Some are using inches, feet, yards, miles, a very archaic measurement system and thankfully Open Shortest Path First, or OSPF, has a better measurement system, doesn’t it?

It definitely does, and the term we associate with OSPF’s measurement system is, cost. Cost, that’s a term you need to ingrain in your memory, cost. It’s known as THE metric. So how far is a certain destination network away from this particular router? And you’ll notice that every router keeps track of their own cost to reach each of those different destination networks. By default it’s based on bandwidth for OSPF. It’s inversely proportional to bandwidth. So what that means is, if the bandwidth is really really low, it has a high cost, if the bandwidth is really really high, for example a 10 gigabit link, well then the cost would be low. So Shortest Path First Algorithm is adding up all the costs along the path to get to the destination network, and in the end its ultimate goal is to find the path with the lowest cost. So the best cost is the one that is the lowest. So how is it calculated? Well we have this reference value known as the reference bandwidth. And by default, this bandwidth is set to 100 Mbps. So since it’s set to 100 Mbps, when I divide that by the interface bandwidth, we’ll use 100 Mbps link in this example. We would have a cost of one, correct?

Well the cost would be one, and we can’t go lower than this, just so we’re clear, we don’t get into decimal points and things like that, but this begs the question now. There are network links that are faster than Fast Ethernet. What do we see nowadays? We see gigabit, 10 gigabit, 40 gigabit, soon there’ll be 100 gigabit. Well that’s getting to the extremes and vastly exceeds Fast Ethernet. But, let’s say I was comparing a Fast Ethernet link and its cost, and a 10 gigabit link which is very available, you can get lots of 10 gigabit link here right now. So Fast Ethernet and 10 gigabit, there’s a factor of 100 apart between the two. How would OSPF see those?

OSPF Cost966

Our default implementation of OSPF, they would both be seen equal, they both have a cost of one. The calculation would be a value greater than zero but less than one. We can’t have less than one as an option, so it’s rounded up to one, well so is the 100 megabit link. So anything greater than 100 Mbps will have a cost of one by default, and that’s a problem. That’s definitely a problem, because they are not equal; they’re treated equal but they’re not equal. So, how do we solve this problem? Can we change a value here to make it work? Am I going to reduce the speed of my 10 gigabit link or my 100 megabit link? No, that doesn’t make sense, what would we do?

Well there are really two ways, you could go interface by interface and change the cost, we don’t really want to get into that, that’s in the weeds, we would like to be at a higher level whenever we can. So what we do is we change the rules. We change the reference bandwidth, and we would change it to something like 10 Gigabit, we change it to 10 Gigabit, and some of the data center gear that Cisco puts out does in fact change the rules by default, but not our Cisco routers and our multilayer switches that we are speaking to you about. So it’s just something to bear in mind, and it would have severe ramifications if you had really high-speed links.

OSPF router ID

This is another one of those really critical elements of our OSPF discussion, the router ID. Now before we get into how this mechanism works, I want to share with you where it’s really used. There are two places where this is required to be stable, consistent, and doesn’t change when the router reboots. They are OSPF virtual links and filtering, when filtering is based on specific routers. Neither of those are topics for anywhere close to right now. However, router ID is something that can and should be controlled, and it’s because of those technologies that you’ll see deeper. It is elected from something that can change reboot to reboot, based on physical conditions. See here’s how the router ID is elected or at least when it is elected, that’s the bigger thing. Router ID is a numeric name, it’s chosen when the OSPF process starts. And let’s say we had a network that was big, that was ready, it’s been working for years and they were running OSPF. A router reboots in the OSPF world and that router was terminating a virtual link.

Well when the router reboots, it then restarts the OSPF protocol, and this is when the election occurs. Now the election looks at the physical interfaces, those physical interfaces have the IP addresses that are the input and the competing values in the election, but only the up/up interfaces get to compete; up/down, down/down administratively down, those don’t play in the election. So it is possible that at the time of reboot we’ll have different interfaces this time around that are up/up than last time. So we got to stabilize this, because we can see that they can change, they can absolutely change. So, now we’ve said by default it’s chosen from the IP addresses of up/up interfaces, but how do we weigh all of those IP addresses? I might have 10, I might have 15, or I might just have 2, how do I weigh that?

We look for the highest IP address. So simply start reading the IP address from left to right. If one of the IP addresses start with 10 another one starts with 192, well then the 192 one is higher, it will beat out the one that starts with 10. So we’re looking for the highest IP address. But we said we want stability. Do we get stability on physical interfaces? No physical interfaces can flap; they can go up, they can go down. As we said, when we reboot a device things can change, all right. So how do we introduce stability here with our router ID? Well one of the things we can do is manually set, just set it and forget it. Here’s my router ID using the router-id command and we’re done. It’ll always be that router ID.

RouterX(config)#router ospf 100
RouterX(config-router)#router-id 10.2.2.2
RouterX(config-router)#end
RouterX#copy running-config startup-config
RouterX#clear ip ospf process

But there’s another way to introduce stability, and that would be with loopback interfaces. What’s a loopback interface?

Well the best way to think about anything in networking that is looped back, is a boomerang. Let’s say you go to Outback Steakhouse, you look to wall you see that boomerang, it’s the aboriginal weapon, it’s a pretty cool weapon, right? You throw it, it comes back to you and it’s that behavior that is so unusual. We have loopback plugs where you send and get it right back in to test your transceivers to send and receive. You have loopback IP addresses, this is not a loopback IP address, that’s not what they’re saying it says loopback interface. But loopback IP addresses says send down through the TCP/IP stack and you’ll get it right back without going in fact to the data link layer or below. So what’s a loopback interface? Well it’s a fake interface, it’s a virtual interface, but if you send to it you’re really speaking right back to the router, and because it lacks physicality it is not dependent on whether your WAN link is up or not; it’s up if you router is up, and that enforces a great deal of stability which is why if we were to flowchart this out, first thing the router does says, did you tell me my router ID? If no, which is the default then we would say, do you have any of these special loopback interfaces, which are great, powerful, stable interfaces? You think why do I have them? It’s for things like this, to control your router, to stabilize your router, to have a consistent IP address when we’re managing it, those are all the reasons okay, the laboratories okay, so we look for this.

Now wait a minute. So I have a loopback interface. Let’s say I have two, let’s say I have two loopback interfaces, what then do I just give up?

We will look for the highest IP address associated with these loopback interfaces. So which one has the higher IP, that will be used as a router ID and we stop there. You see, we prefer loopback interfaces over physical interfaces because of the stability. So when OSPF is going through the process, it looks for the highest IP address associated with the loopback interface first. If it doesn’t find a loopback interface that’s when it’ll look at the active physical interfaces. So those physical interfaces that are up/up and then use the highest IP address out of those. So how do we put this together in a simple easy to remember sentence?

Higher is better but loopback wins. Ooh, I love that – higher is better but loopback wins!

There are many different ways that we can verify the OSPF router ID. But the quickest and easiest solution is to use show ip protocols. We’ll talk more about the output of show ip protocols shortly, when we dive deeper into our configuration of our OSPF, we’ll come back to this command.

Our Recommended Premium CCNA Training Resources

These are the best CCNA training resources online:

Click Here to get the Cisco CCNA Gold Bootcamp, the most comprehensive and highest rated CCNA course online with a 4.8 star rating from over 30,000 public reviews. I recommend this as your primary study source to learn all the topics on the exam. Cisco CCNA Gold Bootcamp
Want to take your practice tests to the next level? AlphaPreps purpose-built Cisco test engine has the largest question bank, adaptive questions, and advanced reporting which tells you exactly when you are ready to pass the real exam. Click here for your free trial. Cisco CCNA Gold Bootcamp