- Open Shortest Path First (OSPF) - A Link State Dynamic Routing protocol
- Uses the Shortest Path First algorithm first invented (discovered?) by Dutch computer scientist Edsger Dijkstra
- (A.K.A Dijkstra’s algorithm)
- Three versions:
- OSPFv1 (1989): Old, not used anymore
- OSPFv2 (1998): Used for IPv4 - this version is on the CCNA Exam Topics list
- OSPFv3 (2008): Used for IPv6 (can also be used for IPv4, but typically v2 is used)
- Routers store information about the network in LSAs (Link State Advertisements) which are organized in a structure called the LSDB (Link State Database)
- Routers will flood LSAs until all routers in the OSPF area develop the same map of the network (LSDB)
- It bears repeating: The LSDB will be identical for all OSPF routers in the OSPF Area
OSPF
There are three main steps in the process of sharing LSAs and determining the best route to each destination in the network:
- Become neighbors with other routers connected to the same segment
- Exchange LSAs with neighbor routers (LSA Flooding)
- Calculate the best routes to each destination, and insert them into the routing table
OSPF Areas
- An Area is a set of routers and links that share the same LSDB
- OSPF uses areas to divide up the network
- Small networks can be single-area without any negative effects on performance
- In larger networks, a single-area design can have negative effects:
- The SPF algorithm takes more time to calculate routes
- The SPF algorithm takes exponentially more processing power on the routers
- Larger LSDBs take up more memory on the routers
- Any changes, even small ones, cause every router to flood LSAs and run the SPF algorithm again
- By dividing large OSPF networks into several smaller areas, we can avoid or mitigate the above negative effects
- In larger networks, a single-area design can have negative effects:
- Small networks can be single-area without any negative effects on performance
- Area 0 is called the backbone area and all other areas must connect to the backbone area
- Routers with all interfaces in the same area are called internal routers
- Routers with interfaces in multiple areas are called area border routers (ABRs)
- Routers connected to the backbone area are called backbone routers
- An intra-area route is a route to a destination inside the same OSPF area
- An inter-area route is a route to a destination in a different OSPF area
Area Rules
- Areas should be contiguous - you cannot have an area split into two sections of the network that are not directly connected to each other
- All areas must have at least one ABR connected to the backbone area
- OSPF interfaces in the same subnet must be in the same area
- Otherwise, they wont form adjacencies/become neighbors and won’t exchange networks
LSAs
- OSPF LSDB is made up of LSAs
LSA Flooding
- Link State Advertisement (LSA)
- Contains:
- Router ID
- IP Address (of the interface being advertised)
- Cost (Metric)
- Other info
- Contains:
- A router creates an LSA to tell its neighbors about a new network
- The LSA is flooded throughout the network until all routers have received it
- All routers in the area will then have identical copies of the LSDB
- Each router then, independently, uses the SPF algorithm to calculate its best route to the IP address included in the LSA
LSA Types
11 types of LSA, but only 3 are relevant for CCNA:
- Type 1 (Router LSA)
- Every OSPF router generates this type of LSA
- It identifies the router using its router ID
- Also lists networks attached to the router’s OSPF-activated interfaces
- Type 2 (Network LSA)
- Generated by the DR of each ‘multi-access’ network (i.e. the broadcast network type)
- Lists the routers which are attached to the multi-access network
- Type 5 (AS External LSA)
- Generated by ASBRs to describe routes to destinations outside of the AS (OSPF domain)
Metric
- OSPF’s metric is called cost
- It is automatically calculated based on the bandwidth (speed) of the interface
- Can be manually configured, too. See Configuration
- You can also affect the cost by configuring the interface bandwidth with
bandwidth
— doesn’t actually affect the interface speed, but will tell various protocols that it uses a different bandwidth. Since this affects more than OSPF cost calculations it is not recommended.
- Calculated by dividing a reference bandwidth value by the interface’s bandwidth
- Default reference bandwidth is 100 Mbps
- 100 Mbps (Reference) / 10 Mbps (Interface) = cost of 10
- 100 Mbps (Reference) / 100 Mbps (Interface) = cost of 1
- 100 Mbps (Reference) / 1 Gbps (Interface) = cost of 1
- 100 Mbps (Reference) / 10 Gbps (Interface) = cost of 1
- All values less than 1 are converted to 1 — FastEthernet, Gigabit Ethernet, 10Gig, etc. are all considered equal.
- You can (and should!) change the reference bandwidth with
auto-cost reference-bandwidth (megabits-per-second)
- You should configure a reference bandwidth greater than the fastest links in the network to allow some room for upgrades.
- You should configure the same reference bandwidth on all OSPF routers in the network (if you don’t then metrics won’t be comparable; incorrect routes will be chosen)
- Default reference bandwidth is 100 Mbps
- Cost to a given destination is the total cost of all outgoing/exit interfaces along the route
- Use
show ip ospf interface brief
to see a short summary of all interfaces and their costs on a router
Neighbors
- Making sure that routers successfully become OSPF neighbors is the main task in configuring and troubleshooting OSPF.
- Once routers become neighbors, they automatically do the work of sharing network information, calculating routes, etc.
- When OSPF is activated on an interface, the router starts sending OSPF hello messages out of the interface at regular intervals (determined by the hello timer). These are used to introduce the router to potential OSPF neighbors
- The default hello timer is 10 seconds on an Ethernet connection
- Hello messages are multicast to 224.0.0.5 (multicast address for all OSPF routers)
- OSPF messages are encapsulated in an IP header, with a value of 89 in the Protocol field
Requirements
- Area number must match
- Interfaces must be in the same subnet
- OSPF process must not be shutdown
- OSPF Router IDs must be unique
- Hello and Dead timers must match
- Authentication (password) settings must match
- IP MTU settings must match
- Can become OSPF neighbors with mismatch, but OSPF doesn’t operate properly
- OSPF Network Type must match
- Can become OSPF neighbors with mismatch, but OSPF doesn’t operate properly
Neighbor States
- Down - No known OSPF neighbors
- One router sends the first message. It usually doesn’t matter which is first.
- Init - A Hello packet was received, but own router ID is not in the Hello packet
- The first message can’t have the recipient’s RID as the sender doesn’t know it yet. The recipient will send its own Hello packet with both RIDs in it.
- 2-way - The router has received a Hello packet with its own RID in it.
- The first router receives the Hello packet with its own RID, then sends another Hello packet with the second router’s RID. This moves both routers to the 2-way state.
- Exstart - Routers establish a ‘Master’ and ‘Slave’ relationship; the master will control the exchange of LSDB
- The routers exchange DBD (Database Description) packets containing their RIDs. The router with the higher RID becomes the Master, the other is the Slave.
- Exchange - The routers each send a list of the LSAs in their LSDB to each other. They compare the received message against their own LSDB to determine what LSAs they are missing
- The Master router will initiate the exchange. The LSA lists are send in DBD packets.
- Loading - Routers send Link State Request (LSR) messages to request their neighbors send them missing LSAs. The LSAs are send in Link State Update (LSU) messages. The routers send LSAck messages to acknowledge that they received the LSAs
- Full - The routers have a full adjacency and identical LSDBs
- The routers will still continue to send Hello packets (every 10 seconds, by default) and will share LSAs as the network changes to maintain identical LSDBs.
- They will not stop treating each other as neighbors unless their dead timer runs out (40s without receiving a Hello packet, by default).
Messages
Type | Name | Purpose |
---|---|---|
1 | Hello | Neighbor discovery and maintenance |
2 | Database Description (DBD) | Summary of the LSDB of the router. Used to check if the LSDB of each router is the same. |
3 | Link-State request (LSR) | Requests specific LSAs from the naighbor. |
4 | Link-State Update (LSU) | Sends specific LSAs to the neighbor. |
5 | Link-State Achnowledgement (LSAck) | Used to acknowledge that the router received a message. |
Network Types
- The OSPF ‘network type’ refers to the type of connection between OSPF neighbors (Ethernet, etc.)
- There are three main OSPF network types:
- Broadcast - enabled by default on Ethernet and FDDI (Fiber Distributed Data Interfaces) interfaces
- Point-to-point - enabled by default on PPP (Point-to-point protocol) and HDLC (High-Level Data Link Control) interfaces
- Non-Broadcast - enabled by default on Frame Relay and X.25 interfaces
- You can manually configure the network type with
ip ospf network (type)
- Non-Broadcast nets use different timers:
- Hello 10, Dead 40 for Broadcast and PTP
- Hello 30, Dead 120 for Non-Broadcast
Broadcast
- Enabled on Ethernet and FDDI interfaces by default
- Routers dynamically discover neighbors by sending/listening for OSPF Hello messages using multicast address
224.0.0.5
- A DR (designated router) and BDR (backup designated router) must be elected on each subnet (only DR if there are no OSPF neighbors)
- Routers which aren’t the DR or BDR become a DROther
- DROthers don’t form full adjacencies with other DROthers; they remain in the 2-way state. DROthers only form full adjacencies with the DR and BDR.
- Therefore, routers only exchange LSAs with the DR and BDR. DROthers do not exchange LSAs with each other.
- All routers will still have the same LSDB, but this reduces the amount of LSAs flooding the network
- Messages to the DR/BDR are multicast to
224.0.0.6
Point-to-point
- Enabled on Serial Interfaces using the PPP or HDLC encapsulations by default
- Routers dynamically discover neighbors by sending/listening for OSPF Hello messages using multicast address 224.0.0.5
- No DR/BDR election
- These encapsulations are used for ‘point-to-point’ connections
- Only 2 nodes; no need for DR/BDR
- The two routers form a full adjacency
DR/BDR election
- Highest OSPF interface priority
- Highest OSPF Router ID
- ’First place’ becomes the DR for the subnet, ‘second place’ becomes the BDR
- Default OSPF interface priority is 1 on all interfaces; unless configured, highest RID will win
- Change OSPF Priority with
ip ospf priority (0-255)
- Non-preemptive; Reelection won’t occur until OSPF is reset, an interface fails/is shut down, etc.
- Change OSPF Priority with
- When OSPF is reset on the DR, the BDR becomes the new DR (even if it doesn’t have the highest priority)
Configuration
- Sample CLI Input
router ospf 1
- ’1’ is the process ID — a locally significant identifier. Routers with different process IDs can still be neighbors. You will typically only need one OSPF process on a router, but routers are capable of running many at once.
network 10.0.12.0 0.0.0.3 area 0
network 10.0.13.0 0.0.0.3 area 0
network 172.16.1.0 0.0.0.15 area 0
passive-interface g2/0
- Note that OSPF uses Wildcard Masks
network
works like in EIGRP; tells OSPF to…- look for any interfaces with an IP address contained in the range specified in the command
- Activate OSPF on the interface in the specified area
- The router will then try to become OSPF neighbors with other OSPF-activated neighbor routers
passive-interface (interface-id)
- Tells the router to stop sending OSPF ‘hello’ messages out of the interface
- The router will continue to send LSAs informing its neighbors about the subnet configured on the interface.
- You should always use this command on interfaces which don’t have any OSPF neighbors
passive-interface default
- configure all interfaces to be passive by default. Make an interface non-passive again with
no passive-interface (interface-id)
- configure all interfaces to be passive by default. Make an interface non-passive again with
default-information originate
- Advertises the default route into OSPF
- Causes OSPF to generate and send an LSA
router-id (a.b.c.d)
- Manually configure the Router ID
- Router must be reloaded or you must use
clear ip ospf process
for the new RID to take effect- Generally you should avoid using the command in a real network; the router will lose all its OSPF routes until it can relearn them
auto-cost reference-bandwidth (megabits-per-second)
- Manually configure the reference bandwidth used for calculating route/interface costs
- Default value is 100 Mbps — you should configure it to be significantly higher
- Ideally, it will be larger than the fastest link in the network
ip ospf cost (cost)
- Manually set the cost of an interface
ip ospf 1 area 0
- Enable OSPF directly on an interface (run this from interface configuration!)
ip ospf priority (0-255)
- Change OSPF interface priority; change which routers becomes DR/BDR/BDOther
- run from (config-if)
- non-preemptive; OSPF must be reset for DR/BDR reelection
ip ospf network (type)
- manually change the network type, run from (config-if)
ip ospf authentication-key (password)
&ip ospf authentication
- Configure an OSPF password & enable its use