OSPF cost

The formula used to calculate the OSPF cost is:

  • Cost = reference bandwidth / interface bandwidth

The default reference bandwidth is 10^8 (100,000,000); therefore, the formula is:

  • Cost = 100,000,000 bps / interface bandwidth in bps

Notice that FastEthernet, Gigabit Ethernet, and 10 GigE interfaces share the same cost,which is 1,  because the OSPF cost value must be an integer. So, we need to adjust the reference bandwidth to assist OSPF in making the correct path determination.

1. Change the reference bandwidth:

This is the way we change the numerator.

r1(config-router)# auto-cost reference-bandwidth

The bandwidth is in Mb/s, the default value is 100. So, in order to differentiate the Gigabit Ethernet and 10 Gigabit Ethernet, we need to set the value to 1000.reference-bandwidth

2. Adjusting the Interface Bandwidth

In this way, we change the denominator in the equation.

R1(config-if)#bandwidth number_in_kilobits

Cancel it: R1(config-if)#no bandwidth

Note that The command only modifies the bandwidth metric used by EIGRP and OSPF. The command does not modify the actual bandwidth on the link.

3. Setting the OSPF cost:

This is a straight forward way, and useful in multi-vendor environments where non-Cisco routers may use a metric other than bandwidth to calculate the OSPF costs.

R1(config-if)#ip ospf cost value

 Verify the interface Configuration

  • To verify the interfaces status: show interfaces interface_name
  • To verify the bandwidth only: show interfaces interface_name | include BW

Hello and dead intervals

 

OSPF Hello and Dead intervals can be modified manually using the following interface configuration mode commands:

  • ip ospf hello-interval seconds
  • ip ospf dead-interval seconds

DR BDR

Instead of relying on the router ID, it is better to control the election by setting interface priorities. Priorities are an interface-specific value, which means it provides better control on a multiaccess network. This also allows a router to be the DR in one network and a DROTHER in another.

To set the priority of an interface, use the following commands:

  • ip ospf priority value – OSPFv2 interface command
  • ipv6 ospf priority value – OSPFv3 interface command

The value can be:

  • 0 – Does not become a DR or BDR.
  • 1255 – The higher the priority value, the more likely the router becomes the DR or BDR on the interface.
Security

To enable OSPF MD5 authentication globally, configure:

  • ip ospf message-digest-key key md5 password interface configuration mode command.
  • area area-id authentication message-digest router configuration mode command.

This method forces authentication on all OSPF enabled interfaces.

Authentication on a per-interface basis. To enable MD5 authentication on a per-interface basis, configure:

  • ip ospf message-digest-key key md5 password interface configuration mode command.
  • ip ospf authentication message-digest interface configuration mode command.

Global and per-interface OSPF MD5 authentication can be used on the same router. However, the interface setting overrides the global setting.

Verify OSPF

1. Show ip ospf neighbor

  • Neighbor ID – The router ID of the neighboring router.
  • Pri – The OSPF priority of the interface. This value is used in the DR and BDR election.
  • State – The OSPF state of the interface. FULL state means that the router and its neighbor have identical OSPF LSDBs. On multiaccess networks, such as Ethernet, two routers that are adjacent may have their states displayed as 2WAY. The dash indicates that no DR or BDR is required because of the network type.
  • Dead Time – The amount of time remaining that the router waits to receive an OSPF Hello packet from the neighbor before declaring the neighbor down. This value is reset when the interface receives a Hello packet.
  • Address – The IPv4 address of the neighbor’s interface to which this router is directly connected.
  • Interface – The interface on which this router has formed adjacency with the neighbor.

Two routers may not form an OSPF adjacency if:

  • The subnet masks do not match, causing the routers to be on separate networks.
  • OSPF Hello or Dead Timers do not match.
  • OSPF Network Types do not match.
  • There is a missing or incorrect OSPF network command.

2. Show ip protocols:  quick way to verify vital OSPF configuration information

3. Show ip ospf: examine the OSPF process ID and router ID.

4. show ip route

O*E2,

  • o signifying that it was learned using OSPF.
  • The asterisk(*) identifies this as a good candidate for the default route.
  • The E2 designation identifies that it is an external route.

5. Show ip ospf interface: This command provides a detailed list for every OSPF-enabled interface. The command is useful to determine whether the network statements were correctly composed, also can be used to if the router is DR or BDR.

    can use Show ip ospf interface brief     or show ip ospf interface interface_name

Example

R2>show ip ospf interface

FastEthernet0/0 is up, line protocol is up

Internet address is 10.10.10.2/29, Area 0

Process ID 1, Router ID 172.16.52.130, Network Type BROADCAST, Cost: 1

Transmit Delay is 1 sec, State DR, Priority 255

Designated Router (ID) 172.16.52.130, Interface address 10.10.10.2

Backup Designated Router (ID) 255.255.255.255, Interface address 10.10.10.4

Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5

Hello due in 00:00:00

Index 1/1, flood queue length 0

Next 0x0(0)/0x0(0)

Last flood scan length is 1, maximum is 1

Last flood scan time is 0 msec, maximum is 0 msec

Neighbor Count is 3, Adjacent neighbor count is 3

Adjacent with neighbor 172.16.50.1

Adjacent with neighbor 1.1.1.1

Adjacent with neighbor 255.255.255.255 (Backup Designated Router)

Suppress hello for 0 neighbor(s)

FastEthernet0/1 is up, line protocol is up

Internet address is 172.16.40.1/22, Area 0

Process ID 1, Router ID 172.16.52.130, Network Type BROADCAST, Cost: 1

Transmit Delay is 1 sec, State DR, Priority 1

Designated Router (ID) 172.16.52.130, Interface address 172.16.40.1

No backup designated router on this network

Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5

Hello due in 00:00:01

Index 2/2, flood queue length 0

Next 0x0(0)/0x0(0)

Last flood scan length is 1, maximum is 1

Last flood scan time is 0 msec, maximum is 0 msec

Neighbor Count is 0, Adjacent neighbor count is 0

Suppress hello for 0 neighbor(s)

Serial0/0/0 is up, line protocol is up

Internet address is 172.16.52.130/30, Area 0

Process ID 1, Router ID 172.16.52.130, Network Type POINT-TO-POINT, Cost: 64

Transmit Delay is 1 sec, State POINT-TO-POINT, Priority 0

No designated router on this network

No backup designated router on this network

Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5

Hello due in 00:00:00

Index 3/3, flood queue length 0

Next 0x0(0)/0x0(0)

Last flood scan length is 1, maximum is 1

Last flood scan time is 0 msec, maximum is 0 msec

Neighbor Count is 1 , Adjacent neighbor count is 1

Adjacent with neighbor 10.0.0.0

Suppress hello for 0 neighbor(s)

6. Debug ip ospf packet

Router# debug ip ospf packet
OSPF: rcv. v:2 t:1 l:48 rid:200.0.0.116
      aid:0.0.0.0 chk:0 aut:2 keyid:1 seq:0x0

The table below describes the significant fields shown in the display.

 
Field Description
v: OSPF version.
t: OSPF packet type. Possible packet types follow:

  • 1–Hello
  • 2–Data description
  • 3–Link state request
  • 4–Link state update
  • 5–Link state acknowledgment
l: OSPF packet length in bytes.
rid: OSPF router ID.
aid: OSPF area ID.
chk: OSPF checksum.
aut: OSPF authentication type. Possible authentication types follow:

  • 0–No authentication
  • 1–Simple password
  • 2–MD5
keyid: MD5 key ID.
seq: Sequence number.