Open Shortest Path First

The need for a dynamic routing protocol

As you probably know, in order for a Router to be able to forward the packets to the network, it must know how to reach that network. The information how to reach a network is stored in a router's routing table. If the router doesn't have a network in it's routing table it simply discards the packet.

Dynamic routing protocols enable the routers to LEARN about the networks from other Routers and then store those routes to their routing tables.

For a better understanding of basic routing concepts visit my previous blog post: Introduction to Routing.

What is OSPF?

OSPF is probably the most used interior gateway protocol, because unlike EIGRP it isn't vendor - proprietary. OSPF has support for Variable Length Subnet Masks (VLSM). OSPF is designed to operate inside an autonomous system.

OSPF doesn't advertise routes as distance/cost vectors like RIP or EIGRP for example, but instead it advertises states of interfaces and links. OSPF stores the link-state information in the Link State Database (LSDB). OSPF uses the Shortest Path First algorithm to populate the routing table.

How does OSPF work?

As we already stated, OSPF is designed to operate inside an autonomous system. OSPF has the concept of "areas", meaning our network can be divided into routing areas. Dividing the network into areas simplifies network maintenance and saves the resources, because the networks in an area can be summarized. There's a backbone area in OSPF network (area 0) and all the areas must connect to it. For now, we'll stick to one area, and later we'll get into multiple-areas OSPF design.

Like EIGRP OSPF has the concept of "neighbors". OSPF establishes neighbor relationships in order to exchange routing information. There are different types of neighborships called adjacencies. As EIGRP, in OSPF routers exchange Hello messages to become adjacent. OSPF routers become fully adjacent only with routers that are directly connected to the local router.

Depending on the type of network Routers elect a DR (Designated Router) and a BDR (Backup Designated Router). Designated Router reduces the need for network resources. The role of DR is to maintain the topology table of an entire network. Designated Router basically sends updates to other routers. This way all routers get their updates from a single source. It basically comes down to:

  1. Router sends update to DR using multicast.
  2. DR sends multicast updates to all other routers in the area.

BDR is just that - a Backup Designated Router. It listens to all the network updates, but it doesn't update others. The moment DR goes down, BDR takes it's place. If that happens, another BDR is elected.

Just how are the DR/BDR elected?

Contrary to the popular belief, a DR/BDR is actually a Router Interface, and not an entire Router. DR is elected during the election process. Basically election process goes through the following steps:

  • The Router with the highest OSPF priority. By default all routers have an OSPF interface priority of 1. If there's a Interface that has a higher priority than other it will win the election.
  • If all the interfaces have the same priority, DR is elected based on highest Router ID among all the participating routers.

Router ID is obtained in the following way:

  1. It can be configured manually. If it's configured manually router uses the configured value as Router ID. If it isn't configured manually router calculates it's own Router ID.
  2. If there are Loopback interfaces, the highest IP address assigned to any Loopback interface of the router becomes Router ID.
  3. If there aren't any Loopback interfaces, Router ID is the highest IP address of ANY active interface.

There are a couple of things worth remembering when talking about the OSPF election process. First of all, if Router interface is configured with an priority of 0, it can NEVER become DR or BDR. It simply doesn't participate in the election process.

Second of all, if the Router with the higher priority has joined the network AFTER the election is over, it won't have any impact. The DRs/BDRs remain the same. It can't become a DR or BDR until they both fail.

Which OSPF route is used?

There are different types of OSPF routes, each with it's own Administrative Distance.

  • Intra-Area

    Intra-area route is a route for a network that's inside the same area as the local router. For now this is really the only type you need to know, because we'll deal with a single-area OSPF first. But, for the sake of completeness, let's list other types as well.
  • Inter-Area

    Inter-Area route is a route that goes beyond an Area Border Router (Router that connects two OSPF areas).
  • External

    External route is a route that has been redistributed into OSPF from another routing protocol. It originates from an ASBR. (Autonomous System Border Router). The difference between External Type 1 and External Type 2 is how the cost is calculated.
    1. External Type 1

      This is the cost of an external route as advertised plus the internal cost to reach the ASBR.
    2. External Type 2

      This is simply an external cost, it doesn't take into account the cost to reach the ASBR. Because the External Type 1 is more precise, it's preferred over External Type 2.

NOTE: We'll get into the details of what is ABR and what is ASBR in some other blog post.

OSPF cost

As with all routing protocols, OSPF calculates the cost of reaching a network. By default cost is calculated via a formula: cost = 108 / bandwidth.

However, the cost can only be compared in the same types of routes.

I think by now, you have a basic understanding of OSPF, enough for a simple configuration example. For first post about OSPF, let's configure a single-area OSPF, and we'll leave multi area OSPF and stubby areas for a future blog post.

Single-area OSPF

The configuration will be simple, just how to enable OSPF and advertise networks so that every point inside our network can be pinged. After that we'll configure a Loopback interface to simulate ISP connection and advertise that route through our network.

As always, routers will play the part of the hosts. First, let's configure them with addresses and default routes:

HOST1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
HOST1(config)#int f0
HOST1(config-if)#ip address
HOST1(config-if)#no shut

And default route:

HOST1(config-if)#ip route

And now for HOST2:

HOST2(config-if)#ip add
HOST2(config-if)#no shut
*Mar  1 00:01:02.527: %LINK-3-UPDOWN: Interface FastEthernet0, changed state to up
*Mar  1 00:01:03.527: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0, changed state to up
HOST2(config-if)#ip route

Next, let's configure R1's interfaces:

R1(config)#int f2/0
R1(config-if)#ip add
R1(config-if)#no shutdown
R1(config-if)#int f1/0
R1(config-if)#ip add
R1(config-if)#no shut
R1(config-if)#int serial 0/0
R1(config-if)#ip add
R1(config-if)#no shut

Now, let's configure OSPF on R1. NOTE that when configuring OSPF on a Router we need to configure Process ID. This is only locally important, so we can enter any number. We can even use the same OSPF process-id on multiple routers. This is used to differentiate multiple OSPF processes on a single router.

Also, for this Router, let's manually configure Router ID:

R1(config)#router ospf ?
  <1-65535>  Process ID
R1(config)#router ospf 100
R1(config-router)#router-id ?
  A.B.C.D  OSPF router-id in IP address format
R1(config-router)#network area 0
R1(config-router)#network area 0
R1(config-router)#network area 0

Now, let's configure R2, so that R1 can learn about the network, and R2 about the network, meaning the hosts will be able to communicate.

First, let's configure interfaces:

R2(config)#int f2/0
R2(config-if)#ip address
R2(config-if)#no shutdown
R2(config-if)#int fast 1/0
R2(config-if)#ip add
R2(config-if)#no shut
R2(config-if)#int s0/0
R2(config-if)#ip add
R2(config-if)#no shut

This time, we'll use the IP address of an Loopback Interface for OSPF Router ID. So, let's now just configure the Loopback interface:

R2(config-if)#interface loopback 0
*Mar  1 00:05:51.363: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up
R2(config-if)#ip address

And now for OSPF:

R2(config)#router ospf 202
R2(config-router)#network area 0
R2(config-router)#network area 0
R2(config-router)#network area 0
*Mar  1 00:07:46.367: %OSPF-5-ADJCHG: Process 202, Nbr on Serial0/0 from LOADING to FULL, Loading Done

See that? We got the message stating there's new adjacency, meaning R1 and R2 are now neighbors. Also, each R2 should have some routes from R1. Let's verify the neighborship and routing table:

R2#show ip ospf neighbor
Neighbor ID     Pri   State           Dead Time   Address         Interface           0   FULL/  -        00:00:38      Serial0/0
R2#show ip route ospf is subnetted, 3 subnets
O [110/65] via, 00:02:20, Serial0/0
O [110/65] via, 00:02:20, Serial0/0

OK, let's try to ping HOST1 from HOST2:

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 568/1260/1988 ms

As you can see, we already have connectivity. But now, let's just complicate things a bit and include R3 into our little network. First, let's configure the interfaces.

R3(config)#int f0/0
R3(config-if)#ip add
R3(config-if)#no shut
R3(config-if)#int f1/0
R3(config-if)#ip add
R3(config-if)#no shutdown

OK, now for OSPF on R3. This time, we won't configure Router ID, or Loopback Interface and the highest IP address will be chosen as a Router ID.

R3(config)#router ospf 300
R3(config-router)#network area 0
*Mar  1 00:10:48.491: %OSPF-5-ADJCHG: Process 300, Nbr on FastEthernet1/0 from LOADING to FULL, Loading Done
R3(config-router)#network area 0
*Mar  1 00:11:08.647: %OSPF-5-ADJCHG: Process 300, Nbr on FastEthernet0/0 from LOADING to FULL, Loading Done

Now, let's verify the Router ID:

R3#show ip ospf 300
 Routing Process "ospf 300" with ID
!!!! OUTPUT OMITTED !!!!!!!!!!!!!!!!!!!!!!!!!!!

NOTE that because R3 joined the network later after the DR has been chosen it isn't a DR even if it has the highest Router ID.

R3#sh ip ospf int fa0/0
FastEthernet0/0 is up, line protocol is up
  Internet Address, Area 0
  Process ID 300, Router ID, Network Type BROADCAST, Cost: 1
  Transmit Delay is 1 sec, State BDR, Priority 1
  Designated Router (ID), Interface address
!!!! OUTPUT OMITTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

So, how can there be an election if R3 didn't even participate? Simple. When the Interface is enabled in OSPF, the router starts sending Hellos. If it doesn't find a neighbor it simply elects itself as a DR, just as R1 did. We can even verify that:

R1#debug ip ospf adj
OSPF adjacency events debugging is on
*Mar  1 00:01:09.731: OSPF: end of Wait on interface FastEthernet1/0
*Mar  1 00:01:09.731: OSPF: DR/BDR election on FastEthernet1/0
*Mar  1 00:01:09.735: OSPF: Elect BDR
*Mar  1 00:01:09.735: OSPF: Elect DR
*Mar  1 00:01:09.739: OSPF: Elect BDR
*Mar  1 00:01:09.739: OSPF: Elect DR
*Mar  1 00:01:09.743:        DR: (Id)   BDR: none
*Mar  1 00:01:09.747: OSPF: end of Wait on interface FastEthernet2/0
*Mar  1 00:01:09.747: OSPF: DR/BDR election on FastEthernet2/0
*Mar  1 00:01:09.751: OSPF: Elect BDR
*Mar  1 00:01:09.751: OSPF: Elect DR
*Mar  1 00:01:09.755: OSPF: Elect BDR
*Mar  1 00:01:09.755: OSPF: Elect DR
*Mar  1 00:01:09.759:        DR: (Id)   BDR: none

Let's try and disconnect the link between R2 and R3 and see what happens. Simply right-click on the line that represents the cable and click "Delete". This is what happens:

*Mar  1 00:14:29.131: %OSPF-5-ADJCHG: Process 202, Nbr on FastEthernet1/0 from FULL to DOWN, Neighbor Down: Dead timer expired

Now reconnect them. They become neighbors once again. Now, let see what happened with DR election:

R3#show ip ospf interface fastethernet 0/0
FastEthernet0/0 is up, line protocol is up
  Internet Address, Area 0
  Process ID 300, Router ID, Network Type BROADCAST, Cost: 1
  Transmit Delay is 1 sec, State DR, Priority 1
!!!! OUTPUT OMITTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

OK, enough DR/BDR stuff, I'm sure you get it. Now, let's see what happened to R1's routes when we configured R3:

R1#sh ip route ospf is subnetted, 3 subnets
O [110/2] via, 00:00:58, FastEthernet1/0 is subnetted, 1 subnets
O [110/3] via, 00:00:58, FastEthernet1/0

So, R1 now reaches network via R3.

Only one thing left to do now. Let's configure a Loopback interface on R3 to simulate a connection to the ISP. We'll use OSPF to redistribute the default route through the network.

R3(config)#interface Loopback 1
*Mar  1 00:06:19.607: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback1, changed state to up
R3(config-if)#ip address

Now, let's create a default route and advertise it with OSPF. It simple, really. We use the default-information originate OSPF subcommand:

R3(config)#ip route Loopback 1
R3(config)#router ospf 300
R3(config-router)#default-information originate

Now, let's verify that the Routers have the default route. Let's see R2:

R2#sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route
Gateway of last resort is to network is subnetted, 1 subnets
C is directly connected, Loopback0 is subnetted, 3 subnets
C is directly connected, FastEthernet1/0
O [110/2] via, 00:01:14, FastEthernet1/0
C is directly connected, Serial0/0 is subnetted, 1 subnets
C is directly connected, FastEthernet2/0
O [110/3] via, 00:01:14, FastEthernet1/0
O*E2 [110/1] via, 00:01:21, FastEthernet1/0

Passive Interface

OK, we have finished our configuration. Now, just for one little tip. As we said earlier, router sends Hello messages on OSPF-enabled interfaces. But what if we don't want to send Hellos on some interfaces because, for instance, only hosts are connected to that interface, so sending Hellos to them is pointless?

Simple, we'll use the passive-interface OSPF subcommand. Passive interfaces simply don't send OSPF traffic, meaning Hellos won't be send via that Interface.

We don't need to send OSPF traffic via R1's Fast Ethernet 2/0 or R2's Fast Ethernet 2/0 because only hosts are connected to those interfaces. So, let's configure it:

R1(config)#router ospf 100
R1(config-router)#passive-interface fa2/0
R2(config)#router ospf 202
R2(config-router)#passive fa2/0

NOTE: OSPF adjacency can't be formed if one of the interfaces is passive! If you configure an interface as passive where an adjacency exists, the adjacency will drop!

So be careful to configure the right interface as passive!

That's it for this post, I hope it's been somewhat informative. In the some next blog post we'll deal with multi-area OSPF and other OSPF thingies, should be fun. Until next time I wish you all the best!

Comments are closed