OSPF Cost


What is Cost?
OSPF metric is known as cost and OSPF Cost is the overhead required to send packets across a certain interface. IN OSPF different interface have different cost related to bandwidth, a interface have high bandwidth have lower cost and OSPF consider the best path/link among the different link by lower cost.
OSPF use the following formula for calculating cost for a link.

OSPF Cost=100 / (bandwidth in MB)

OSPF Cost for different interfaces(Cisco):
Link/interface
OSPF cost
56k
1785
64k
1562
T1
65
E1
48
FE/GE/10 GE
1



Cost Management/Configuration:
By default, the cost of an interface is calculated based on the bandwidth and also FE=G=GE=E=10G have cost of ‘1’. Since all E/FE/GE interfaces have equal cost therefore in some networks design there you are using all E/FE/GE interfaces router can give the preference to E interface over GE to avoid such situation it is recommended that you set the cost of different interface manually. For this you can force the cost of an interface with the ip ospf cost <value>interface sub configuration mode command.

Router(config-if)#ip ospf cost <1 to 22>
Also following are some method for cost management in OSPF.
Metric Tuning

Engineers have a couple of commands available that allow them to tune the values of the OSPF interface cost, thereby influencing the choice of best OSPF route. There are three methods:
         i.            Changing the reference bandwidth
       ii.            Setting the interface bandwidth
      iii.            Setting the OSPF cost directly.

Changing the Reference Bandwidth:
Using reference bandwidth command you can change the default cost of any interface\link and you can accommodate good default for higher-speed link. Auto-cost reference bandwidth 100 is the default where 100 MB link= 1 (cost).
I fyou have GE interface in your network you can change your reference bandwidth by "auto-cost reference bandwidth 1000", in this case cost of gig interface is selected as 1.
Setting Bandwidth
You can change the OSPF cost by configuring the bandwidth of an interface. In such cases, the cost formula (Cost=100 / (bandwidth in MB) is used, just with the configured bandwidth value.
On Ethernet interfaces, if not configured with the bandwidth command, the interface bandwidth matches the actual speed. For example, on an interface that supports auto negotiation
for 10/100, the bandwidth is either 100,000 (kbps, or 100 Mbps) or 10,000 (Kbps, or 10 Mbps) depending on whether the link currently runs at 100 or 10 Mbps, respectively.
Configuring Cost Directly
The handiest method to configure OSPF costs is to set the cost manually by command:
Router#ip ospf cost <number>
When you configuration the manual cost of each interface then OSPF ignore every this use the manually configured cost.
Ip ospf cost set the cost by you according to interface speed. For example if there are FE, GE and 10 GE interface you can set 20 for FE,10 for GE and 1 for 10 GE. In this way you can easy manage cost of OSPF link and take full advantage of you GE interfaces.
Verifying OSPF Cost Settings
You can verify OSPF cost settings of various interfaces by following commands.
Router#show run
Router#show ip ospf interface brief
Router#show ip ospf interface fa 0/0

OSPF Tables

OSPF Tables:

In link state routing protocol there are different tables for storing different types of information regarding router and its networks. There are three tables in OSPF same like in EIGRP.
1.       OSPF Neighbor table
2.       OSPF Topology table
3.       OSPF Routing table


OSPF Neighbor table
Neighbor table contains the information of all connected OSPF routers.  In OSPF neighbor table OSPF have the information of neighbor status, IP address, timers, interfaces DR\BDR status, router-ID of connected OSPF router etc.
You can check the OSPF neighbor on a CISCO router by following command:

router#show ip ospf 1 neighbor

Router#show ip ospf 1 neighbor detail

Note: Where ‘1’ is OSPF process ID.

OSPF Topology table
In OSPF process each router have full road map of its entire area and this the one of difference between link state routing protocols and distance vector routing protocols that in Link state every router have complete understanding of their entire area. All such information in OSPF is stored in OSPF topology table. The difference between OSPF and EIGRP topology table is that EIGRP only know about it connected neighbor where as OSPF has full road map of entire area.
You can view the topology structure on a Cisco router by following command:

router#show ip OSPf 1 database

OSPF Routing table
Routing table has best routes for reaching different networks. OSPF use the SPF for calculation of best path in OSPF process.  You can check the routing on a CISCO router by following commands:

Router#show ip route
Router#show ip route ospf
Router#show ip route ospf 1

For More OSPF details you can visit OSPF design and concepts, link state routing protocols , distance vector routing protocols, OSPF virtual linksOSPF LSA Types.

OSPF LSA Types


OSPF LSA Types
LSAs are building block of OSPF, OSPF use the LSA (link state advertisement) for building the topology table and database. There are total 11 types of LSA but famous types are as follow.
1.       LSA Type-1| Router LSA from one network
2.       LSA Type-2| Network LSA from more network (DR Generated)
3.       LSA Type-3| Summary LSA (ABR summary Route)
4.       LSA Type-4| Summary LSA (just IP address of ASBR)
5.       LSA Type-5| External LSA (ASBR summary Route)
6.       LSA type-6 (not supported by Cisco)
7.       LSA type-7

LSA Type-1| Router LSA
LSA type 1 defining router properties like RID and all interface IP addresses on that router that are in same area. Each router creates its own Type 1 LSA to represent itself for each area to which it connects.
LSA Type-2| Network LSA
LSA type 2 are also known as network LSA and it is advertises for all the router connect in same Ethernet segment or switch. Type 2 LSA is created by the DR on the network, and represents the subnet and the router interfaces connected to that network.
LSA Type-3| Summary LSA
LSA type-3 is summary LSA and contains all the summary routes for an area. It is created by ABRs to represent subnets listed in one area’s type 1 and 2 LSAs when being advertised into another area. Type-3 LSAs are always created whether you are summarizing or not.
 LSA Type-4| Summary LSA
LSA type-4 is also summary LSA and it is location of ASBR or you can say IP address of ASBR. The reason of creating type-4 LSA is that in OSPF process whenever some internal ASB want to advertise routes to ASBR, use the LSA-4 or IP address of ASBR. 
LSA Type-5| External LSA
LSA type-5 is generated by ASBR for injecting the external routes to backbone area. ASBR send the LSA type-5 to backbone router which contain the external routes updates e.g. RIP, EIGRP updates.




LSA Type-6
Type-6 LSAs are not supported by Cisco IOS.
LSA Type-7
A not-so-stubby area (NSSA) is a type of stub area that can import autonomous system external routes and send them to other areas. Since Type 5 LSAs are not allowed in NSSA areas, so the ASBR in NSSA generates a type 7 LSA instead, this type-7 LSA passes to backbone area and then converted back to types-5 LSA.
LSA Type-8
Not supported by Cisco routers.

LSA Type-9 | LSA Type-10 | LSA Type-11
These LSA are for future use, recently type-10 LSA is using in MPLS.

OSPF Virtual Links

OSPF Virtual Links
In OSPF there is a basic requirement while designing a network with multiple areas that every area is directly connected to backbone area 0. Virtual link comes when some area e.g. area-2 in figure is not directly connected to area 0. There is area-1 in between area-2 and backbone area-0, so in this case communication between area-0 and area-2 is not possible. To make communication between these areas you need to create virtual-links.




How to create OSPF Virtual-links:
For creating virtual- links you need to connect the area which is not directly connect to area-0 to area which is directly connected to area-0. In figure you can see that Area-2 is not directly connect to area-0 to connect this area-2 to area-0 you need to create a virtual link between area-1 & area-2 by using commands as
R2(config)#router ospf 1
R2(config-rtr)#area 1 virtual-link 3.3.3.3

R3(config)#router ospf 1
R3(config-rtr)#area 1 virtual-link 2.2.2.2

Where 2.2.2.2 and 3.3.3.3 are router IDs.

OSPF Virtual link configuration Example
Follow this link for OSPF virtual link configuration example on Cisco router.

UA-23728446-1