OSPF by Computernetworkingnotes
OSPF by Computernetworkingnotes
OSPF stands for Open Shortest Path First. OSPF is a link state open standard based routing
protocol. It was created in mid-1980. Since it is based on open standard, we can use it with
any vendor’s router.
Just like other routing protocols, OSPF also has its negatives.
Disadvantage of OSPF
This tutorial is the first part of our article “OSPF Routing Protocol Explained with examples".
You can read other parts of this article here.
Basically OPSF was created to fulfill the requirement of enterprise size network. To scale a
large size network it uses area concept. Area concept is similar to Subnetting. It allows us to
separate the large internetwork into smaller networks known as areas.
Along with Area concept OSPF also supports Autonomous System (AS). Just like area, AS
also divide a large network into smaller networks.
Difference between AS and Area concept
Area concept is a feature of OSPF. It is limited only with OSPF. We cannot use it with other
routing protocol.
AS is an independent concept originally defined in RFC 1771. We can use it with any routing
protocols which understand its concept.
AS
An AS is a group of networks running under a single administrative control. This could be our
company or a branch of company. Just like Subnetting AS is also used to break a large
network in smaller networks.
AS creates a boundary for routing protocol which allow us to control how far routing
information should be propagated. Beside this we can also filter the routing information
before sharing it with other AS system. These features enhance security and scalability of
overall network.
Basically AS concept was developed for large networks. Routing protocols which were
developed for small networks such as RIP do not understand the concept of AS systems.
IGP (Interior Gateway Protocol) is a routing protocol that runs in a single AS such as RIP,
IGRP, EIGRP, OSPF and IS-IS.
EGP (Exterior Gateway Protocol) is a routing protocol that performs routing between
different AS systems. Nowadays only BGP (Border Gateway Protocol) is an active EGP
protocol.
Public AS Numbers: - We only need to use public numbers if we are going to connect our
AS with Internet backbone through the BGP routes from Internet. IANA (Numbers Authority)
controls the public AS numbers.
Private AS Numbers: - Private AS numbers are used to break our internal network into the
smaller networks. We can use any valid AS number in our network unless we connect it with
public network. In above example we used two AS numbers 10 and 20 to divide our company
network.
In OSPF implementation, routers which connect two different ASes are known as autonomous
system boundary router (ASBR). In an OSPF network any router can become ASBR.
Connecting multiple ASes is a complex process. Luckily Cisco understood this and pushed
this hard topic in CCNP exam. Till associate level exams we only need to focus on single AS
design.
OSPF implements two levels hierarchy with areas: backbone and area off backbone.
Backbone
Backbone is the central point of this implementation. Routers running in this area required to
maintain a complete database of entire network. All areas need to connect with this area
through a physical link or via a virtual link if physical link is not possible.
Area off backbone is the extension of backbone. Routes running in this area required to
maintain an area specific database instead of complete database. This is a cool feature. It will
speed-up the convergence time.
ABR
Area Border Router (ABR) is a bridge between Backbone and Area off backbone. With
correct IP addressing we can summarize routes information on this router.
IR
IR (Internal Router) is a router running in area off backbone. IR only needs to maintain an
area centric local database.
Let’s put all these together in a simple example. Assume that our company has 600 hosts. It
decided to use three class C subnets; 192.168.0.0/24, 192.168.1.0/24 and 192.168.2.0/24.
Each subnet has 200 hosts.
For easy administration these subnets are divided in smaller networks. With VLSM default
subnet /24 is subnetted in /29. When we break a default class C Subnet /24 in Subnet /29, it
produces 32 networks (8 hosts in each network).
In this situation if we use a classical flat network design, routers need to learn and advertise
96 (32 + 32 + 32) networks. With hierarchy design we can reduce this number to 34 (32 + 1 +
1). Well…. how could this be possible?
Create three areas (area 0, area 1 and area 2) one for each default subnet.
In a hierarchy design we always start from area 0. No matter how many areas you create, you
should always start counting from 0. Area 0 has special privilege in OSPF implementation.
OSPF treats area 0 as backbone area. Assign area 0 to our first subnet 192.168.0.0/24.
Create area 1 and assign it to subnet 192.168.1.0/24. Finally create area 2 and assign it to
subnet 192.168.2.0/24.
ABR is a special router which connects two areas. In a proper implementation it should share
only summarized route information with remote area.
Through routes summarization on ABR, other areas would see only summarized networks for
respective areas instead of full subnets. By doing this we are reducing the amount of
information that ABR need to share.
Have a look on following figure. It illustrates our implementation. Area 0 has 32 sub networks
(/29) created from one default network 192.168.0.0/24. ABR of area 0 is sharing only one
route 192.168.0.0/24 with area 1 and area 2 instead of all internal routes connecting 32
networks.
Hierarchy design limits network instability in a single area. It also reduces routing overhead
and speed up the convergence time. If properly implemented with VLSM, it can scale an
enterprise size network. Vice versa a little mistake can make it a nightmare.
I have a good news for you, Cisco tests hierarchical design in CCNP. So you can fee relax
until you prepare for CCNP exam. Till associate level exam Cisco limits designing part to
single area. We will use area 0 to explain the remaining article. Of-course we can use any
other valid area number, but it is good practice to take correct learning path from beginning.
And we know that in a hierarchy design Area 0 stands on the top.
Okay let’s remove other areas from network and make it simple. Now we have only single
area to study. Let’s explore it step by step. You learned that OSPF is a link state protocol.
What does it mean? What is link? And what is state?
Link
Link is an interface running OSPF routing protocol. When we add an interface in OSPF
process, it will be considered as a link.
State
State is the information associated with a link (interface). A link (interface) contains several
information such as IP address, up/down status, subnet mask, type of interface, type of
network , bandwidth and delay. OSFP consider this information as state.
LSA
Link state advertisement (LSA) is data packet. It contains link-state and routing information.
OSPF uses it to share and learn network information.
LSDB
Every OSPF router maintains a Link state database (LSDB). LSDB is collection of all LSAs
received by a router. Every LSA has a unique sequence number. OSPF stores LSA in LADB
with this sequence number.
Upon initialization or due to any change in network information, an OSPF speaking router
generates a LSA. This LSA includes the collection of all link-states or link state updates. All
routers exchange LSA by flooding. Each router that receives a LSA will store a copy of it in
its LSDB then propagate the LSA to other routers.
For example figure display a basic flooding process where R1 is generating LSA and flooding
it to the other routers of network.
R2 and R5 are the first clients who receive this LSA. They will update their LSDB and then
forward it to R3 and R6 respectively. R3 and R6 will update their database with this LSA and
then forward it to R4. From here only one router either R3 or R6 will be able to forward this
LSA to R4. Why does this happen?
Because flooding process has a mechanism to prevent the loops. Before sending a LSA to
neighbors, it asks them “Do you have this LSA?” If neighbor reply with yes, it will avoid
flooding that LSA to this neighbor. If neighbor reply with no, it will flood that LSA to this
neighbor. Thus R4 will only receive this LSA only from one neighbor; either R3 or R6.
OSPF routers share LSA only with neighbors. To become an OSPF neighbor, certain
conditions need to be matched. In next part of this article we will explain those conditions in
detail with examples.
OSPF routers share routing information only with neighbors. OSPF uses hello packets to
discover neighbors in segments. A hello packet contains some essential configuration values
that must be same on both routers who want to build an OSPF neighborship. In this tutorial
we will explain these configuration values in detail with example.
In order to become OSPF neighbor following values must be match on both routers.
Area ID
Authentication
Hello and Dead Intervals
Stub Flag
MTU Size
This tutorial is the second part of our article “OSPF Routing Protocol Explained with
examples". You can read other parts of this article here.
Area ID
OSPF uses area concept to scale an enterprise size network. I have explained OSPF Areas in
first part of this article. Just for reference, OSPF areas create a logical boundary for routing
information. By default routers do not share routing information beyond the area. So in order
to become neighbor, two routers must belong to same area. Here one confusing fact needs to
clear. Area is associated with specific interface, not with entire router. This allows us to
configure the router in multiple areas. For example a router that has two interfaces; Serial
interface and FastEthernet interface, can run Serial interface in one area and FastEthernet in
another area. It means link which connects two routers need be in same area including its both
ends interface. Beside this interfaces should have same network ID and subnet mask.
Following figure illustrate a simple OSPF network. In this network R1 is eligible to form
neighborship with R4 and R2 respectively on S0/0 and F0/0.
I have question for you. Why neighborship cannot be built between R1 and R3?
Authentication
To enhance the security of network, OSPF allows us to configure the password for specific
areas. Routers who have same password will be eligible for neighborship. If you want to use
this facility, you need to configure password on all routers which you want to include in
network. If you skip any router, that will not be able to form an OSPF neighborship.
Suppose that our network has two routers R1 and R2. Both routers are connected with direct
link and meet all criteria mentioned in first requirement. What if I configure password in R1
and leave R2 as it is? Will it form neighborship with R2?
Well in this situation neighborship will not take place. Because when both routers see each
other’s hello packet in segment, they try to match all configure values including password
field. One packet has a value in password filed while other has nothing in it. In this case
routers will simply ignore each other’s packet.
Hello packets are the special type of LSAs (Link State Advertisements) which are used to
discover the neighbors in same segment. And once neighborship is built same hello packets
are used to maintain the neighborship. Hello packets contain all necessary information that is
required to form a neighborship. Hello packets are generated and distributed in hello interval
via multicast. Hello interval is the length of time in seconds between the hello packets.
Default hello interval is 10 seconds.
Dead Intervals
As we already know once neighborship is built, hello packets are used to maintain the
neighborship.
So a router must see hello packets from neighbor in particular time interval. This time interval
is known as dead interval. Dead interval is the number of seconds that a router waits for hello
packet from neighbor, before declaring it as dead.
Default dead interval is 40 seconds. If a router does not receive hello packet in 40 seconds
from neighbor it will declare that as dead. When this happens, router will propagate this
information to other OSPF neighboring router via LSA message.
Hello and dead interval must be same between two neighbors. If any of these intervals are
different, neighborship will not form.
This value indicates that whether sending router belong to stub area or not. Routers who want
to build OPSF neighborship must have same stub area flag.
Just like another areas, Stub area also has some specific meanings in OSPF hierarchal design.
A stub area can have only single exit point from that area.
Stub area cannot be used as a transit area for virtual links.
Routing from stub area to outside of the area should not have to take an optimal path.
Any external networks (redistributed from other protocols into OSPF) should not be
flooded in stub area.
Configuring a stub area reduces the size of topology table inside that area. Thus routers
running in this area require less memory.
MTU
Consider a situation where MTU setting between two OSPF routers does not match. If the
router with the higher MTU sends a packet larger than the MTU set on the neighboring router,
the neighboring router will ignores this packet. This function creates serious problem for
database updates. Database updates are heavier in nature. Once an update becomes larger than
the configured MTU setting, it needs to be spilt. In a case of miss match MTU, database
update may lost few bytes. Due to this, OSPF will ignore that update and cannot sync with
database. It will be stuck in Exstart/Exchange stage.
It is always worth to spend a little extra time in matching optional values along with
compulsory values. Matching configuration values will make troubleshooting easier.
That’s all for this part. In next part we will learn how OSPF routers build neighborship in
detail with examples.
OSPF routers go through the seven states while building neighborship with other routers.
1. Down state
2. Attempt/Init state
3. Two ways state
4. Exstart state
5. Exchange state
6. Loading state
7. Full state
If you are an intermediate or advance leaner, grab this tutorial from where you want. But if
you are a beginner or Cisco exam candidate, I suggest you to go through the entire article
without skipping any section. Believe me OSPF is the most complex routing protocol among
the routing protocols which you will study in CCNA.
Let’s understand these states with a simple example. Assume that our network has two routers
running OSPF routing protocol. Routers are connected with each other via serial link. We just
turned on both routers simultaneously.
Down state
At this point both routers have no information about each other. R1 does not know which
protocol is running on R2. Vice versa R2 have no clue about R1. In this stage OSPF learns
about the local interfaces which are configured to run the OSPF instance.
In down state routers prepares themselves for neighborship process. In this state routers
choose RID (Router ID). RID plays a big role in OSPF process. Before we move in next state
let’s understand what is RID.
RID
RID is a unique identifier of Router in OSPF network. It must be unique within the
autonomous system. Routers identify each other through the RID in AS.
1. Manual configuration
2. Loopback interface IP configuration
3. Active interfaces IP configuration
Manual configuration
Because RID plays a significant role in network, OSPF allows us to configure it manually.
RID is 32 bit long. IP address is also 32 bit in length. We can use IP address as a RID. This
gives us more flexibility over RID. For example we can use a simple and sequential IP
scheme such as 1.1.1.1 for R1, 1.1.1.2 for R2, 1.1.1.3 for R3, 1.1.1.4 for R4, 1.1.1.5 for R5
and so on.
Router(config)#router ospf 1
Router(config-router)#router-id ip_address
If we have assigned RID manually, OSPF will not look in next two options. Suppose we did
not assign it through the command. In this situation OSPF will look in next option to find the
RID.
Loopback interface IP configuration
If loopback interface is configured, OSPF will choose its IP address as RID. If multiple
loopback interfaces are configured, highest IP address will be chosen from all loopback
interfaces configuration.
If loopback interface is not configured, OSPF will look in next and last possible place to
choose the RID.
OSPF will choose the highest IP address from all operational IP interfaces. We should not let
the OSPF to use this option. This option does not provide a fix RID which is very necessary
for network stability.
This option has several reasons which may force OSPF to recalculate the RID such as
Interface which IP address is chosen may go down or for troubleshooting we may enable /
disable the interfaces.
Key points
OSPF will follow the sequence (Manual configuration => Loopback interface => Active
interface) of options while selecting RID. If RID is found, it will not look in next option.
OSPF will choose IP address only from operational IP interface. Operational means interface
should be listed as line is up and line protocol is up in the output of show ip interface brief
command.
When multiple IP addresses are available, OSPF will always pick highest IP address for RID.
For network stability we should always set RID from either router-id command or by using
loopback interfaces.
By default Router chooses OSPF RID when it initialized. Once RID is selected it will use that
RID until next reboot.
OSPF will not consider any change in RID which we make after initialization. We have two
options to implement new RID. Either reboots the router or clear the OPSF process with clear
ip ospf process command.
If OSPF fails to select the RID, it will halt the OSPF process. We cannot use OSPF process
without RID.
In down state router do following
Attempt/Init state
Neighborship building process starts from this state. R1 multicasts first hello packet so other
routers in network can learn about the existence of R1 as an OSPF router. This hello packet
contains Router ID and some essential configuration values such as area ID, hello interval,
hold down timer, stub flag and MTU. Essential configuration values must be same on routers
who want to build an OSPF neighborship.
In previous part of this article I explained essential configuration values in detail with
example. For this tutorial I assume that these values match on both routers. If essential
configuration values match, R2 will add R1 in his neighbor Table.
In Init state routers do following
R1 will generate a hello packet with RID and essential configuration values and send it out
from all active interfaces.
The hello packets are sent to the multicast address 224.0.0.5.
R2 will receive this packet.
R2 will read RID from packet and look in neighbor table for existing entry.
If match found, R2 would skip neighborship building process and reset the dead interval
timer for that entry.
If OSPF does not find a match in neighbor table, it will consider R1 (sender router) as a
possible OSPF neighbor and start neighborship building process.
R2 will match its essential configuration values with values listed in packet.
If all necessary configuration values match, R2 will add R1 in its neighbor table.
At this moment R1 has no idea about R2. R1 will learn about R2 when it will respond.
Before we enter in third state, let’s have a quick look on attempt state.
Attempt
In Non-broadcast multi-access environment such as Frame Relay and X.25, OSPF uses
Attempt state instead of Init state. OSPF uses this state only if neighbors are statically
configured with neighbor command. In this situation, it does not have to discover them
dynamically. As it already knows the neighbors, it will use unicast instead of multicast in this
state.
Once neighborship is built, OSPF uses hello packets as keep alive. If a router does not receive
a hello packet from any particular neighbor in dead interval, it will change its state to down
from full. After changing the state it will make an effort to contact the neighbor by sending
Hello packets. This effort is made in Attempt state.
Basically Both Init and Attempt states describe similar situation where one router has sent a
hello packet and waiting for response.
If essential configuration values match, R2 will add R1 in neighbor table and reply with its
hello packet. As R2 knows the exact address of R1, it will use unicast for reply. Beside RID
and configuration values, this packet also contains the R2’s neighbor table data. As we know
R2 has already added R1 in its neighbor table. So when R1 will see R2’s neighbor table data,
R1 would also see its name in this data. This will assure R1 that R2 has accepted its
neighborship request.
At this point:-
R2 has checked all essential configuration values listed in hello packet which it received from
R1.
R2 is ready to build neighborship with these parameters.
R2 has added R1 in its neighbor table.
To continue the neighborship process, R2 has replied with its hello packet.
R1 has received a reply from neighbor, with its own RID listed in R2’s neighbor table.
Now it is R1’s turn to take action on R2’s reply. This reply would be based on hello packet
which it received from R2. As we know that this hello packet contains one additional field;
Neighbor table data field which indicates that this is not a regular neighbor discovery hello
packet. This packet is a reply of its own request.
It will read RID from hello packet and look in its neighbor table for existing entry.
If a match for RID found in neighbor table, it would reset the dead interval timer for that
entry.
If a match is not found in neighbor table, it would read the essential configuration values
from packet.
It will match configuration values with its own values. If values match, it will add R2’s RID in
neighbor table.
If packet contains neighbor table data with its own RID, it will consider that as request to
enter in two way state.
R1 will reply with a hello packet which contains its neighbor table data.
This packet is a confirmation of two ways state.
Fine, our routers are neighbor now. They are ready to exchange the routing information.
Before we understand how routers will exchange routing information, we need to understand
the types of network. OSPF uses different types of exchange process for different types of
network.
It is a Cisco specific network type. It connects a single pair of routers. HDLC and PPP are
example of point to point network type. In this type of network:-
I will explain the terms adjacencies, DR, BDR and AllSPFRouters shortly.
Broadcast Networks
Broadcast networks are capable in connecting more than two devices. Ethernet and FDDI are
the example of broadcast type network. In this type of network:-
NMBA
Non-broadcast Multi-access networks are also capable in connecting more than two devices.
But they do not have broadcast capability. X.25 and Frame Relay are the example of NMBA
type network. In this type of network:-
As network does not have broadcast capability, dynamic network discovery will not be
possible.
OSPF neighbors must have to define statically.
All OSFP packets are unicast.
DR and BDR are required.
Point to multipoint
So what does DR and BDR actually do? Why do we need them in our network?
DR and BDR
OSPF routers in a network which need DR (Designated router) and BDR (Backup designated
router) do not share routing information directly with all each other’s. To minimize the
routing information exchange, they select one router as designated router (DR) and one other
router as backup designated router (BDR). Remaining routers are known as DROTHERs.
All DROTHERs share routing information with DR. DR will share this information back to
all DROTHERs. BDR is a backup router. In case DR is down, BDR will immediately take
place the DR and would elect new BDR for itself.
Main reason behind this mechanism is that routers have a central point for routing information
exchange. Thus they need not to update each other’s. A DROTHER only need to update the
central point (DR) and other DROTHERs will receive this update from DR.
Practically this will cut the numbers of routing information exchange from O(n*n) to O(n)
where n is the number of routers in a multi-access segment.
For example following figure illustrates a simple OSPF network. In this network R4 is
selected as DR and R5 is selected as BDR. DROTHERs (R1, R2 and R3) will share routing
information with R4 (DR) and R5 (BDR), but they will not share routing information with
each other. Later DR will share this information back to all DROTHERs.
OSPF uses priority value to select DR and BDR. OSPF router with the highest priority
becomes DR. Router with second highest priority becomes BDR. If there is a tie, router with
the highest RID will be chosen.
Priority value is 8 bit in length. Default priority value is 1. We can set any value from range 0
to 255. We can change it from Interface Sub-configuration mode with ip ospf priority
command.
We can force any router to become DR (Highest) or BDR (Second highest) by changing its
priority value. If we set priority value to 0, it will never become DR or BDR.
For example following figure illustrates a simple OPSF network. In this network we have five
routers. We do not want that R3 becomes DR or BDR. So we changed its default priority
value to 0. Now let’s see how these routers select DR and BDR.
Condition 1:- Use the highest priority value
This condition says “Arrange all routes in high to low order and pick the highest for DR and
second highest for BDR”. If we arrange our routers in high to lower order, R3 will stand at
last. Remaining routers have equal priority value. So at the end of this condition we have a tie
between four routers.
This condition says “If there is a tie, use RID value to choose”. In our network we have a tie
between four routers, so our routers will use RID to elect the DR and BDR. Arranging routers
in high to low order will give us the DR and BDR.
As we know that there are two types of network; networks which do not require DR and BDR
for exchange process and networks which require DR and BDR for exchange process.
In first type all routers will exchange routing information with each other’s. In second type
DROTHERs will exchange routing information with DR and BDR.
Routers which will exchange routing information are known as adjacent. Relationship
between two adjacent is known as adjacency. This terminology is associated with interfaces.
A router which has two interfaces can be adjacent in one interface and DROTHER in other
interface.
For example following figure illustrates an OSPF running NBMA network. In this network;
R3 will build adjacency with R1, so in this relationship they will be considered as Adjacent.
R3 will not build adjacency with R4, so in this relationship they will be considered only
DROTHER.
In a network which doesn’t require DR and BDR, all routers will be considered as Adjacent
and relationship between them will be considered as Adjacency.
Only adjacent routers will enter in next states to build the adjacency.
Exstart state
Routers who decided to build adjacency will form a master / slave relationship. In each
adjacency router who has higher RID will become master and other will become slave. Do not
mix Master /Slave relationship with DR/ BDR/ DROTHER relationship. Both terms look
similar but have different meaning. DR/ BDR/ DROTHER relationship is built in a segment
and have a wider meaning while Master / Slave relationship is built between two interfaces
which need to exchange routing information. Master / Slave relationship has limited purpose.
It is used to decide the Router who will start exchange process. Always Master starts
exchange process.
Once routers settle down on Master/Slave, they will establish the initial sequence numbers
which will be used in routing information exchange process. Sequence numbers insure that
routers get most accurate information.
Exchange state
In exchange state, Master and slave decide how much information needs to be exchange. A
router that has more than one interface may learn same network information from different
sources. An OSFP router is smart enough to filter the updates before receiving it. It will ask
only for the updates which it does not have. In this state, routers will filter the updates which
need be to exchange.
Before we learn how routes will filter this information, let’s understand few relative terms.
LSA and LSDB are explained in the first part of this tutorial. To maintain the flow of this
article I am including the summary of these terms here again.
LSA
Link state advertisement (LSA) is a data packet which contains link-state and routing
information. OSPF uses it share and learn network information.
LSDB
Every OSPF router maintains a Link state database (LSDB). LSDB is collection of all LSAs
received by a router. Every LSA has a sequence number. OSPF stores LSA in LADB with
this sequence number.
DBDs
Database description packets (also referred as DDPs) contain the list of LSA. This list
includes link state type, cost of link, ID of advertising router and sequence number of link.
Make sure you understand this term correctly. It is only a list of all LSAs from its respective
database. It does not include full LSAs.
In this state, routers exchanges DBDs. Through DBDs routers can learn which LSAs they
already have. For example in following network R1 has A1, A2 and B2 LSAs in its LADB.
So it will send a list of these LSAs to R2. This list is a DBDs. R2 will send an
acknowledgment of receiving the list with LSACK signal. Same as R2 will send its DBDs to
R1 and R1 would acknowledge that with its LSACK single.
LSR
Upon receiving DBDs, routers will compare it with their own LADB. Thus they will learn
what they need to order. For example R1 received a check list (DBDs) of A1 and B1. When it
will compare this list with its own LSA database (LADB), it will learn that it already has A1.
So it does not need to order this LSA again. But it does not have B1, so it needs to order for
this LSA. After a complete comparison, both routers will prepare a list of LSAs which they do
not have in their own LADB. This list is known as LSR (Link State Request).
What other have (DBDs) – What I have (LADB) = What I need to order (LSR)
At the end of this state both routers have a list of LSAs which need to be exchanged.
Loading state
In this state actual routing information is exchanged. Routers exchange LSAs from LSR list.
Routers will use LSU (Link state update) to exchange the LSAs. Each LSA contains routing
information about a particular link. Routers also maintain a retransmission list to make sure
that every sent LSA is acknowledged.
For example following figure illustrates loading state of above example. R1 sent a LSU which
contain two LSAs but it received acknowledgement of only one, so it had to resend lost LSA
again.
This exchange process will continue till router has any unsent LSA in LSR list.
Full state
Full state indicates that both routers has been exchanged all LSAs from LSR list. Now they
have identical LSDB.
Adjacent routers remain in this state for life time. This state also referred as adjacency. If any
change occurs in network, routers will go through this process again.
Maintaining adjacency
That’s all for this part. In next part, I will explain configuration part of OSPF.
To keep this tutorial simple, I used terms neighbor and adjacencies synonymously.
Technically both terms are related but have different meanings especially in OSPF.
Neighboring routers are defined in RFC 2328.
Neighboring routers are the routers that have interfaces in common network.
For demonstration we will use packet tracer network simulator software. You can use real
Cisco devices or any other network simulator software for following this guide.
Initial IP Configuration
Assign IP address to PC
Double click PC0 and click Desktop menu item and click IP Configuration. Assign IP
address 10.0.0.2/8 to PC0.
Repeat same process for Server0 and assign IP address 20.0.0.2/8.
Double click Router0 and click CLI and press Enter key to access the command prompt of
Router0.
Four interfaces FastEthernet0/0, FastEthernet0/1, Serial 0/0/0 and Serial0/0/1 of Router0 are
used in this topology. By default interfaces on router are remain administratively down during
the start up.
We need to configure IP address and other parameters on interfaces before we could actually
use them for routing. Interface mode is used to assign the IP address and other parameters.
Interface mode can be accessed from global configuration mode. Following commands are
used to access the global configuration mode.
Router>enable
Router# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#
From global configuration mode we can enter in interface mode. From there we can configure
the interface. Following commands will assign IP address on FastEthernet0/0 and
FastEthernet0/1.
Serial interface needs two additional parameters clock rate and bandwidth. Every serial
cable has two ends DTE and DCE. These parameters are always configured at DCE end.
We can use show controllers interface command from privilege mode to check the cable’s
end.
Fourth line of output confirms that DCE end of serial cable is attached. If you see DTE here
instead of DCE skip these parameters.
Router(config-if)#clock rate 64000 In real life environment this parameter controls the data
flow between serial links and need to be set at service provider’s end. In lab environment we
need not to worry about this value. We can use any valid clock rate here.
Router(config-if)#bandwidth 64 Bandwidth works as an influencer. It is used to influence
the metric calculation of OSPF or any other routing protocol which uses bandwidth parameter
in route selection process. Serial interface has default bandwidth of 1544Kbps. To explain,
how bandwidth influence route selection process we will configure (64Kbps) bandwidth on
three serial DCE interfaces of our network; R0’s Se0/0/0, R1’s Se0/0/1 and R2’s Se0/0/0.
Router1
Router2
As I mention earlier, serial interface has a default bandwidth of 1544Kbps. If we don’t assign
any custom bandwidth, router would use default bandwidth. To see this feature in action we
will not assign bandwidth on remaining routers.
Router6
Router5
Router3
Router4
Great job we have finished our half journey. Now routers have information about the
networks that they have on their own interfaces. Routers will not exchange this information
between them on their own. We need to implement OSPF routing protocol that will insist
them to share this information.
To be on same track I have uploaded my practice topology. Use this if you want to skip above
IP configuration part.
This command will enable OSPF routing protocol in router. Process ID is a positive integer.
We can use any number from 1 to 65,535. Process ID is locally significant. We can run
multiple OSPF process on same router. Process ID is used to differentiate between them.
Process ID need not to match on all routers.
Network command allows us to specify the interfaces which we want to include in OSPF
process. This command accepts three arguments network number, wildcard mask and area
number.
Network number
Network number is network ID. We can use any particular host IP address or network IP
address. For example we can use 192.168.1.1 (host IP address) or we can use 192.168.1.0
(Network IP address). While targeting a specific interface usually we use host IP address
(configured on that interface).
While targeting multiple interfaces, we use network IP address. So any interface that belongs
to specified network ID will be selected.
Wildcard mask
Wildcard mask are used with network ID to filter the interfaces. Wildcard mask is different
from subnet mask. Subnet mask is used to separate the network portion and host portion in IP
address. While wildcard mask is used to match corresponding octet in network portion.
Wildcard mask tells OSPF the part of network address that must be matched. Wildcard masks
are explained with examples in access list tutorials of this category.
Key points
0 (Decimal – octet format) Wildcard mask indicates that corresponding octet in network
address must be matched exactly.
255 (Decimal – octet format) Wildcard mask indicates that we don’t care about
corresponding octet in network address.
For example
0 (Binary – bit format) Wildcard mask indicates that corresponding bit in network address
must be matched exactly.
255 (Binary – bit format) Wildcard mask indicates that we don’t care about corresponding bit
in network address.
OSPF is a classless protocol. With wildcard we can also filter Subnetted networks. In classes
implementation usually we use Subnetted networks. For example consider following figure
A classless routing protocol such as OSPF goes beyond the default boundary of mask and
work well with Subnetted networks. With wildcard mask we can easily filter Subnetted
networks.
With wildcard we are no longer limited with default boundaries. We can match Subnetted
networks as well as default networks.
For example we want to exclude serial interfaces in above configuration. We can use a
wildcard mask of 0.0.0.255 to match the subnet mask of /24.
Above commands will ask router to match /24 bits of address instead of default /16 bits. Now
router will look for 172.168.1.x and 172.168.2.x network. Our serial interfaces have
172.168.3.0/24 and 172.168.4.0/24 networks which do not fall in these search criteria.
Let’s take one more example, if we use following network command, which interfaces would
be selected.
In this case valid host IP addresses are 192.168.0.1 and 192.168.0.2. So any interface that has
these IP address would be selected. /30 network is usually used for serial link connection
which need only two valid host IP addresses; one for each end.
If you are unfamiliar with wildcard mask, I suggest you to check our tutorials on access lists
configuration in this category. In those tutorials wildcard masks are explained in detail with
examples.
For this tutorial let’s move on third argument. Third argument which network command
accept is area number. This parameter say router to put matched interface in specified area.
OSPF areas are explained in second part this article.
Now we know the essential commands for configuration. Let’s implement them in our
network.
OSPF configuration
Router0
Router1
Router2
Router6
Router5
Router4
Router3
That’s it. Our network is ready to take the advantage of OSPF routing. To verify the setup we
will use ping command. ping command is used to test the connectivity between two devices.
We have two routes between source and destination. tracert command is used to know the
route which is used to get the destination.
Access the command prompt of PC1 and use ping command to test the connectivity from
Server0. After that use tracert command to print the taken path.
Great! We have successfully implemented OSFP routing in our network.
If you did not get the same out as explained in this tutorial, use this configured topology to
cross check your topology and find out the reason.
Download OSPF Practice Topology with OSPF configuration
Summary
Command Description
Router(config-router)#network
Enable OSPF with area 0 on matching interface.
10.10.0.0 0.0.255.255 area 0
Router(config-if)#ip address
Assign IP address to loopback interface.
192.168.250.250 255.255.255.0
Router(config-router)#router-id
Set 1.1.1.1 as router ID
1.1.1.1
Router(config)#interface serial
Inter in sub interface configuration mode
0/0
Router(config-if)#ip ospf priority Used to influence DR/BDR selection process. Valid range is 0 to
100 255. 0 makes router ineligible for DR/BDR while 255 makes router
guaranteed DR/BDR. Higher priority value means higher chance of
Command Description
becoming DR/BDR.
Router(config-if)#ip ospf hello- Set hello interval timer to 15 seconds. Hello timer must be match
interval timer 15 on both routers in order become neighbors.
Router(config-if)#ip ospf dead- Set dead interval timer to 60 seconds. Dead interval timer must be
interval 60 match on both routers in order to become neighbor
Router#show ip route ospf Display all routers learned through OSPF from routing table
Router#show ip ospf interface Display information about all OSPF active interfaces
As we know upon initialization or due to any change in routing information an OSPF router
generates a LSA. This LSA (Link State Advertisement) contains the collection of all link-
states on that router. Router propagates this LSA in network. Each router that receives this
LSA would store a copy of it in its LSA database then flood this LSA to other routers.
After database is updated, router selects a single best route for each destination from all
available routes. Router uses SPF algorithm to select the best route.
Just like other routing algorithm SPF also uses a metric component called cost to select the
best route for routing table.
This tutorial is the last part of our article “OSPF Routing Protocol Explained with
examples". You can read other parts of this article here.
Logically a packet will face more overhead in crossing a 56Kbps serial link than crossing a
100Mbps Ethernet link. Respectively it will take less time in crossing a higher bandwidth link
than a lower bandwidth link. OSPF uses this logic to calculate the cost. Cost is the inverse
proportional of bandwidth. Higher bandwidth has a lower cost. Lower bandwidth has a higher
cost.
Reference bandwidth was defined as arbitrary value in OSPF documentation (RFC 2338).
Vendors need to use their own reference bandwidth. Cisco uses 100Mbps (108) bandwidth as
reference bandwidth. With this bandwidth, our equation would be
Now we know the equation, let’s do some math and figure out the default cost of some
essential interfaces.
OSPF router builds a Shortest Path Tree. SPT is just like a family tree where router is the root
and destination networks are the leaves. SPF algorithm calculates the branch cost between
leaves and root. Branch with lowest cost will be used to reach at leaf. In technical language
route that has lowest cumulative cost value between source and destination will be selected
for routing table.
Best route for routing table = Route which has the lowest cumulative cost
Summary
OSPF uses SPT tree to calculate the best route for routing table.
A SPT tree cannot grow beyond the area. So if a router has interfaces in multiple areas, it
needs to build separate tree for each area.
SPF algorithm calculates all possible routes from source router to destination network.
Cumulative cost is the sum of the all costs of the outgoing OSPF interfaces in the path.
While calculating cumulative cost, OSPF consider only outgoing interfaces in path. It does not
add the cost of incoming interfaces in cumulative cost.
If multiple routes exist, SPF compares the cumulative costs. Route which has the lowest
cumulative cost will be chosen for routing table.
Now we have a basic understanding of SPF algorithm. In remaining part this tutorial we will
learn how SPF algorithm selects the best route from available routes.
Create a practice lab as illustrated in following figure or download this pre-created practice
lab and load in practice tracer.
Run show ip route ospf command from privilege mode to view all learned routes through the
OSPF protocol.
As output shows, Router0 has six routes from OSPF in routing table. We will go through the
each route and find out why it was chosen as the best route for routing table by OSPF.
Route 20.0.0.0
We have three routes to get 20.0.0.0/8 network. Let’s calculate the cumulative cost of each
route.
Via route R0 – R3 – R4 – R6
Via route R0 – R5 – R6
Among these routes, route R0-R5-R6 has the lowest cumulative cost. So it was selected as the
best route for routing table.
Route 192.168.0.4
Via Route R0 – R1
R0’s Serial 0/0/0 cost (1562) + R1’s Serial 0/0/1 cost (1562) = 3124 (Cumulative cost)
Via Route R0 – R3 – R4 – R6 – R2
R0’s Serial 0/0/1 cost (64) + R3’s Serial 0/0/0 cost (64) + R4’s Serial 0/0/1 cost (64) + R6’s
Serial 0/0/0 cost (64) + R2’s Serial 0/0/1 cost (64) = 320 (Cumulative cost)
Via Route R0 – R5 – R6 – R2
Ro’s FastEthernet 0/1 cost (1) + R5’s FastEthernet 0/0 cost (1) + R6’s Serial 0/0/0 cost (64)
+R2’s Serial 0/0/1 cost (64) = 130 (Cumulative cost)
Among these routes, Route R0 – R5 – R6 – R2 has the lowest cost so it was picked for
routing table.
Route 192.168.0.8
Via Route R0 – R1
R0’s Serial 0/0/0 cost (1562) + R1’s Serial 0/0/1 cost (1562) + R2’s Serial 0/0/0 (1562) =
4686 (Cumulative cost)
Via Route R0 – R3 – R4 – R6
R0’s Serial 0/0/1 cost (64) + R3’s Serial 0/0/0 cost (64) + R4’s Serial 0/0/1 cost (64) + R6’s
Serial 0/0/0 cost (64) = 256 (Cumulative cost)
Via Route R0 – R5 – R6
Ro’s FastEthernet 0/1 cost (1) + R5’s FastEthernet 0/0 cost (1) + R6’s Serial 0/0/0 cost (64) =
66 (Cumulative cost)
Among these routes, Route R0 – R5 – R6 has the lowest cost so it was picked for routing
table.
Route 192.168.1.4
Via Route R0 – R1 – R2 – R6
R0’s Serial 0/0/0 cost (1562) + R1’s Serial 0/0/1 (1562) + R2’s Serial 0/0/0 (1562) + R6’s
FastEthernet 0/0 (1) = 4687 (Cumulative cost)
Via R0 – R3 – R4 – R6
R0’s Serial 0/0/1 cost (64) + R3’s Serial 0/0/0 cost (64) + R4’s Serial 0/0/1 cost (64) + R6’s
FastEthernet 0/0 (1) = 193
Via R0 – R5
R0’s FastEthernet 0/1 cost (1) + R5’s FastEthernet 0/0 cost (1) = 2
Among these routes, Route R0 – R5 has the lowest cost so it was selected as the best route.
Route 192.168.2.4
Via Route R0 – R1 – R2 – R6 – R4
R0’s Serial 0/0/0 cost (1562) + R1’s Serial 0/0/1 cost (1562) + R2’s Serial 0/0/0 cost (1562) +
R6’s Serial 0/0/1 cost (64) + R4’s Serial 0/0/0 cost (64) = 4814
Via Route R0 – R5 – R6 – R4
R0’s FastEthernet 0/1 cost (1) + R5’s FastEthernet 0/0 cost (1) + R6’s Serial 0/0/1 (64) + R4’s
Serial 0/0/0 cost (64) = 130
Via Route R0 – R3
R0’s Serial 0/0/1 cost (64) + R3’s serial 0/0/0 cost (64) = 128
Among these routes, Route R0 - R3 has the lowest cost for destination 192.168.2.4.
Route 192.168.2.8
Via Route R0 – R3 – R4
R0’s Serial 0/0/1 cost (64) + R3’s Serial 0/0/0 cost (64) + R4’s Serial 0/0/1 cost (64) = 192
Via Route R0 – R1 – R2 – R6
Ro’s Serial 0/0/0 cost (1562) + R1’s Serial 0/0/1 cost (1562) + R2’s Serial 0/0/0 cost (1562) +
R6’s Serial 0/0/1 cost (64) = 4750
Via Route R0 – R5 – R6
R0’s FastEthernet 0/1 cost (1) + R5’s FastEthernet 0/0 cost (1) + R6’s Serial 0/0/1 cost (64) =
66
After selecting best route for each destination OSPF network look likes following figure.
OSPF Route cost Manipulation
Sub interface mode command Bandwidth is used to set the bandwidth of supported interface.
If bandwidth is set through this command, OSPF will use it. If bandwidth is not set, it will use
interface’s default bandwidth.
When we enable an interface, router automatically assign a bandwidth value to it based on its
type. For example serial interface has a default bandwidth value of 1544k. Until we change
this value with bandwidth command, it will be used where it is required.
Let me clear one more thing about bandwidth. Changing default bandwidth with bandwidth
command does not change actual bandwidth of interface. Neither default bandwidth nor
bandwidth set by bandwidth command has anything to do with actual layer one link
bandwidth.
This command is only used to influence the routing protocol which uses bandwidth in route
selection process such as OSPF and EIGRP.
We have already seen an example of this method in our example. We changed default
bandwidth (1544Kbps) to custom (64kbps) bandwidth on R0’s serial 0/0/0, R1’s serial 0/0/1
and R2’s serial 0/0/0. Due to this change R0 took another router for 192.168.0.4 network.
Via Route R0 – R1
R0’s Serial 0/0/0 cost (1562) + R1’s Serial 0/0/1 cost (1562) = 3124 (Cumulative cost)
Via Route R0 – R5 – R6 – R2
Ro’s FastEthernet 0/1 cost (1) + R5’s FastEthernet 0/0 cost (1) + R6’s Serial 0/0/0 cost (64)
+R2’s Serial 0/0/1 cost (64) = 130 (Cumulative cost)
Via Route R0 – R3 – R4 – R6 – R2
R0’s Serial 0/0/1 cost (64) + R3’s Serial 0/0/0 cost (64) + R4’s Serial 0/0/1 cost (64) + R6’s
Serial 0/0/0 cost (64) + R2’s Serial 0/0/1 cost (64) = 320 (Cumulative cost)
Among these routes, Route R0 – R5 – R6 – R2 has the lowest cost so it was picked for
routing table.
Well … Which route would have selected, if we had used default bandwidth?
Via Route R0 – R1
R0’s Serial 0/0/0 cost (64) + R1’s Serial 0/0/1 cost (64) = 128 (Cumulative cost)
Via Route R0 – R5 – R6 – R2
Ro’s FastEthernet 0/1 cost (1) + R5’s FastEthernet 0/0 cost (1) + R6’s Serial 0/0/0 cost (64)
+R2’s Serial 0/0/1 cost (64) = 130 (Cumulative cost)
Via Route R0 – R3 – R4 – R6 – R2
R0’s Serial 0/0/1 cost (64) + R3’s Serial 0/0/0 cost (64) + R4’s Serial 0/0/1 cost (64) + R6’s
Serial 0/0/0 cost (64) + R2’s Serial 0/0/1 cost (64) = 320 (Cumulative cost)
Among these routes, Route R0 – R1 has the lowest cost value so it would be selected for
routing table. Thus by changing interface bandwidth we actually influenced route selection
process.
Route R2 – R3
In this route we have two exit points. Both points have default 1oo Mbps speed.
Route R2 – R1 – R3
In this route we have three exit points. Two exit points (R2 and R1) have 1 Gbps link.
With default reference bandwidth R2 will choose Route R2 – R3, which is not good.
Sadly packet tracer does not include this command. For the practice of this command please
use other simulator software which support this command or use real router.
Let’s change reference bandwidth to 1000Mbps on all three routers using following
commands
{module in_art_slot_10}
Route R2 – R3
Route R2 – R1 – R3
In this case Route R2-R1-R3 will be selected, which is the shortest route for destination.
That’s all for this article. I hope now you have better understanding of OSPF Routing
protocol. In next article I will explain Access List in detail with examples.
Stub Area – An area that has a single exit point and blocks type 5/7 LSA types and receives
type 3/4 LSA’s with a default route (0.0.0.0/0) This type of stub area is an IETF standard. To
configure an Area as a stub you’d execute the area # stub in OSPF router configuration mode
on the ABR.
Not-So-Stubby-Area (NSSA) – This area allows a stub area to have characteristics of a stub
and non stub. External routes advertised into the OSPF autonomous system by am NSSA
advertising an LSA type 7 which is translated at the ABR to type 5 and forwarded into the
OSPF backbone. This type of stub area is an IETF standard. To configure an area as a NSSA
you’d execute the area # nssa in OSPF router configuration mode on the ABR.
Totally Stubby Area – Permits type 1 and 2 LSA’s while blocking types 3*/4/5/7 LSA’s.
*TSA’s receive a single type 3 LSA containing a default route to the ABR. This type of stub
area is an extension to OSPF created by Cisco. To configure an area as a totally stubby area
you’d execute the area # stub no-summary in OSPF router configuration mode on the ABR.
Totally NSSA – Is an area that permits LSA’s 1, 2 and 7 while blocking 3 4 and 5. This stub
area receives a default route from the ABR using a type 3 LSA. This type of stub area is an
extension to OSPF created by Cisco. To configure an area as a not so totally stubby area area
you’d execute the area # nssa no-summary in OSPF router configuration mode on the ABR.
When configuring an area stub type the command is executed on the ABR, however when
you specify an area as a stub on the ABR, all routers in that area must have be configured as a
stub by using the area # stub
In this lab you will configure and verify area 3 as a stub area and totally stubby area.
Command Description
This command is executed in OSPF configuration mode to configure
a specific area in OSPF as a stub. All routers in a stub area must have
area # stub the stub area flag set. This means that all routers in the area must be
configure with this command if the ABR has the area configured as a
stub.
This command is executed in OSPF configuration mode on the ABR
to specify an area as a not so stubby area. This type of area allows for
area # nssa redistributed routes as a type 7 lsa which is translated to a type 5 at
the ABR before being propagated through out the autonomous
system.
This command is executed in OSPF configuration mode on the ABR
area # stub no- to specify an area as a totally stubby area which only allows type 1
summary and 2 LSA’s and a single type 3 LSA (default route) from the ABR.
all other LSA’s are blocked.
This command is executed in OSPF configuration mode on the ABR
in OSPF configuration mode to specify a specific area as a not so
area # nssa no-
totally stubby area which blocks types 3 4 and 5 LSA’s but allows a
summary
single type 3 LSA as the default route and type 7 LSA’s internal to
the area.