Open Shortest Path First (OSPF) is a routing protocol for Internet Protocol (IP) networks. It uses a link state routing (LSR) algorithm and falls into the group of interior gateway protocols (IGPs), operating within a single autonomous system (AS).
OSPF gathers link state information from available routers and constructs a topology map of the network. The topology is presented as a routing table to the internet layer for routing packets by their destination IP address. OSPF supports Internet Protocol version 4 (IPv4) and Internet Protocol version 6 (IPv6) networks and is widely used in large enterprise networks. IS-IS, another LSR-based protocol, is more common in large service provider networks.
Originally designed in the 1980s, OSPF version 2 is defined in RFC 2328 (1998). The updates for IPv6 are specified as OSPF version 3 in RFC 5340 (2008). OSPF supports the Classless Inter-Domain Routing (CIDR) addressing model.
Concepts OSPF is an interior gateway protocol (IGP) for routing Internet Protocol (IP) packets within a single routing domain, such as an autonomous system. It gathers link state information from available routers and constructs a topology map of the network. The topology is presented as a routing table to the internet layer, which routes packets based solely on their destination IP address.
OSPF detects changes in the topology, such as link failures, and converges on a new loop-free routing structure within seconds. It computes the shortest-path tree for each route using a method based on Dijkstra's algorithm. The OSPF routing policies for constructing a route table are governed by link metrics associated with each routing interface. Cost factors may be the distance of a router (round-trip time), data throughput of a link, or link availability and reliability, expressed as simple unitless numbers. This provides a dynamic process of traffic load balancing between routes of equal cost.
OSPF divides the network into routing areas to simplify administration and optimize traffic and resource utilization. Areas are identified by 32-bit numbers, expressed either simply in decimal or often in the same octet-based dot-decimal notation used for IPv4 addresses. By convention, area 0 (zero), or 0.0.0.0, represents the core or backbone area of an OSPF network. While the identifications of other areas may be chosen at will, administrators often select the IP address of a main router in an area as the area identifier. Each additional area must have a connection to the OSPF backbone area. Such connections are maintained by an interconnecting router, known as an area border router (ABR). An ABR maintains separate link-state databases for each area it serves and maintains summarized routes for all areas in the network.
OSPF runs over IPv4 and IPv6, but does not use a transport protocol such as UDP or TCP. It encapsulates its data directly in IP packets with protocol number 89. This is in contrast to other routing protocols, such as the Routing Information Protocol (RIP) and the Border Gateway Protocol (BGP). OSPF implements its own transport error detection and correction functions. OSPF also uses multicast addressing for distributing route information within a broadcast domain. It reserves the multicast addresses (IPv4) and (IPv6) for all SPF/link state routers (AllSPFRouters) and (IPv4) and (IPv6) for all Designated Routers (AllDRouters). For non-broadcast networks, special provisions for configuration facilitate neighbor discovery. OSPF multicast IP packets never traverse IP routers, they never travel more than one hop. The protocol may therefore be considered a link-layer protocol, but is often also attributed to the application layer in the TCP/IP model. It has a virtual link feature that can be used to create an adjacency tunnel across multiple hops. OSPF over IPv4 can operate securely between routers, optionally using a variety of authentication methods to allow only trusted routers to participate in routing. OSPFv3 (IPv6) relies on standard IPv6 protocol security (IPsec), and has no internal authentication methods.
For routing IP multicast traffic, OSPF supports the Multicast Open Shortest Path First (MOSPF) protocol. Cisco does not include MOSPF in their OSPF implementations. Protocol Independent Multicast (PIM) in conjunction with OSPF or other IGPs, is widely deployed.
OSPF version 3 introduces modifications to the IPv4 implementation of the protocol. Except for virtual links, all neighbor exchanges use IPv6 link-local addressing exclusively. The IPv6 protocol runs per link, rather than based on the subnet. All IP prefix information has been removed from the link-state advertisements and from the hello discovery packet, making OSPFv3 essentially protocol-independent. Despite the expanded IP addressing to 128 bits in IPv6, area and router Identifications are still based on 32-bit numbers.
Router relationships + Network types (OSPFv2) Network type Point to point (P2P) Broadcast (default) Non-broadcast multi-access (NBMA) Point to multipoint Point to multipoint non broadcast (P2MP-NB) Passive Max routers per network 2 Unlimited Unlimited Unlimited Unlimited Full mesh assumed style="text-align:center;vertical-align:bottom;border-right: solid 2px " style="text-align:center;vertical-align:bottom;border-right: solid 2px " style="text-align:center;vertical-align:bottom;border-right: solid 2px " Hello timer (default Cisco)10 1030 3030 Dead timer (default Cisco)40 40120 120120 Wait timer0 equal to dead timerequal to dead timer 00 Automatic neighbour discovery style="text-align:center;vertical-align:bottom;border-right: solid 2px " style="text-align:center;vertical-align:bottom;border-right: solid 2px " style="text-align:center;vertical-align:bottom;border-right: solid 2px " Discovery and hellos are sent to224.0.0.5 224.0.0.5Neighbour IP 224.0.0.5Neighbour IP Neighbour communication is sent to224.0.0.5 UnicastUnicast UnicastUnicast LSAs are sent to224.0.0.5 DR/BDR: 224.0.0.6All: 224.0.0.5DR/BDR: 224.0.0.6All: 224.0.0.5 UnicastUnicast Next-hop IPPeer Original routerOriginal router HubHub Imported in to OSPF as Stub and P2P TransitTransit Stub and P2PStub and P2P Stub OSPF supports complex networks with multiple routers, including backup routers, to balance traffic load on multiple links to other subnets. Neighboring routers in the same broadcast domain or at each end of a point-to-point link communicate with each other via the OSPF protocol. Routers form adjacencies when they have detected each other. This detection is initiated when a router identifies itself in a hello protocol packet. Upon acknowledgment, this establishes a two-way state and the most basic relationship. The routers in an Ethernet or Frame Relay network select a designated router (DR) and a backup designated router (BDR), which act as a hub to reduce traffic between routers. OSPF uses both unicast and multicast transmission modes to send "hello" packets and link-state updates.
As a link-state routing protocol, OSPF establishes and maintains neighbor relationships for exchanging routing updates with other routers. The neighbor relationship table is called an adjacency database. Two OSPF routers are neighbors if they are members of the same subnet and share the same area ID, subnet mask, timers and authentication. In essence, OSPF neighborship is a relationship between two routers that allows them to see and understand each other but nothing more. OSPF neighbors do not exchange any routing information the only packets they exchange are hello packets. OSPF adjacencies are formed between selected neighbors and allow them to exchange routing information. Two routers must first be neighbors, and only then can they become adjacent. Two routers become adjacent if at least one of them is designated router or backup designated router (on multiaccess-type networks), or they are interconnected by a point-to-point or point-to-multipoint network type. For forming a neighbor relationship between the interfaces, the relationship must be in the same OSPF area. While an interface may be configured to belong to multiple areas, this is generally not practiced. When configured in a second area, an interface must be configured as a secondary interface.
Operation modes The OSPF can have different operation modes on the following setups on an interface or network: Point-to-point. Each router advertises itself by periodically multicasting hello packets. No designated router is elected. The interface can be IP unnumbered (without a unique IP address assigned to it). Broadcast (default), each router advertises itself by periodically multicasting hello packets. Non-broadcast multi-access, with the use of designated routers. May need static configuration. Packets are sent as unicast. Point-to-multipoint, where OSPF treats neighbours as a collection of point-to-point links. No designated router is elected. Separate hello packets are sent to each neighbor. Point to Multipoint Non Broadcast (P2MP-NB), No designated router is elected. Separate hello packets are sent to each neighbor. Packets are sent as unicast. Passive, Only advertised to other neighbours. No adjacency is advertised on network.
Indirect connections Virtual link over Virtual links, tunneling and sham links, are a form of connections that goes over the routing engine, and is not a direct connection to the remote host.
Virtual links: The packets are sent as unicast. Can only be configured on a non-backbone area (but not stub-area). Endpoints need to be ABR, the virtual links behave as unnumbered point-to-point connections. The cost of an intra-area path between the two routers is added to the link. Virtual link over tunneling (like GRE and WireGuard): Since OSPF does not support virtual links for areas other than the backbone, a workaround is the use of tunneling. If the same IP or router ID is used, the link creates two equal-cost routes to the destination. Sham link: An intra-area link that connects two sites via the MPLS VPN backbone that is preferred to an internal intra-area "OSPF backdoor link" between the same two sites. A sham link is only needed if the MPLS VPN backbone is preferred over the OSPF backdoor link.
Adjacency state machine Each OSPF router within a network communicates with other neighboring routers on each connecting interface to establish the states of all adjacencies. Every such communication sequence is a separate conversation identified by the pair of router IDs of the communicating neighbors. RFC 2328 specifies the protocol for initiating these conversations (Hello Protocol) and for establishing full adjacencies (database description packets, link-state request packets). During its course, each router conversation transitions through a maximum of eight conditions defined by a state machine:
Neighbor state changes
Down: The state down represents the initial state of a conversation when no information has been exchanged and retained between routers with the Hello Protocol. Attempt: The attempt state is similar to the down state, except that a router is in the process of efforts to establish a conversation with another router, but is only used on non-broadcast multiple-access networks (NBMAs). Init: The init state indicates that a hello packet has been received from a neighbor, but the router has not established a two-way conversation. Two-way: The two-way state indicates the establishment of a bidirectional conversation between two routers. This state immediately precedes the establishment of adjacency. This is the lowest state of a router that may be considered as a DR.
Database exchange
Exchange start (exstart): The exstart state is the first step of adjacency of two routers. Exchange: In the exchange state, a router is sending its link-state database information to the adjacent neighbor. At this state, a router can exchange all OSPF routing protocol packets.