What is OSPF? Packet Types



Packet types for OSPF

  • Hello packet: Exchanges information about neighbors with each other.
  • Database Description packet: Elects a version of the database to be used.
  •  Link-state request packet: Requests a specific LSA from a neighbor.
  •  Link-state update packet: Sends an entire LSA to a neighbor who has requested an update.
  •  Link-state acknowledge packet: Acknowledges the receipt of a link-state update packet.

    1.ospf_hello
    2.ospf_dd
    3.ospf_lsr


                                                       3a.router LSA

                                               

                                                         3b.Network LSA

                                               

                                                      3c.Summary LSA

                                                

                                                       3d.External LSA


    4.ospf_lsu
    5.ospf_lsa

    states an interface passes through before becoming adjacent to another router:






    Neighbor State Machine

    1.Down The initial state of a neighbor conversation indicates that no Hellos have been heard from the neighbor in the last RouterDeadInterval. Hellos are not sent to down neighbors unless those neighbors are on NBMA networks; in this case, Hellos are sent every PollInterval. If a neighbor transitions to the Down state from some higher state, the link state Retransmission, Database Summary, and Link State Request lists are cleared.
    2.Attempt This state applies only to neighbors on NBMA networks, where neighbors are manually configured. A DR-eligible router transitions a neighbor to the Attempt state when the interface to the neighbor first becomes Active or when the router is the DR or BDR. A router sends packets to a neighbor in Attempt state at the HelloInterval instead of the PollInterval.
    3.Init This state indicates that a Hello packet has been seen from the neighbor in the last RouterDeadInterval, but two-way communication has not yet been established. A router includes the Router IDs of all neighbors in this state or higher in the Neighbor field of the Hello packets.
    4.2-Way This state indicates that the router has seen its own Router ID in the Neighbor field of the neighbor’s Hello packets, which means that a bidirectional conversation has been established. On multi-access networks, neighbors must be in this state or higher to be eligible to be elected as the DR or BDR. The reception of a Database Description packet from a neighbor in the init state also causes a transition to 2-Way.
    5.ExStart In this state, the router and its neighbor establish a master/slave relationship and determine the initial DD sequence number in preparation for the exchange of Database Description packets. The neighbor with the highest Router ID becomes the master.
    6.Exchange The router sends Database Description packets describing its entire link-state database to neighbors that are in the Exchange state. The router may also send Link State Request packets, requesting more recent LSAs, to neighbors in this state.
    7.Loading The router sends Link State Request packets to neighbors that are in the Loading state, requesting more recent LSAs that have been discovered in the Exchange state but have not yet been received.
    8.Full Neighbors in this state are fully adjacent, and the adjacencies appear in Router LSAs and Network


    >>role - DR,BDR,DRother
    ** DR/BDR election is not preempt (if high priority router goes down and if come back again its not back like STP root bridge election)

    >>LSA's stored in link state database
    then the dijkstra algarithm run against the contents of this database to create ospf routing table
    routers should have synchronized link state database

    >> Why DR/BDR
    The idea behind this is that routers have a central point of contact for information exchange. Instead of each router exchanging updates with every other router on the segment, every router exchanges information with the DR and BDR. The DR and BDR relay the information to everybody else. In mathematical terms, this cuts the information exchange from O(n*n) to O(n) where n is the number of routers on a multi-access segment


    >>when a router on ospf segment with DR & BDR detect a change in the network,
    -the router will not notify all of its neighbors
    -send a multicast to 224.0.0.6,the address to which both DR/BDR listen to learn about changes (only DR & BDR will receve changes)
    -the DR will then send a multicast to 224.0.0.5 to notify all non-DR and BDR routers of the change (01:00:5e:00:00:05)

    >>SPF timers
    router(config-router)#timers spf delayValue holddownValue

    There are two timers associated with controlling the triggering of an OSPF SPF calculation.
    1.The delay timer sets the amount of time to wait before running an SPF after receiving a database change.
    2.The holddown timer sets the minimum amount of time to wait between consecutive SPF runs. These timers support floating point values between 0.00 and 65535.00. 

    How the Age field works
    • Aging timer: Each LSA has its own aging timer that increments over time, starting from the time it was first generated.
    • Refresh process: To prevent LSAs from expiring and causing the database to become inconsistent, the originating router will, on average every 30 minutes (which is 1800 seconds, the default LSA refresh time), send a fresh copy of the LSA.
      • This new LSA has an age of zero and an incremented sequence number.
    • Flushing an LSA: If an LSA reaches its maximum age (default of 1 hour or 3600 seconds), it is considered stale and is "flushed" or removed from the database. This triggers the router to resend it with the age set to MaxAge so neighbors will then also flush it. 
    Yes, an LSA can have a lower age and a lower sequence number at the same time.
    But sequence number always takes priority over age.

    Link Flapping (Most Common) - Each flap causes:  New LSA ,Sequence number increments

    Can Sequence Number Decrease?

    No  It is monotonically increasing Until it reaches 0x7FFFFFFF

    What happens at max?

    LSA set to MaxAge (3600)  & LSA flushed & Sequence restarted at 0x80000001

    OSPF state machine Issue & reasons


    1. down - interface down,No hellos, subnet mismatch, passive, firewall
    2. init - Area mismatch , timer mismatch, authentication issues, unidirectional issue
    3. 2-way - normal in broadcast multiaccess topology
    4. exstart - MTU mismatch & duplicate RID
    5. exchange - MTU mismatch & corrupt DBD
    6. loading  - Missing LSU, packet drops, CPU/memory issue
    7. Full - final state

    note:
    MTU mismatch is checked multiple times because different OSPF packets have different sizes:
    DBD packets → checked in ExStart
    LSUs → checked in Loading
    A “successful” DBD exchange does not guarantee LSUs will succeed if the MTU is smaller than the LSA packets.


    OSPF Route selection process


    When an OSPF router receives information about the same destination prefix from two different neighbors, it uses a hierarchical process to determine the best path. The router doesn't just pick one neighbor's route immediately; it calculates all possible paths using the information in its link-state database (LSDB) and applies the Shortest Path First (SPF) algorithm, following specific tie-breaking rules.
    Here is how OSPF calculates and selects the best route:
    1. The Primary Criteria: Route Type Preference
    OSPF first categorizes the routes based on their LSA Type, prioritizing routes discovered within its own area over those from other areas or external sources, regardless of the cost at this stage. The general order of preference (from most preferred to least preferred) is: 
    • Intra-Area (O): Routes within the same OSPF area (learned via Type 1 and Type 2 LSAs).
    • Inter-Area (O IA): Routes in other areas of the same OSPF Autonomous System (learned via Type 3 LSAs).
    • External Type 1 (E1) / NSSA Type 1 (N1): Routes redistributed from other routing protocols where the external cost and internal OSPF cost are summed up. (The preference between N1 and E1 can vary by vendor implementation and RFC compatibility settings).
    • External Type 2 (E2) / NSSA Type 2 (N2): Routes where only the external cost is considered, and the internal cost to reach the Autonomous System Boundary Router (ASBR) is not added to the total metric.
    The router will always choose an Intra-Area route over an Inter-Area route, even if the Inter-Area route has a lower total cost. 
    2. The Secondary Criteria: Lowest Cost Metric
    If the router learns multiple paths to the same prefix that fall into the same LSA Type (e.g., two different Inter-Area paths), it then uses the OSPF metric (cost) to break the tie:
    • Lowest Cumulative Cost: The router calculates the total path cost (sum of all outgoing interface costs along the path) for each available route to the destination prefix. The path with the lowest total cost is selected as the best route. 
    3. The Tie-Breaker: Equal-Cost Multipath (ECMP)
    If the router finds multiple paths to the same prefix that have both the same LSA Type and the exact same cumulative cost, OSPF will install all of these paths into the routing table. This is known as Equal-Cost Multipath (ECMP), and the router will perform load balancing across these multiple next-hop neighbors. 
    Summary
    The router prioritizes the route based on a strict set of rules, starting with route type and then moving to metric. The LSA Age and Sequence Number are used to ensure the information used in these calculations is the most current and valid LSA available in the network

    Type-1 LSAs carry link cost; Type-3 and Type-5/7 carry accumulated metrics; Type-2 and Type-4 do not carry cost.

    Where Exactly Is the Cost Stored?

    Type-1 LSA (Router LSA)  MOST IMPORTANT
    Carries interface/link cost
    Generated by every router
    Each link entry includes: Link type, Link ID, Cost (metric)
    Primary source of OSPF path calculation
    Type-2 LSA (Network LSA)
    Generated by DR
    Represents a multi-access network
    Does NOT carry a cost
    All routers connected to the segment appear as neighbors
    Cost is assumed from Type-1 LSA of routers
    Type-3 LSA (Summary LSA)
    Generated by ABR
    Advertises routes between areas
    Carries an accumulated cost from ABR to destination
    Metric = intra-area cost + ABR cost
    Type-5 LSA (External LSA)
    Generated by ASBR
    Used for redistributed routes
    Carries:
    External metric
    Metric type:
    E1 (cost + internal cost)
    E2 (external cost only)

    Type-7 LSA (NSSA External)
    Same as Type-5 but inside NSSA
    Translated to Type-5 by ABR
    Carries external cost


    How reconvergence happens when interface goes down
    When an interface goes down, the router cannot send the update out of the interface that just failed. Instead, the router uses its remaining active interfaces to flood the invalidation message to its other neighbors.
    Here is how the updates are propagated:
    1. Detection of Failure: The router detects the administrative shutdown of an interface.
    2. LSA Generation (MaxAge=3600): The router creates a new LSA for the link that just failed, explicitly marking it as stale by setting its Age to the maximum value of 3600 seconds.
    3. Flooding via Active Interfaces: The router sends this updated LSA out of all its other operational OSPF interfaces. This is the OSPF flooding mechanism in action.
    4. Propagation: Neighboring routers receive this update via their interfaces connected to the functional parts of the network, immediately remove the stale entry from their databases, and propagate the update further until all routers in the area are synchronized with the new, correct topology.
           



    Area & LSA





    OSPF LAS Filtering

    In OSPF, you don’t filter LSAs freely — you design areas to control flooding.

    Type-3 LSA filtering (Inter-area routes)

    Only on ABRs - This is the most common and safest LSA filtering.


    Area 1 ---- R1 ---- Area 0 ---- R2

    Goal: Prevent 10.10.10.0/24 from Area 0 entering Area 1


    Step 1: Prefix list
    ip prefix-list BLOCK_NET seq 5 deny 10.10.10.0/24
    ip prefix-list BLOCK_NET seq 10 permit 0.0.0.0/0 le 32

    Step 2: Apply filter on ABR
    router ospf 1
    area 1 filter-list prefix BLOCK_NET in



     Area-type based filtering

    • Stub/ Totally stub /NSSA /NSSA no-summary

    This is implicit LSA filtering.


    Comments

    Popular posts from this blog

    gNMI_with_grafana on containerlabs

    EVPN Route type-1 & type-4 in action

    Network Automation with ROBOT Framework