Open In App

Configuring OSPF Interface Cost in Cisco

Improve
Improve
Like Article
Like
Save
Share
Report

Pre-requisites: Open Shortest Path First (OSPF)

Open Shortest Path First (OSPF)  is a routing protocol that exchanges routing information within an autonomous system (AS). it is a link-state protocol that provides a more efficient and scalable way of routing traffic compared to distance vector protocols like RIP.it uses a hierarchical network design with areas, where each area has its own link-state database and all routers within an area have identical information about that area. Dijkstra algorithmis used  to calculate the shortest path between two points in a network, based on the link-state information available.

Key Points of  OSPF

  • It uses different metrics to determine the best path for traffic, including cost, bandwidth, delay, reliability, and load.
  • It uses the concept of administrative distance to determine which routing protocol to use when multiple protocols are configured on a router.
  • OSPF elects a designated router (DR) and backup designated router (BDR) in each multi-access network to reduce the amount of traffic generated by neighbor discovery.
  • OSPF supports authentication to ensure that only authorized routers can participate in the OSPF network. It also supports various features such as route summarization, virtual links, and route redistribution.
  • OSPF supports IPv4 and IPv6 networks.
  • It allows for the configuration of different types of network connections, including point-to-point, broadcast, and non-broadcast.
  • OSPF messages include Hello packets, Link State Advertisement (LSA) packets, and Database Description (DBD) packets.
  • OSPF has several types of areas, including standard areas, stub areas, totally stubby areas, and not-so-stubby areas (NSSAs).
  • OSPF is widely used in enterprise networks and service provider networks due to its scalability, fast convergence, and support for hierarchical network design.
  • OSPF has different types of LSAs, including router LSAs, network LSAs, summary LSAs, and AS external LSAs.

Link State Advertisement in OSPF

In OSPF, LSAs (Link State Advertisement)  are messages sent by routers to advertise information about their local networks and the state of their links to neighboring routers. Each router in an OSPF network maintains a Link State Database (LSDB) that contains a copy of all the LSAs in the network. The LSDB is used to calculate the shortest path to each destination network in the network.There are several types of LSAs used in OSPF, including:

  • Router LSA: Generated by each router to advertise information about its directly connected links.
  •  Network LSA: Generated by the designated router (DR) on a multi-access network to advertise information about the network.
  • Summary LSA: Generated by Area Border Routers (ABRs) to advertise summary information about networks in other areas.
  • AS External LSA: Generated by Autonomous System Boundary Routers (ASBRs) to advertise information about networks outside the OSPF domain.
  • Type 4 LSA: Generated by the ASBR in the backbone area to advertise the existence of an ASBR in other areas.
  • Type 5 LSA: Generated by the ASBR to advertise external routes from the AS into the OSPF domain.
  • Type 7 LSA: Used in Not-So-Stubby-Areas (NSSAs) to advertise external routes from the NSSA into the OSPF domain.

In nutshell, LSAs are flooded throughout the OSPF domain to ensure that all routers have the same information about the network topology. Routers use the information in LSAs to calculate the shortest path to each destination network in the network.

OSPF Areas

OSPF divides networks into areas to reduce the amount of routing information that must be exchanged between routers. There are several types of OSPF areas:

  • Backbone area (Area 0): This is the central area of an OSPF network and is required for all OSPF networks. It connects all other OSPF areas.
  • Standard area: A standard area is any OSPF area that is not the backbone area (Area 0).
  • Totally Stub area: In a totally stub area, all external routes, including those that would normally be advertised in the OSPF domain, are replaced by a single default route. This reduces the amount of routing information in the area and makes it easier to manage.
  • Not-so-Stubby-Area (NSSA): An NSSA is a type of area in which external routes are allowed, but are translated into internal routes within the NSSA. This allows the area to be connected to an external network while maintaining the benefits of OSPF.
  • Totally NSSA: In a totally NSSA, external routes are translated into internal routes within the NSSA, and a default route is injected into the area. This further reduces the amount of routing information in the area and simplifies management.
  • Transit area: A transit area is an OSPF area through which traffic must pass in order to reach another OSPF area. It typically connects multiple standard areas to the backbone area.

Each OSPF area has its own topology database, which contains information about the routers and networks within that area. This allows OSPF to maintain separate routing tables for each area and reduce the amount of routing information that must be exchanged between routers.

How OSPF Works

OSPF (Open Shortest Path First) is a link-state routing protocol that works by building a complete topology of the network. OSPF routers exchange information about their directly connected links and build a map of the entire network. This map is then used to calculate the shortest path to a destination, making OSPF an efficient routing protocol.

  1. OSPF routers discover their neighbors: OSPF routers use hello messages to discover their neighbors and establish adjacency. Routers exchange hello messages to determine if they are on the same network segment and agree on the OSPF parameters.
  2. OSPF routers exchange link-state information: OSPF routers exchange link-state advertisements (LSAs) that describe the state of their directly connected links. These LSAs are flooded throughout the network to build a complete topology map of the network.
  3. OSPF routers calculate the shortest path to a destination: OSPF routers use the received LSAs to build a shortest path tree of the network, using the Dijkstra algorithm to calculate the shortest path to each destination.
  4. OSPF routers select the best path to a destination: OSPF routers select the best path to a destination based on the path’s total cost, which is calculated as the sum of the link costs along the path. The router then forwards the packet to the next hop router along the chosen path.

In summary, OSPF works by building a complete topology map of the network, calculating the shortest path to a destination using the Dijkstra algorithm, and selecting the best path based on the path’s total cost. OSPF routers maintain the network topology by continually monitoring the network and updating their LSAs, and converge quickly when there is a change in the network.

Configure the OSPF and Verify Two Routers Connection in Cisco Packet Tracer

Here we will take an example by using the CISCO packet tracer to configure ospf in the  network which contains two routers two switchs and two pcs as shown in below figure 1. now open the cisco packet tracer and select the following devices as shown below:

S.no

Device

Qty

1

PC 2

2

Switch 2

3

Router 2
  • Use the automatic connecting wire to connect the devices with each other and the topology as shown in figure 1.

Figure 1: OSPF Configuration

Now we have to assign the ip address as shown below table to each pc and router this is done by the following steps:

S.NO 

Device 

Interface

IPv4 Address

 Subnet-Mask

Default-Gateway

01 PC1   192.168.1.2 255.255.255.0 192.168.1.3
02 PC2   192.168.2.2 255.255.255.0 192.168.2.3
03 Router 0 GigabitEthernet0/0 192.168.1.3 255.255.255.0  
GigabitEthernet0/1 192.168.3.2 255.255.255
04 Router 1 GigabitEthernet0/0 192.168.2.3 255.255.255.0  
GigabitEthernet0/1 192.168.3.3 255.255.255.0

Step1: select pc1 then go to Desktop then select ip configration and assign the ip address to pc1 as shown below:

Figure 2: pc1 configuration

Step2: select PC2 then go to Desktop then select ip configration and assing the ip address to pc1 as shown below:

figure 3: PC2 configration

Step 3:Here  we have two methods to assing ip address to router0:

  1. Graphical method: select the router0 R0 go to config then select GigabitEthernet0/0 then assign ip address 192.168.1.3  similarly go to GigabitEthernet0/1 to assign the ip address  192.168.1.3 as shown in figure below:

Figure 4: Router 0 configuration

 Command line: in this method select the router R0 then go to CLI and enter the following commands as shown below to set the ip address of GigabitEthernet0/0 and GigabitEthernet0/1:
 

             GigabitEthernet0/0
              Router>enable
              Router#configure terminal
              Router(config)#interface GigabitEthernet0/0
              Router(config-if)#ip address 192.168.1.3 255.255.255.0

              GigabitEthernet0/1
              Router(config)#interface GigabitEthernet0/0
              Router(config-if)#ip address 192.168.1.3 255.255.255.0
 

Step4: select the router R1 and similarly as shown in step2 assign the ip address as shown in tabble II to GigabitEthernet0/1 and GigabitEthernet0/0 

After these steps will done now we have to follow these steps to configure ospf in two routers R0 and R1 :
 

Step 1:Select the router R0 then go to CLI and enter the below commands:
 

Router> enable
Router# config t
Router(config)#router ospf 1
Router(config-router)#network 192.168.1.0 0.0.0.255 area 0
Router(config-router)#network 192.168.3.0 0.0.0.255 area 0

Step 2:Select the router R1 then go to CLI and enter the below commands:

Router> enable
Router# config t
Router(config)#router ospf 2
Router(config-router)#network 192.168.2.0 0.0.0.255 area 0
Router(config-router)#network 192.168.3.0 0.0.0.255 area 0

After configuring the ospf now we will verify ospf is working or not to  this we will ping from pc1 to pc2. To do this select pc1 and go to command prompt and enter the following command:

Ping 192.168.2.3

as shown in figure 5 the packets are received successfully and now ospf is working successfully.

Figure 5: Ping from pc1 to pc2

Now we will ping from pc2 to pc1 by entering the following command:

Ping 192.168.1.3

as shown in figure 6 the packets are successfully received which means OSPF is working successfully 

Figure 5: Ping from pc2 to pc1

What is OSPF Interface Cost?

OSPF (Open Shortest Path First) interface cost is a metric used by the OSPF routing protocol to determine the best path to a destination. It represents the cost of sending data across a specific link, and it is calculated based on the bandwidth of the link. The formula for calculating the cost of interface in Cisco router is, as follows.

        interface Cost = Reference Bandwidth(Mbps) / Interface Bandwidth(Mbps)

By default the value of reference bandwidth is 100Mbps. OSPF interface cost plays a crucial role in determining the path selection process in OSPF. When OSPF receives multiple paths to a destination, it chooses the path with the lowest cumulative interface cost. This means that the path with the lowest total cost (sum of interface costs) is selected as the best path to the destination.

Network administrators can manipulate the path selection process by adjusting the cost of specific interfaces. For example, increasing the cost of an interface will make OSPF less likely to use that path, and decreasing the cost will make OSPF more likely to use that path.

In summary, OSPF interface cost is a critical metric used by OSPF to determine the best path to a destination, and it allows network administrators to optimize network performance by manipulating the path selection process.

Example To Calculate Path Cost

To calculate the route cost from router R0  to router R1 as shown in figure 7 below: 

Figure 7: path cost from R0 to R1

as you seen above figure 7 the cost of route R1 to R2 which consists GigabitEthernet0/1 and GigabitEthernet0/0 whose cost is 10 and 16 respectively. To calculate the cost  the above formula is used:

Cost = 10^8bps/BW bps

Cost = 100000 kbps/BW kbps

cost R1 to R2 = 100000 kbps/10000 kbps +100000 kbps/6000kbps

                     = 10+16=26

To see the cost of the interface in the cisco packet tracer following commands will be followed:

Router>enable

Router#sh ip route

As shown in figure 8 below the highlighted part is the cost of the route:

figure 8: cost of the route

Similarly we can see the cost of the another by following the same procedure.

How To Change the Interface Cost?

Changing the OSPF cost can control the determination of the optimal route. There are three methods for modifying the OSPF cost.

  • Directly Configuring OSPF Costs
  • Modifying Interface Bandwidth (BW)
  • Altering the numerator in the formula used to calculate costs (reference-bandwidth)

Directly Configuring OSPF Costs

To configure the OSPF cost directly, by using the following command in interface configuration mode.

Router>en
Router#config t

Router(config-if)#ip ospf cost 20

as shown in figure 9 highlighted part show the new cost of the interface:

figure 9: Directly Configuring OSPF Costs

 Modifying Interface Bandwidth

To modify the interface bandwidth, use the following command in interface configuration mode.

Router>en
Router#config t
Router(config-if)#bandwidth 2000
Router(config-if)#exit

Altering the numerator in the formula used to calculate costs (reference-bandwidth)

To modify the numerator of the cost formula, use the following command in OSPF configuration mode.

(config)#router ospf < process-id >
(config-router)#auto-cost reference-bandwidth < bandwidth >

< process-id > : OSPF process id
< bandwidth > : numerator of the cost formula

The following is the conclusion of the OSPF cost:

 



Last Updated : 07 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads