Friday, March 23, 2012

OSPF Cost/Metric Calculation

The Open Shortest Path First routing protocol is a critical piece of knowledge for any networking professional working in an enterprise environment. Most major networking certifications covering routing and switching including the Cisco Certified Network Associate (CCNA), Cisco Certified Network Professional (CCNP), and Cisco Certified Internetwork Expert (CCIE) extensively test OSPF knowledge and skills. OSPF is the most popular dynamic routing protocol used in complex enterprise networks as an interior gateway protocol (IGP). This example will demonstrate the concepts and configuration involved with metrics in an OSPF network. I utilize a Cisco c7200 in Dynamips/GNS3 to provide syntax examples in the post below.

Understanding OSPF Cost

Internal Route OSPF Cost

OSPF uses a value called cost for its metric when determining the metric for a particular routing prefix. OSPF defines the cost for a particular prefix according to the following formula:

OSPF cost = cost from LSA + (incoming interface bandwidth/reference bandwidth)

OSPF uses 100 Mb/s for its default reference bandwidth on Cisco routers, but on routers that use Gigabit Ethernet or 10 Gigabit Ethernet, this value should be changed both on the router and everywhere else in the OSPF network. This can be changed using the auto-cost reference-bandwidth  command:

R1(config-router)#auto-cost reference-bandwidth ?
  <1-4294967>  The reference bandwidth in terms of Mbits per second

Note that this is the configured bandwidth on the interface, not the actual bandwidth. The following table shows the OSPF cost for different link types and reference bandwidths:
Link Type 100M (default) Reference Bandwidth 1G Reference Bandwidth 10G Reference Bandwidth
56k serial 1785 17857 178571
64k serial 1562 15625 156250
T1 (1.544 Mbps serial) 64 647 6476
E1 (2.048 Mbps serial) 48 488 4882
Ethernet 10 100 1000
Fast Ethernet 1 10 100
Gigabit Ethernet 1 1 10

The OSPF cost can also be manually set for an interface with the ip ospf cost interface subcommand.

R1(config-if)#ip ospf cost ?
  <1-65535>  Cost

The OSPF cost of an outgoing interface is not added to an outgoing LSA, rather the receiving router adds its own interface cost to the cost that was advertised in the LSA (and propagates that cost to other routers). In this way, the total cost is the cost of each outgoing interface on each router between a particular router and the router connected to a specific prefix.

The OSPF cost can be set for connected networks being advertised into OSPF using the ip ospf cost interface command. It is also possible to set the OSPF cost for a connected route using a route map and redistributing connected networks, though this causes the route to be considered an external route and the metric is determined initially by the set clause of the route map and propagated according to whether it is considered a type 1 external route or a type 2 external route (type 2 is default on the Cisco IOS platform).

It should also be noted that the bandwidth interface configuration command (which has no actual effect on available bandwidth) can modify the OSPF cost for an interface by overriding the bandwidth inferred from the interface type.

Inter-Area and External Route OSPF Cost and Path Selection

Inter-area routes add the cost of the ABR to reach a particular network with the cost to reach an ABR.

External routes redistributed into OSPF are either considered type 2 or type 1 external routes. Type 2 is default and the cost used to determine the shortest path to the advertised network is solely the cost advertised by the ASBR for the prefix (not by the cost to reach any intermediate ABRs or other routers). For type 1 routes, routers add the cost to get to the ASBR to the cost advertised by the ASBR to determine the metric for the route as well as the cost to reach any intermediate ABRs or other routers.

Most of the examples that show routing differences between type 1 and type 2 external routes are theoretical. There aren't very many drivers from a network design standpoint to implement multiple interior gateway routing protocols in a new network or in a network that is being re-engineered or transitioning between routing protocols (ex. RIP -> OSPF or EIGRP -> OSPF). The drivers that do exist mainly involve migrations due to mergers and acquisitions or in high complexity service provider scenarios (mainly interior to a service provider's network or involved with layer 3 carrier MPLS solutions). For VoIP design, EIGRP and OSPF can both be tuned to have subsecond convergence assuming the correct level of redundancy exists in the network and redistribution is not typically required.  

When thinking about OSPF costs, it is important to think about how OSPF chooses routes because the rules may supercede cost in a few different scenarios:
  • OSPF prefers intra-area routes to inter-area routes, regardless of cost
  • OSPF routes across area zero without routing across a non-backbone area if at all possible
  • Finally, OSPF routes to the destination without traversing area 0
This creates challenges with design and troubleshooting because flows may take a non-intuitive path if two non-backbone areas are directly connected with a lower cost than the cost across a backbone area, or if there is a high cost route through the backbone area and a low cost route that traverses the backbone area and a non-backbone area. Special care should be taken with regard to link failures and different external routing scenarios.

See Also
The Road to the CCIE

No comments:

Post a Comment