OSPF 2 - Cost, Neighbours and Configs

OSPF Cost

OSPF's METRIC is COST !!

  • It is automatically calculated based on the BANDWIDTH (speed) of the interface

  • It is calculated by dividing a reference bandwidth value by the interface's bandwidth

    • The default reference bandwidth is 100Mbps, so lets say an interface is 10Mbps

      • Reference: 100Mbps / Interface:10Mbps: COST= 10

      • Reference: 100Mbps / Interface:100Mbps: COST = 1

      • Reference: 100Mbps / Interface:1000Mbps: COST = 1

      • Reference: 100Mbps / Interface:10000Mbps: COST = 1

  • All values less than 1, will be converted to 1

  • Therefore Fast Ethernet, Gigabit Ethernet, 10/100Gig Ethernet are ALL equal with a value of 1

  • R3# show ip ospf interface fa2/0 Shown in 2 places : Cost 1

  • BUT!!!! we CAN change this with the following command R1(config-router)# auto-cost reference-bandwidth <reference bandwidth in megabits-per-second> R1(config-router)# auto-cost reference-bandwidth 100000

  • You should configure a reference bandwidth GREATER than the fastest links in your network (to allow for future upgrades) across ALL routers in the network

Cost

The OSPF cost to a destination is the TOTAL cost of the 'outgoing/exit' interfaces. Just like spanning tree cost

For example: R1's cost to reach the 192.168.4.0/24 network is:

  • Exit of R1's Gi0/0, exit of R2's G1/0 and the exit of R4's Gi1/0 (taking the reference bandwidth of 100000) is 100+100+100=300

  • Now loopback interfaces have a cost of 1 - what is the cost of reaching R2's loopback interface of 2.2.2.2?

    • R1's exit interface = 100 and R2's loopback interface = 1

    • So to reach R2's loopback interface is 100+1=101

Manually Configure the OSPF Cost of an Interface

R1(config)# interface gi0/0 R1(config-if)# ip ospf cost ? <1 - 65535> Cost R1(config-if)#interface gi0/0 cost 10000

  • This cost is configured directly on the interface and will take priority over the 'auto-calculated cost'

  • We have configured the interface as 10000 and we can now see the cost as 10000 and not as 100 (we are still using the reference bandwidth as 100000)

  • One more option to change the OSPF cost of an interface is to change the 'bandwidth' of the interface. R1(config-if)# bandwidth ? <1 - 10000000> Bandwidth in kilobits Remember - changing the bandwidth does NOT change the SPEED of the interface - the bandwidth command is for COST calculation from the OSPF cost formula: OSPF COST = reference bandwidth \ interface bandwidth

This method is not recommended as the 'bandwidth' VALUE is used in other calculations so don't want to go and change this. Rather use the auto-cost reference bandwidthand THEN use the ip ospf cost to change the individual interfaces if you want.

Lets Summarise

  • There are 3 ways to modify the OSPF cost:

    • Change the reference bandwidthR1(config-router)# auto-cost reference-bandwidth <in megabits per second>

    • Manual Configuration R1(config-if)# ip ospf cost <cost>

    • Change the interface bandwidth R1(config-if)# bandwidth <kilobits per second>

  • To check the cost of the interfaces we can use:

    • R3# show ip ospf interface brief

OSPF Neighbours

Ensuring routers successfully become OSPF neighbours is the main task in configuring and troubleshooting OSPF.

  • Once they become neighbours, they automatically do the work of sharing network information, calculating routes etc. MAKE SURE OSPF IS ACTIVATED ON THE CORRECT INTERFACES and the correct conditions are met to allow the routers to become neighbours, otherwise OSPF wont work !!

  • So how do OSPF routers become neighbours?

    • When OSPF is activated on an INTERFACE, the router starts sending hello messages out of that interface at regular intervals (default every 10 seconds for Ethernet - they are different for other types of media ) - that's why we issue the command R1(config-router)# passive-interface gi2/0 to STOP hello messages being sent to non OSPF aware devices.

  • By exchanging "hello" messages with other OSPF aware routers, they check that they are compatible in becoming OSPF neighbours.

  • These messages are multicast to the OSPF IP address 224.0.0.5 (remember RIP=224.0.0.9, EIGRP=224.0.0.10) and are ENCAPSULATED into an IP header of 89 to indicate "OSPF" (remember TCP=6) [If you look into an OSPF hello packet you will see in the "protocol" field 0x59 - this is hexadecimal and converting this to decimal you will get "89"

OSPF States

For OSPF to become neighbours, they have to go through various states.

Lets assume OSPF has already been activated on R2's Gi0/0 interface, then OSPF is activated on R1's Gi0/0 interface

  • R1 send OSPF hello messages to 224.0.0.5 with R1's router ID (1.1.1.1) and neighbour RID (0.0.0.0) - it doesn't know its neighbour RID ....so this OSPF state is known as the "DOWN STATE"

  • When R2 receives the hello packet, it will add an entry for R1 into its OSPF NEIGHBOUR table and its now in the "INIT STATE"

  • R2 will send a hello packet containing the RID of BOTH routers. R1 will insert R2 into its OSPF NEIGHBOUR table and then R1 will send ANOTHER hello packet, this time containing R2's RID of 2.2.2.2. Now both routers are in the "2-WAY STATE" The 2-way state means that the router has received a hello packet with its OWN router ID in it. Also at this point a Designated Router (DR) and Backup Designated router (BDR) will be elected.

  • Once the routers reach the 2-way state, the conditions have been met for them to become OSPF neighbours and are now ready to share LSA's to build a common LSDB of the network. To do this one of them will have to start the exchange and the one with the highest RID will become the MASTER Router and the other will become the SLAVE Router, This is done via the exchange of Data Base Description (DBD) packets, and this is known as the "EXSTART STATE"

  • These DBD packets contain a list of the LSA's currently in their LSDB and the routers will then determine which LSA's they must receive from their neighbour. This is known as the "EXCHANGE STATE"

  • The routers now know which LSA's they should receive from their neighbours from the DBD packets received earlier. The router now send out LSR's (Link State Request) to their neighbour requesting any LSA's they don't have. These LSA's are sent in LSU's (Links State Updates) and the neighbour router responds with LSAck message to acknowledge they received the LSA's. Now the routers have the same LSDB. This is called the "LOADING STATE"

  • The final state is where the routers have a full adjacency and identical LSDB's. They continue to send hello messages every 10 seconds (by default) to maintain the neighbour adjacency. Every time a hello packet is received on a router the "DEAD TIMER" is reset (every 40 seconds). This should count down to 30 before another hello packet is received and the dead timer is reset to 40 again. This id called the "FULL STATE"

Some Show and Configuration Commands

R1# show ip ospf neighbour R1# show ip ospf interface gi0/0 R1# show ip ospf interface brief

You can configure OSPF directly on an interface without using the "network" command.

R1(config)# interface gi0/0 R1(config-if)# ip ospf 1 area 0 R1(config-if)# interface g1/0 R1(config-if)# ip ospf 1 area 0 ......etc

You can configure ALL interfaces as "passive" and then issue the 'no' command on interfaces that you WANT to send hello packets out from

R1(config-router)# router ospf 1 R1(config-router)# pasive-interface default R1(config-router)# no pasive-interface Gi0/0 R1(config-router)# no passive-interface Gi1/0 ....etc R1# show ip protocol

QUIZ 1

QUIZ 2

QUIZ 3

QUIZ 4

QUIZ 5

ExSim Question:

LAB - Day 27

On R1 ( after step 3) we can see that OSPF shows equal cost to the 192.168.4.0/24 network via R2 and R3 even-though via R2 goes via gigabit links. So step 4 on the lab we need to set a reference bandwidth where Fa interfaces have a cost of 100 and not 1 (as per default)

R3(config-router)#auto-cost reference-bandwidth 10000 ....do to all other routers

Q4

R1(config-router)# auto-cost reference-bandwidth 10000

Q5

R1(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.2 R1(config)# router ospf 1 R1(config-router) # default-information originate

Last updated