If multiple routes to a destination are known, routes learned through
the protocol with the better administrative distance are preferred.If more than one route to a destination is learned through the
preferred protocol, then the preference of routes is based on the metric
of the routes.Routes with the better metric are preferred.
Open Shortest Path First (OSPF) uses cost as the metric calculated, based on the bandwidth of the link.
The
auto-cost reference-bandwidth command allows you to change the reference
bandwidth that OSPF uses to calculate its metrics:
Router5#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router5(config)#router ospf 87
Router5(config-router)#auto-cost reference-bandwidth 1000
Router5(config-router)#end
Router5#
You can also adjust the OSPF cost of a single interface with
the
ip ospf cost configuration
command:
Router5#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router5(config)#interface Ethernet0
Router5(config-if)#ip ospf cost 31
Router5(config-if)#end
Router5#
The custom in OSPF networks is to make the link cost inversely proportional to the bandwidth of a link. This isn't required, but it is common,
and it is the default behavior for Cisco routers. The reference bandwidth defines the link speed that has an OSPF cost of 1. By default, the reference
bandwidth is 100Mbps.
However, if you have faster links in your network (such as
gigabit Ethernet or even OC-3 connections), OSPF can't give these links a better
cost than 1. So you should set the reference bandwidth to at least as high as
the fastest link in your network. In fact, you may want to set this value higher
than the bandwidth of your fastest link to ensure that you don't have to
reconfigure your whole network when you eventually upgrade some of your core
links.
It is important to set the same reference bandwidth on all
routers in an area, and preferably throughout the entire network. Recall that
OSPF allows every router to calculate its own routing table based on the LSAs
that they receive. So, they must all agree on the relationship between costs and
bandwidth. Suppose you set the reference bandwidth differently on two routers,
causing them to advertise different link costs for their Ethernet interfaces.
This could cause seriously strange routing patterns as OSPF will try to avoid
using the higher-cost links. It may decide, for example, that a FastEthernet
interface on one router is faster than a Gigabit Ethernet interface on the other
router.
But there is another interesting problem with the way OSPF
calculates its metrics. Suppose your network includes one or more Gigabit
Ethernet links in the core and a WAN that provides 9.6Kbps dial backup for the
most remote branches. This means that the fastest link is over 100,000 times as
fast as the slowest. When this happens, the router will simply apply the maximum
link cost of 65,535.
The problem is that the OSPF metric is only 16 bits long,
giving it a maximum per-link cost value of 65,535. So, if your fastest link used
the emerging 10Gbps Ethernet standard, and you set the cost of this link to 1,
then a relatively common 56Kbps serial link would need to have a cost of
178,571. Since this is not possible, OSPF would have to use the maximum link
cost of 65,535. This in itself is not a problem. The problem is that your
128Kbps circuits would also need to have the same cost. This could cause some
very poor routing patterns.
We suggest using an alternate costing strategy to avoid this
problem. The idea is that the cost of a link doesn't actually have to be 10
times as high just because the link is 1/10 as fast. In fact, this default
behavior implies that it is better to go through a succession of 10 FastEthernet
links rather than use a single Ethernet, which is probably not true in most
cases. So a useful alternative strategy is to use the square root of the
bandwidth instead of the bandwidth when calculating the link cost. The result of this strategy would be -
if you use the default costs, then the three fastest links all wind up with a
cost of 1. Changing the reference bandwidth to 10Gbps, however, produces
impossibly large metrics for the three slowest links (the router will assign
them all a link cost of 65,535). So, no matter what reference bandwidth you use,
if you retain the default 1/bandwidth cost mode, you will need to manually
adjust either the fastest or slowest several link costs.
The second example shows how to change the OSPF cost for a
single interface:
Router5(config)#interface Ethernet0
Router5(config-if)#ip ospf cost 31
If you change the OSPF cost of a link like this, make sure that
all of the other routers that connect to this same network segment use the same
cost, or strange routing will result. Further, it is usually a good practice to
ensure that all of the links of a particular type have the same cost throughout
the network, or at least throughout the area. So, if we set the OSPF cost for
10Mbps Ethernet to 31 on this router, we should do the same on the other routers
as well.
There are times when you will want to make sure that one
particular link is favored, regardless of its actual bandwidth. In this case,
you can give this link a special OSPF cost value. However, you will generally
want to be careful that all of the devices on this link agree on the cost.
You could also achieve a similar effect by just adjusting the
bandwidth statements on each interface, but this will have other
consequences as well. It will affect any other routing protocols that you might
also be running. It also means that an SNMP query of the interface speed will
give an incorrect value, which could confuse network management software. We
recommend the direct approach of manually setting the OSPF cost because it is
more clear what you are doing and why. This becomes most important when somebody
else comes along and wants to change the router configuration.
If your cost scheme is not clear, you could
cause serious support problems for your successor.