Table of Contents
The “path cost” is used as the metric for OSPF’s optimal route selection criteria. The costs on the path to the destination network are accumulated and the path with the lowest cost is adopted in the routing table as the optimal route. Think of it as measuring the distance to the destination network by path cost.
Determining the cost is automatically calculated from bandwidth by default in Cisco router implementations; routers from non-Cisco vendors are also often calculated automatically from bandwidth. The formula for calculating the cost in Cisco router implementations is, by default, as follows.
100(Mbps) / Interface Bandwidth(Mbps)
For example, 10 Mbps Ethernet has a cost of 10 and 1.544 Mbps leased line has a cost of 64. Since the value of the cost is lower for larger bandwidths, the selection of the best route by OSPF will by default give preference to routes with larger bandwidths.
However, because it does not take into account a decimal point, the cost of this formula is 1 for all bandwidths above 100 Mbps, which may not properly reflect the bandwidth of the network if there are links above 100 Mbps. Therefore, the administrator can manually set the cost value by command instead of depending on the interface’s bandwidth.
You can also change the parameters in the cost formula itself to accommodate a faster interface. However, when you change the OSPF cost formula, you should change it on all OSPF routers. If you have a mixture of routers that have changed the formula and those that have not, the cost calculation results will be different for interfaces with the same bandwidth, and you will not be able to correctly determine the optimal route.
The following table summarizes the default cost values for each typical interface in a Cisco router.
Example of path cost
To calculate the cumulative cost, OSPF routers run the SPF algorithm. For simplicity, assuming an OSPF route flows in, as in RIP, the cost of the interface receiving the route will be cumulative. A simple example of cumulative cost is shown in the following figure: from R1, the path cost up to 192.168.1.0/24 will be the cumulative cost values in the beige area of the figure.
If there is more than one minimum cost route, then these routes can be used to achieve an equal cost load balance.
Changing OSPF Costs
You can control the determination of the optimal route by changing the OSPF cost. there are three ways to change the OSPF cost.
- Configuring OSPF Costs Directly
- Changing the Interface Bandwidth (BW)
- Changing the numerator of the cost formula (reference-bandwidth)
To configure the OSPF cost directly, use the following command in interface configuration mode.
(config-if)#ip ospf cost <cost>
<cost> : OSPF cost
To change the interface bandwidth, use the following command in interface configuration mode.
<BW> : Bandwidth(kbps)
To change 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 figure summarizes the OSPF cost changes.
Changes to the cost should be made so that the cost values are consistent across the network as a whole, not just for a single router. It is especially important that the configuration for changing the numerator of the formula be the same on all OSPF routers.
Verification of OSPF costs
To verify the cost of the OSPF, you can mainly use the following commands
- show ip ospf interface
- show interface
- show ip protocols
show ip ospf interface
The show ip ospf interface command is the easiest way to verify OSPF costs. In particular, if you add a brief, you can quickly see the cost value for each OSPF-enabled interface.
R1#show ip ospf interface brief Interface PID Area IP Address/Mask Cost State Nbrs F/C Se2/0 1 0 Unnumbered Fa0/0 64 P2P 1/1 Fa0/0 1 0 192.168.12.1/24 1 BDR 0/1 R1#show ip ospf interface FastEthernet 0/0 FastEthernet0/0 is up, line protocol is up Internet Address 192.168.12.1/24, Area 0 Process ID 1, Router ID 18.104.22.168, Network Type BROADCAST, Cost: 1 Transmit Delay is 1 sec, State DR, Priority 1 Designated Router (ID) 22.214.171.124, Interface address 192.168.12.1 No backup designated router on this network Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5 oob-resync timeout 40 Hello due in 00:00:01 Supports Link-local Signaling (LLS) Index 1/1, flood queue length 0 Next 0x0(0)/0x0(0) Last flood scan length is 0, maximum is 0 Last flood scan time is 0 msec, maximum is 0 msec Neighbor Count is 1, Adjacent neighbor count is 0 Suppress hello for 0 neighbor(s)
The show interface command verifies the BW used for OSPF costing.
R1#show interface FastEthernet 0/0 FastEthernet0/0 is up, line protocol is up Hardware is AmdFE, address is cc01.29a8.0000 (bia cc01.29a8.0000) Internet address is 192.168.12.1/24 MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec, reliability 255/255, txload 1/255, rxload 1/255 Encapsulation ARPA, loopback not set Keepalive set (10 sec) Full-duplex, 100Mb/s, 100BaseTX/FX ARP type: ARPA, ARP Timeout 04:00:00 Last input 00:00:01, output 00:00:00, output hang never Last clearing of "show interface" counters never Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0 Queueing strategy: fifo Output queue: 0/40 (size/max) ～省略～
show ip protocols
You can use the show ip protocols command to see the reference-bandwidth, which is the value of the numerator of the OSPF cost formula.
R1#show ip protocols Routing Protocol is "ospf 1" Outgoing update filter list for all interfaces is not set Incoming update filter list for all interfaces is not set Router ID 126.96.36.199 Number of areas in this router is 1. 1 normal 0 stub 0 nssa Maximum path: 4 Routing for Networks: 192.168.12.0 0.0.0.255 area 0 Reference bandwidth unit is 100 mbps Routing Information Sources: Gateway Distance Last Update 188.8.131.52 110 00:00:00 Distance: (default is 110)
- OSPF Overview
- OSPF process flow
- OSPF Router ID : Identify OSPF routers
- What if the router ID of the OSPF router is duplicated?
- OSPF Neighbor and Adjacency
- OSPF DR/BDR
- How show ip ospf neighbor looks on Ethernet
- OSPF Network Type : Classification of OSPF-enabled interfaces
- Synchronization process of OSPF LSDB
- Problems with large-scale OSPF network
- OSPF Area – Inside the area, in detail; outside the area, just a summary
- OSPF Router Type
- OSPF LSA Type
- OSPF Area Type
- OSPF Basic Configuration and Verification Commands
- Details of enabling OSPF on the interface
- OSPF Advertising Loopback Interface
- Configuring and Verifying OSPF Hello/Dead interval
- OSPF Cost Configuration and Verification
- Configuring and Verifying OSPF Router Priority
- Configuring OSPF Neighbor Authentication
- Neighbor Authentication over Virtual-link
- OSPF Configuring and Verifying Stub area [Cisco]
- OSPF Stub Area Configuration Example [Cisco]
- OSPF default route generation : default-information originate command
- Configuration Example of OSPF default route generation : stub area
- OSPF Virtual-Link : Virtual area 0 point-to-point link
- Configuring and Verifying OSPF Virtual-link [Cisco]
- OSPF Virtual-link Configuration Example [Cisco]
- OSPF Virtual-link for discontinuous backbone configuration example
- OSPF Route Summary and Configuration
- Cisco OSPF Route Summary Configuration Example
- OSPF Route Type Preference
- Why the OSPF neighbor state gets stuck in Exstart?
- OSPF packet type and header format
- OSPF Hello Packet
- OSPF DD(Database Description) Packet
- OSPF LSR(Link State Request) Packet
- OSPF LSU(Link State Update) Packet
- OSPF LSAck(Link State Acknowledgement) Packet
- Limitation of OSPF redistribution routes – redistribute maximum-prefix command
- Overview of LSA Filters for OSPF – Filter LSA Type 3/Type 5
- Configuration example of LSA type 3 filter
- Configuration example of LSA type 5 filter
- OSPFv3 Configuration Example [Cisco]
- Configuration Example of OSPFv3 Route Summary [Cisco]