At a very high level, the operation of OSPF is easily explained:
- 1 OSPF-speaking routers send Hello packets out all OSPF-enabled interfaces. If two routers sharing a common data link agree on certain parameters specified in their respective Hello packets, they will become neighbors.
- 2 Adjacencies, which can be thought of as virtual point-to-point links, are formed between some neighbors. OSPF defines several network types and several router types. The establishment of an adjacency is determined by the types of routers exchanging Hellos and the type of network over which the Hellos are exchanged.
- 3 Each router sends link-state advertisements (LSAs) over all adjacencies. The LSAs describe all of the router’s links, or interfaces, the router’s neighbors, and the state of the links. These links might be to stub networks (networks with no other router attached), to other OSPF routers, to networks in other areas, or to external networks (networks learned from another routing process). Because of the varying types of link- state information, OSPF defines multiple LSA types.
- 4 Each router receiving an LSA from a neighbor records the LSA in its link-state database and sends a copy of the LSA to all of its other neighbors.
- 5 By flooding LSAs throughout an area, all routers will build identical link-state databases.
- 6 When the databases are complete, each router uses the SPF algorithm to calculate a loop-free graph describing the shortest (lowest cost) path to every known destination, with itself as the root. This graph is the SPF tree.
- 7 Each router builds its route table from its SPF tree.
Hello packets are exchanged between neighbors as keepalives, and LSAs are retransmitted every 30 minutes. If the network topology is stable, no other activity should occur.
- Each Hello packet contains the following information:
- Router ID of the originating router.
- Area ID of the originating router interface.
- Address mask of the originating interface.
- Authentication type and authentication information for the originating interface.
- HelloInterval of the originating interface.
- RouterDeadInterval of the originating interface.
- Router Priority.
- DR and BDR.
- Five flag bits signifying optional capabilities.
- Router IDs of the originating router’s neighbors. This list contains only routers from which Hellos were heard on the originating interface within the last RouterDeadInterval.
Whenever a router sends a Hello, it includes in the packet the Router IDs of all neighbors listed for the link on which the packet is to be transmitted. If a router receives a valid Hello in which it finds its own Router ID listed, the router knows that two-way communication has been established.
DR/BDR election:
In simpler language, when an OSPF router becomes active and discovers its neighbors, it checks for an active DR and BDR. If a DR and BDR exist, the router accepts them. If there is no BDR, an election is held in which the router with the highest priority becomes the BDR. If more than one router has the same priority, the one with the numerically highest Router ID wins. If there is no active DR, the BDR is promoted to DR and a new election is held for the BDR.
So any cost that is calculated to a fraction of 1 is rounded up to 1. However, this means that if your network consists of high-bandwidth links, all interfaces wind up with a cost of 1 and the calculated shortest paths become based on least router hops.
Adjacency:
An adjacency is established in four general phases:
- 1 Neighbor discovery.
- 2 Bidirectional communication. This communication is accomplished when twoneighbors list each other’s Router IDs in their Hello packets.
- 3 Database synchronization. Database Description, Link State Request, Link State Update, and Link State Acknowledgement packets (described in a later section) are exchanged to ensure that both neighbors have identical information in their link-state databases. For the purposes of this process, one neighbor will become the master and the other will become the slave. As the name implies, the master will control the exchange of Database Description packets.
- 4 Full adjacency.
Neigborship:
- use hello packets to discover neighbors.hello packets are send to 224.0.0.5 Multi-cast address. Hello packets will contains router-id, area, Interface IP,Neighbor priority, DR, BDR, etc
- 2-way communication is established whenever router A sees its name in the list of the neighbour in the routerB’s hello packet.
Neighbor State Machine:
- Down state: OSPF neighbours start with down state which means no hello has been received from the neighbor
- init state: When a hello is received from the neighbour but I don’t see my router-id in the neighbour’s hello packet (hello packet will have the list of the neighbours router-id). I will move to init state
- 2-way state: when I receive hello from the neighbour and see my router-id in the neighbours hello packet, I will move to 2-way state. DR/BDR Election will happen at this stage
- Exstart state: Master/Slave relationship happens in this state. Initial database descriptor sequence number is determined by the master. router with highest router-id becomes the master
- Exchange: the router send database descriptor to the neighbour giving summary of the LSA router has. neighbour may request further details using Link state request
- Loading: Link state request is done in this state
- Full: fully adjancency
Adjacency:
Adjacency uses below 3 OSPF packet types:
- Database descriptors
- the packets carry a summary description of each LSA in the originating router’s link-state database.
- Link state request packets
- Link state update packets
- Link state acknowledgment
- Explicit Acknowledgment—A Link State Acknowledgment packet containing the LSA header is received
- Implicit Acknowledgment—An Update packet that contains the same instance of the LSA (neither LSA is more recent than the other) is received
OSPF Areas:
- Areas are identified by a 32-bit Area ID.
- The Area 0 or backbone is responsible for summarizing the topologies of each area to every other area
- A virtual link is a link to the backbone through a non-backbone area.
- Virtual links must be configured between two ABRs.
LSA types:
Type 1: This most fundamental LSA lists all of a router’s links, or interfaces, the state and outgoing cost of each link, and any known OSPF neighbors on the link. These LSAs are flooded only within the area in which they are originated.
Type 2: are produced by the DR on every multi-access network
Type 3: are originated by ABRs.When an ABR originates a Network Summary LSA, it includes the cost from itself to the destination the LSA is advertising.When another router receives a Network Summary LSA from an ABR, it does not run the SPF algorithm. Rather, it simply adds the cost of the route to the ABR and the cost included in the LSA.
Type 4: ASBR Summary LSAs are also originated by ABRs. ASBR Summary LSAs are identical to Network Summary LSAs except that the destination they advertise is an ASBR.
Type 5: External LSAs, are originated by ASBRs.They advertise either a destination external to the OSPF autonomous system, or a default route external to the OSPF autonomous system. These LSAs are flooded throughout the autonomous system
Type 6:
Type 7:
Stub area:
A stub area is an area into which AS External LSAs are not flooded. And if type 5 LSAs are not known inside an area, type 4 LSAs are unnecessary; these LSAs are also blocked. ABRs at the edge of a stub area use Network Summary (type 3) LSAs to advertise a single default route (destination 0.0.0.0) into the area.
NSSA:
allow external routes to be advertised into the OSPF autonomous system while retaining the characteristics of a stub area to the rest of the autonomous system. To do this, the ASBR in an NSSA will originate type 7 LSAs to advertise the external destinations. These NSSA External LSAs are flooded throughout the NSSA but are blocked at the ABR.
The NSSA External LSA has a flag in its header known as the P-bit. The NSSA ASBR has the option of setting or clearing the P-bit. If the NSSA’s ABR receives a type 7 LSA with the P-bit set to one, it will translate the type 7 LSA into a type 5 LSA and flood it throughout the other areas
If the P-bit is set to zero, no translation will take place and the destination in the type 7 LSA will not be advertised outside of the NSSA. This option allows you to design an NSSA in which the external destinations learned in that area are known only in that area.
Path types:
when choosing a route and adding in the routing table, ospf will consider: intera-area > inter-area > E1 > E2
what is E1 and E2?
When ASBR redistributes routes, it adds a cost which can be understand by OSPG process.now to reach a route outside OSPF domain, you have cost of reaching out to the ASBR + ASBR advertised cost of the route. In E1, total cost = cost to reach ASBR + ASBR cost. In E2, only ASBR advertised cost is taken into account. In can be used for hot-potato routing.