OSPF (Open Shortest Path First) is a Classless, Interior Gateway Protocol (IGP) for IP networks used to distribute routing information within a single Autonomous System. OSPF is defined in RFC 2328 for IPv4 (OSPF v2) and RFC 5340 for IPv6 (OSPF v3).
OSPF is one of two Link-State routing protocols, the other one being IS-IS, and is mostly used in enterprise networks. Link-State protocols form a database with the complete topology of their network and use Dijkstra's algorithm to calculate the best path through. The fact that OSPF has a complete knowledge of the network allows it to respond quickly to topology changes, like an interface failure, and to converge in seconds. Another advantaged of this is that it creates a loop-free structure without the need of Split-Horizon as in Distance Vector protocols.
OSPF uses “Cost” as its metric. The lower the Cost, the more preferred the path. The formula to calculate Cost (OSPF’s metric) is:
The reference bandwidth is set with the “ospf auto-cost reference-bandwidth” under the OSPF process. The default on IOS devices is 100Mbps. Here is an example of a 10Mbps link with the default reference:
This link would have a Cost of 10, and be more preferred than any paths with a Cost >10.
Designated Router (DR)/Backup Designated Router (BDR)
Designated Routers and Backup Designated routers will be elected for multi-access segments on which OSPF is running. Non-DR/BDR routers will only form adjacencies with the DR and BDR on a segment. This makes each OSPF segment more efficient by cutting down on the traffic between neighbors. The DR/BDR election is based on the priority of the router’s interface participating in the election, if priorities are equal, Router-ID (RID) is used to break the tie. A router can be configured to never become the DR or BDR for a segment with the command “ip ospf priority 0” on an interface.
The RID a 32-bit number, which is decided based on the highest interface IP address, with loopbacks taking priority. For instance, a router has two interfaces, one physical and one loopback. The physical interface has an IP of 172.30.1.1 and the loopback has an IP of 188.8.131.52. In this case, the RID will be 184.108.40.206 because it’s the highest loopback IP address.
There are four OSPF router types, they are:
- Internal Router - An internal router is a router that has all its interfaces in the same area.
- Area Border Router (ABR) - An ABR is a router which sits between multiple areas and one of these must be area 0. The ABR keeps a Link-State Database (LSDB) for each area in which is resides.
- Autonomous System Boundary Router (ASBR) - An ASBR is a router which connects an OSPF autonomous system to an external autonomous system, for instance BGP/the Internet or another routing domain within a network.
- Backbone Router - A backbone router is a router that has at least one interface in area 0. All ABRs should also be backbone routers since they should be connected to area 0.
Link-State Advertisements (LSAs)
In an OSPF Autonomous System, multiple areas can exist. Every router in an area knows about every link in the area. This is accomplished with LSAs. Routers store LSAs in the Link-State Database (LSDB). Each LSA has a specific function. The OSPF LSA types are:
- Type 1 - Router LSA - the router announces its presence and lists the links to other routers or networks in the same area, together with the metrics to them. Type 1 LSAs are flooded across their own area only. The link-state ID of the type 1 LSA is the originating router ID.
- Type 2 - Network LSA - the designated router on a broadcast segment (e.g. Ethernet) lists which routers are joined together by the segment. Type 2 LSAs are flooded across their own area only. The link-state ID of the type 2 LSA is the IP interface address of the DR.
- Type 3 - Summary LSA - an Area Border Router (ABR) takes information it has learned on one of its attached areas and it can summarize it (but not by default) before sending it out on other areas it is connected to. This summarization helps provide scalability by removing detailed topology information for other areas, because their routing information is summarized into just an address prefix and metric. The summarization process can also be configured to remove a lot of detailed address prefixes and replace them with a single summary prefix, also helping scalability. The link-state ID is the destination network number for type 3 LSAs.
- Type 4 - ASBR-Summary LSA - this is needed because Type 5 External LSAs are flooded to all areas and the detailed next-hop information may not be available in those other areas. This is solved by an Area Border Router flooding the information for the router (i.e. the Autonomous System Boundary Router) where the type 5 originated. The link-state ID is the router ID of the described ASBR for type 4 LSAs.
- Type 5 - External LSA - these LSAs contain information imported into OSPF from other routing processes. They are flooded to all areas (except stub areas). For "External Type 1" LSAs routing decisions are made by adding the OSPF metric to get to the ASBR and the external metric from there on, while for "External Type 2" LSAs only the external metric is used. The link-state ID of the type 5 LSA is the external network number.
- Type 6 - Group Membership LSA - this was defined for Multicast extensions to OSPF (MOSPF), a multicast OSPF routing protocol which was not in general use. MOSPF has been deprecated since OSPFv3 and is not currently used. It may be reassigned in the future.
- Type 7 - Routers in a Not So Stubby Areas (NSSA) do not receive external LSAs from Area Border Routers, but are allowed to send external routing information for redistribution. They use type 7 LSAs to tell the ABRs about these external routes, which the Area Border Router then translates to type 5 external LSAs and floods as normal to the rest of the OSPF network.
Regarding OSPF there are three network types, Point-to-Point, Broadcast and Non-Broadcast. These types and their characteristics are:
- Point-to-Point - Each of these networks has exactly two members and a single path between them. These networks have no broadcast capability, so OSPF communication is unicast. No Designated Router (DR) or Backup Designated Router (BDR) is elected. An example Point-to-Point network is PPP.
- Broadcast - These networks have broadcast capability and are further divided into the two following types.
- Broadcast (Multi-Access) - These networks allow multiple (more than two) routers to access the same network and also offer a broadcast ability. In these, OSPF will automatically form adjacencies, and a DR and a BDR is elected. OSPF communication is multicast. An example broadcast network is Ethernet.
- Point-to-Multipoint, Broadcast - These networks consist of a single router who is connected by a single path with multiple others. These networks have a broadcast capability so OSPF communication is multicast and a DR or BDR is elected.
- Non-Broadcast - These networks don't have broadcast capability and are, also, divided into two types.
- Point-to-Multipoint, Non-Broadcast - These networks consist of a single router who is connected by a single path with multiple others. Since these networks have no broadcast capability, OSPF communication is unicast. No DR or BDR is elected. An example Non-Broadcast Point-to-Point network is IP over ATM.
- Non-Broadcast Multi-Access (NBMA) - - These networks allow multiple routers to access the same network but do not have a broadcast capability, so OSPF communication is unicast. A DR and a BDR will be elected. An example NBMA network is Frame Relay.
OSPF uses the concept of areas to logically group routers inside an autonomous system. The backbone area is 0. All other areas must connect to area 0. Within an area, updates are flooded to all routers. All routers in an area must have complete information about the area.
OSPF has multiple area types:
- Backbone - Area 0 is the back bone in an OSPF autonomous system. All areas must connect to Area 0. This should be accomplished physically, but it can be done virtually with OSPF Virtual Links. Area 0 must also be contiguous.
- Stub - A Stub area does not accept external LSAs (type 5). They are filtered at the ABR. The ABR generates a default route (0.0.0.0) which is injected into the stub area.
- Totally Stubby Area - A Totally Stubby Area does not accept external (type 5) or summary LSAs (type 3/inter-area). Similar to Stub Areas, ABRs in Totally Stubby Areas generate and inject a default route into the area.
- Not So Stubby Area (NSSA) - NSSAs are essentially stub areas that include an ASBR. These areas do not accept external LSAs (type 5). The ASBR in a NSSA injects external prefixes as Type 7 LSAs, which are converted to Type 5 LSAs by the area’s ABR.
- NSSA Totally Stubby Area - NSSA Totally Stubby areas are a mixture of NSSAs and Totally Stubby Areas. These areas do not allow external (type 5) or summary (type 3) LSAs. They have an ASBR which injects external prefixes as Type 7 LSAs, which are converted to Type 5 LSAs by the ABR.