# OSPF - Open Shortest Path First
## What is OSPF
OSPF stands for Open Shortest Path First. It is a link-state routing protocol widely used in enterprise and service provider networks. OSPF is an interior gateway protocol meaning it is used for routing within a single autonomous system. Unlike distance vector protocols like RIP, OSPF builds a complete map of the network topology and uses Dijkstra's shortest path first algorithm to calculate the best path to each destination. OSPF is defined in RFC 2328 for IPv4 and RFC 5340 for IPv6.
## How OSPF Works
Every router running OSPF collects information about its directly connected links and their costs. This information is packaged into Link State Advertisements or LSAs. Each router floods its LSAs to every other router in the OSPF area. When a router has received LSAs from all other routers it has a complete picture of the network topology. It stores this information in a link state database. Each router then independently runs Dijkstra's algorithm on its link state database to calculate the shortest path tree rooted at itself. The routing table is built from this shortest path tree.
## OSPF Cost Metric
OSPF uses cost as its metric. The cost of a link is by default calculated as 100 divided by the bandwidth of the interface in megabits per second. A 100 Mbps Ethernet link has a cost of 1. A 10 Mbps link has a cost of 10. A 1 Mbps link has a cost of 100. The total cost of a path is the sum of the costs of all links along the path. OSPF selects the path with the lowest total cost. The reference bandwidth can be adjusted to accommodate high-speed links.
## OSPF Areas
OSPF supports hierarchical design through the use of areas. An area is a logical grouping of routers that share a common link state database. All OSPF networks must have an area 0, called the backbone area. All other areas must connect to area 0, either directly or through a virtual link. Dividing the network into areas limits the size of the link state database in each area, reduces the computational burden of running Dijkstra's algorithm, and contains LSA flooding within each area. Area border routers connect areas and summarize routing information between them.
## OSPF Router Types
Internal routers have all their interfaces in a single area. Area border routers have interfaces in multiple areas and summarize routes between areas. Autonomous system boundary routers connect the OSPF network to other routing domains and redistribute external routes into OSPF. Backbone routers have at least one interface in area 0.
## OSPF Neighbor Relationships
Before routers can exchange LSAs they must become neighbors. OSPF routers discover neighbors by sending Hello packets on each OSPF-enabled interface. Two routers become neighbors if they share the same subnet, area ID, authentication, and Hello and Dead timer values. On multi-access networks like Ethernet, OSPF elects a designated router and a backup designated router to reduce the number of adjacencies that need to be formed.
## Advantages of OSPF
OSPF converges quickly when topology changes occur because LSAs are flooded immediately rather than waiting for periodic updates. It supports VLSM and CIDR. It has no hop count limit. It selects paths based on bandwidth cost rather than just hop count. It scales well to large networks through the use of areas.Back to Subject