DEV Community

MinBapE
MinBapE

Posted on

OSPF - Open Shortest Path First

1. OSPF Characteristics

  • A Link State routing protocol
  • Supports large networks, converges very fast
  • Messages are sent by multicast
  • An open standard, so it runs on every vendor's equipment
  • Uses Dijkstra's SPF (Shortest Path First) algorithm to pick the best path
  • Administrative Distance 110

IGP comparison

RIP EIGRP OSPF
Scalability Low, small networks and labs Good Good
Standard open Originally Cisco proprietary, now open but thin support elsewhere open, supported everywhere
Production use Rarely Yes Most common

What Link State means

  • Each router describes itself and its interfaces to its directly connected neighbours
  • That information is passed from router to router unchanged
  • So every router ends up with the full picture of the network: every router, its interfaces, and what they connect to
  • LSAs (Link State Advertisements) carry that information

2. OSPF Operations

  1. Discover neighbours
  2. Form adjacencies
  3. Flood the LSDB (Link State Database)
  4. Compute the Shortest Path
  5. Install the best routes in the routing table
  6. Respond to network changes

Packet types

Type Name Role
1 Hello Sent and listened for on OSPF-enabled interfaces to discover neighbours and form adjacencies
2 DBD (Database Description) Tells a neighbour which networks this router knows about
3 LSR (Link State Request) Asks for the specific networks missing from a received DBD
4 LSU (Link State Update) Carries the list of LSAs to be updated, used during flooding
5 LSAck Acknowledges received LSAs

An LSA is not a packet type. It's the content carried inside an LSU.

OSPF uses IP protocol number 89 (6 = TCP, 17 = UDP).


3. Basic Configuration

Process ID

R1(config)#router ospf 1
Enter fullscreen mode Exit fullscreen mode
  • Locally significant only. It does not have to match the neighbour to form an adjacency
  • Each instance has its own LSDB. Splitting one router across processes means routes won't cross between them
  • In practice only one process is ever used

The network command

R1(config-router)#network 10.0.0.0 0.0.255.255 area 0
Enter fullscreen mode Exit fullscreen mode

It means three things.

  1. Find interfaces with an IP address inside this range
  2. Enable OSPF on them (send and listen for Hellos, peer with adjacent OSPF routers)
  3. Advertise the network and mask configured on those interfaces
  • The wildcard mask is the inverse of a subnet mask. Subtract each octet from 255 (255.255.0.0 = 0.0.255.255, 255.255.255.252 = 0.0.0.3)
  • It does not fall back to the classful boundary. Omit the wildcard mask and you get % Incomplete command.
  • What gets advertised is the actual subnet on the interface, not the range typed in the network command

Verification

Command What it shows
`show run \ section ospf`
show ip protocols Router ID, area count, advertised networks, AD
show ip ospf interface brief Per-interface area, cost, state, neighbour count
show ip ospf neighbor Neighbour ID, priority, state, dead time
show ip ospf database The LSDB
show ip route O = OSPF, O IA = inter area, O E2 = external

4. Router ID

  • A 32 bit value identifying an OSPF router, written like an IP address
  • Selection order: manually configured > highest IP of any loopback > highest IP of any other interface
  • Loopbacks never go down, so the Router ID never changes
  • Best practice: use a loopback or set it manually
R1(config-router)#router-id 2.2.2.2
R1#clear ip ospf process
Enter fullscreen mode Exit fullscreen mode

A Router ID change only takes effect after the OSPF process restarts.


5. Passive Interfaces and Default Routes

Passive interface

  • Stops sending Hellos out that interface. The network is still advertised
  • Use it on interfaces with no routers behind them (user LANs, loopbacks) to cut pointless Hellos and reduce exposure
R1(config-router)#passive-interface default
R1(config-router)#no passive-interface f0/0
Enter fullscreen mode Exit fullscreen mode

Default route injection

R4(config)#ip route 0.0.0.0 0.0.0.0 203.0.113.2
R4(config)#router ospf 1
R4(config-router)#default-information originate
Enter fullscreen mode Exit fullscreen mode

Other routers receive it as O*E2 0.0.0.0/0.


6. Areas

Every router holding the full picture becomes a problem on large networks. Too many routes eat router memory, and one change makes every router reconverge, costing time and CPU.

Areas are a hierarchical design that splits a large network into smaller pieces. Each router keeps full information about its own area and only summary information about others.

  • Two-level hierarchy: a Transit area (backbone, area 0) and regular areas
  • Area 0 generally holds no end users. By default all transit traffic goes through it
  • Small networks don't need the hierarchy, everything can sit in area 0
  • The area is set per interface by the network command. Both sides must be in the same area to form an adjacency

Router types

Type Definition Route code
Backbone Router All OSPF interfaces in area 0 -
Normal Internal Router All OSPF interfaces in one normal area Same area shows as O
ABR (Area Border Router) Interfaces in multiple areas Other areas show as O IA
ASBR (Autonomous System Boundary Router) Redistributes an external protocol into OSPF External shows as O E1 / O E2

ABR characteristics

  • Separates LSA flooding zones
  • Is the primary point for area address summarization
  • Regularly acts as the source of default routes
  • Maintains a separate LSDB for each connected area
  • Ideal design is one ABR on the backbone plus one area, with three areas as the upper limit

Manual summarization

ABRs do not summarize automatically. Without it, every route is flooded everywhere.

R2(config-router)#area 0 range 10.1.0.0 255.255.0.0
R2(config-router)#area 1 range 10.0.0.0 255.255.0.0
Enter fullscreen mode Exit fullscreen mode

7. Cost Metric

  • OSPF picks the path with the lowest cost
  • Total cost = sum of the outgoing interface costs along the path
  • For a destination in another area, the router picks the cheapest path to the ABR, and the ABR decides from there
  • Set the cost the same on both ends of a link or you get asymmetric routing

Reference bandwidth

Cost = Reference Bandwidth / Interface Bandwidth
Enter fullscreen mode Exit fullscreen mode
  • The default reference bandwidth is 100 Mbps
  • FastEthernet = 100/100 = 1, T1 = 100/1.544 = 64
  • Problem: everything at 100 Mbps or faster is cost 1. FastEthernet and 10 Gigabit rank equally
  • Fix: raise the reference bandwidth, and set it identically on every router
R1(config-router)#auto-cost reference-bandwidth 100000
Enter fullscreen mode Exit fullscreen mode

speed vs clock rate vs bandwidth

Command Applies to Effect
speed Ethernet Actual physical transmission rate
clock rate Serial Actual physical transmission rate (default 1.544 Mbps)
bandwidth All No effect on physical rate. Only affects software policy: OSPF/EIGRP path selection, QoS

Manipulating the metric

  • Prefer ip ospf cost over bandwidth, because bandwidth affects features beyond OSPF such as QoS
  • A manually configured cost overrides the value derived from the bandwidth
R1(config-if)#ip ospf cost 50
Enter fullscreen mode Exit fullscreen mode

8. Adjacencies

Hello packets

  • Sent out every OSPF-enabled interface (except passive ones)
  • Multicast to 224.0.0.5 (all OSPF routers)
  • Every 10 seconds by default, Dead Interval defaults to 4x Hello = 40 seconds

Hello contents: Router ID, Hello and Dead Intervals, Neighbors list, Area ID, Router Priority, DR and BDR addresses, Authentication Flag, Stub Area Flag

These must match for two routers to form an adjacency

  • Each must be in the other's Neighbor list
  • Hello Interval, Dead Interval
  • Area ID
  • IP subnet
  • Authentication Flag
  • Stub Area Flag

MTU is not on that list. Mismatched MTU still forms neighbours, but they won't exchange routes. Default 1500 bytes, mtu affects all packets and ip mtu only IP packets.

Neighbor states

Step State Meaning
1 Down No active neighbour detected
2 INIT A Hello was received from the neighbour
3 2-Way Own Router ID appears in the received Hello (DR/BDR elected here on multiaccess)
4 Exstart The higher Router ID becomes primary, roles determined
5 Exchange DBD packets sent
6 Loading LSRs sent and LSUs received
7 Full Fully adjacent

9. DR and BDR

On point-to-point links a pair of routers simply forms a FULL adjacency. On a multiaccess segment like Ethernet there can be many routers, and having all of them form FULL adjacencies with each other is inefficient.

  • A DR (Designated Router) and BDR (Backup DR) are elected
  • Highest priority becomes DR, second highest becomes BDR. Default priority 1, range 0-255, higher is better
  • Highest Router ID breaks a tie
  • Priority 0 removes a router from the election
  • The election happens at the 2-Way stage. No election on point-to-point links
R1(config-if)#ip ospf priority 100
Enter fullscreen mode Exit fullscreen mode

Restart OSPF on the interface for it to take effect.

  • Only the DR and BDR reach FULL with every router on the segment. The rest stay at 2-Way and never exchange routes directly
  • On a link state change a router multicasts an LSU to 224.0.0.6 (all designated routers), and the DR multicasts it on to 224.0.0.5 (all OSPF routers)

10. Summary

  • OSPF is Link State, an open standard, AD 110, IP protocol number 89, uses Dijkstra's SPF
  • LSAs propagate unchanged, so every router holds the full picture of its own area
  • Process ID is local only, Router ID should come from a loopback or be set manually
  • The network command takes a wildcard mask, and what's advertised is the interface's actual subnet
  • Cost = Reference Bandwidth / Interface Bandwidth, summed over outgoing interfaces. Everything at 100 Mbps+ is cost 1, so raise the reference bandwidth identically on every router
  • Adjacency must match on: Hello/Dead Intervals, Area ID, IP subnet, Authentication, Stub Flag. MTU mismatch still forms neighbours but blocks route exchange
  • Neighbor states: Down, INIT, 2-Way, Exstart, Exchange, Loading, Full
  • DR/BDR are elected on multiaccess segments only, at the 2-Way stage. Highest priority wins, then highest Router ID
  • 224.0.0.5 for Hellos and DR reflooding, 224.0.0.6 for sending to the DR
  • ABRs don't summarize automatically. Use area range

Top comments (0)