---
title: Open Shortest Path First (OSPF)
breadcrumbs:
- title: Network
---
{% include header.md %}

### Related Pages
{:.no_toc}

- [Routing Theory](/networking/routing/)

## TODO

- OSPFv3.
- Auth for v2 and v3. Best practices.
- Always redistribute into OSPF as external type 1 to allow updating OSPF metric (type 2, NSSA external, does not).



## Theory

### General

- A link-state (LS) IGP, using Dijkstra's algorithm individually on all routers to calculate the shortest paths.
- The metric used to calculate path lengths is the cumulative link cost, where the link costs are generally based on the capacity of the links.
    - Cisco uses a rather low reference bandwidth where 100Mb/s Ethernet and everything above has the same cost of 1. This reference can be adjusted using the `ospf auto-cost reference-bandwidth <x>` command or apropriately setting `ip ospf cost <x>` for each interface.

### Areas

- Uses a two-tier hierarchy consisting of a backbone area (area 0) and zero or more regular areas.
- Regular areas can only be connected to the backbone area and not to eachother.
    - If a non-backbone router is connected to multiple areas, it will not become an ABR for the areas and it will not redistribute LSAs between them. Routes and LSAs will be kept separate. This design should probably be avoided.
- Area IDs are 32-bit numbers represented in decimal or dotted decimal.
- **Backbone area**:
    - "Main" area (area 0), connected to all other areas.
- **Regular area**:
    - Any non-backbone area.
- **Stub area**:
    - Configured as `stub` (IOS) on the ABRs.
    - For areas with external routes (i.e. ASBRs).
    - Prevents external LSAs from flooding into the area and makes the ABR generate default route LSAs into the area, while still alowing normal summary LSAs from other areas.
    - Don't support virtual links.
- **Totally stubby area** (Cisco variant):
    - Configured as `stub no-summary` (IOS) on the ABRs.
    - Just like a stub area, but blocks summary LSAs (type 3 and 4) in addition to external LSAs.
    - Only the default route generated by the ABRs is used.
- **Not so stubby area (NSSA)**:
    - Configured as `nssa` (IOS) on the ABRs.
    - Like a stub area (no external LSAs flooded *into* it), but allows external routes (i.e. it allows ASBRs).
    - The ASBRs generate NSSA external LSAs (type 7), which are translated to external LSAs (type 5) at the ABRs.
    - NSSAs may be used to summarize external routes before they're distributed into the backbone area.
    - Among the stub area types, this one is typically the most appropriate.
- **Totally NSSA** (Cisco variant):
    - Configured as `nssa no-summary` (IOS) on the ABRs.
    - Like an NSSA, but without summary LSAs, like a totally stubby area.

### Routers

- Area boundaries in OSPF are through routers (not between), so OSPF routers have interfaces in one or more areas.
- **Backbone router**:
    - A router with an interface in the backbone area.
    - Maintains state information about all backbone links, all summary links and all external links.
- **Internal router**:
    - A router with all interfaces inside a single area.
- **Area border router (ABR)**:
    - A router with interfaces in multiple areas.
    - Is implicitly always a backbone router.
    - May summarize routes for one of the areas.
- **AS boundary router (ASBR)**:
    - A router that imports routing information from another AS as external routes.
    - Does not need to be a backbone router.
    - May summorize external routes.

### Link State Advertisements (LSAs)

- LSAs contain link state information and are flooded to all routers in an area and partially to other areas.
- LSA types:
    - **Router LSA** (**type 1**): For XXX. Flooded to XXX.
    - **Network LSA** (**type 2**):
    - **Summary LSA** (**type 3**):
    - **ASBR summary LSA** (**type 4**):
    - **External LSA** (type 5**) (**external type 1**):
    - **NSSA external LSA** (**type 7**) (**external type 2**):

{% include footer.md %}
