Saturday, January 5, 2008

Understanding OSPF Routing


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). It is defined as OSPF Version 2 in RFC 2328 (1998) for IPv4. The updates for IPv6 are specified as OSPF Version 3 in RFC 5340 (2008). OSPF supports the Classless Inter-Domain Routing (CIDR) addressing model.

OSPF is a widely used IGP in large enterprise networks. IS-IS, another LSR-based protocol, is more common in large service provider networks.


  • How to become OSPF neighbor

OSPF Area ID
Subnet mask (used on the subnet) &
    Subnet number (as derived using the subnet mask and each router's interface IP address)
Hello and Dead interval
Value of the Stub area flag (type of area: two neighbors must be identical - either normal or stub area)
Must pass authentication checks (if used)

  • OSPF Neighbor States (LSDB Exchange) - DAI2EExLF


[Source: Cisco Community]

Down:
This is the first OSPF neighbor state. It means that no information (hellos) has been received from this neighbor, but hello packets can still be sent to the neighbor in this state.
During the fully adjacent neighbor state, if a router doesn't receive hello packet from a neighbor within the RouterDeadInterval time (RouterDeadInterval = 4*HelloInterval by default) or if the manually configured neighbor is being removed from the configuration, then the neighbor state changes from Full to Down.

Attempt:
This state is only valid for manually configured neighbors (by neighbor command) in an NBMA environment. In attempt state, the router sends unicast hello packets every poll interval to the neighbor, from which hellos have not been received within the dead interval.

Init:
This state specifies that the router has received a hello packet from its neighbor, but the receiving router's ID was not included in the hello packet. When a router receives a hello packet from a neighbor, it should list the sender's router ID in its hello packet as an acknowledgment that it received a valid hello packet.

2-Way:
This state designates that bi-directional communication has been established between two routers. Bi-directional means that each router has seen the other's hello packet. This state is attained when the router receiving the hello packet sees its own Router ID within the received hello packet's neighbor field. At this state, a router decides whether to become adjacent with this neighbor.

On broadcast media (Ethernet) and non-broadcast multiaccess networks (NBMA), a router becomes full only with the designated router (DR) and the backup designated router (BDR); it stays in the 2-way state with all other neighbors.
On Point-to-point and Point-to-multipoint networks, a router becomes full with all connected routers.

At the end of this stage, the DR and BDR for broadcast and non-broadcast multiacess networks (NBMA) are elected.

Note: Receiving a Database Descriptor (DBD) packet from a neighbor in the init state will also a cause a transition to 2-way state.

Exstart:
Once the DR and BDR are elected, the actual process of exchanging link state information can start between the routers and their DR and BDR.

In this state, the routers and their DR and BDR establish a master-slave relationship and choose the initial sequence number for adjacency formation. The router with the higher router ID becomes the master and starts the exchange, and as such, is the only router that can increment the sequence number.

Note that one would logically conclude that the DR/BDR with the highest router ID will become the master during this process of master-slave relation. Remember that the DR/BDR election might be purely by virtue of a higher priority configured on the router instead of highest router ID. Thus, it is possible that a DR plays the role of slave. And also note that master/slave election is on a per-neighbor basis.


Exchange:
In the exchange state, OSPF routers exchange database descriptor (DBD) packets. Database descriptors contain link-state advertisement (LSA) headers only and describe the contents of the entire link-state database.
Each DBD packet has a sequence number which can be incremented only by master which is explicitly acknowledged by slave.
Routers also send link-state request (LSR) packets and link-state update (LSU) packets (which contain the entire LSA) in this state.

Loading:
In this state, the actual exchange of link state information occurs. Based on the information provided by the DBDs, routers send link-state request (LSR) packets. The neighbor then provides the requested link-state information in link-state update (LSU) packets.
During the adjacency, if a router receives an outdated or missing LSA, it requests that LSA by sending a link-state request (LSR) packet. All link-state update packets are acknowledged.

Full:
In this state, routers are fully adjacent with each other. All the router and network LSAs are exchanged and the routers' databases are fully synchronized.

Full is the normal state for an OSPF router. If a router is stuck in another state, it is an indication that there are problems in forming adjacencies. The only exception to this is the 2-way state, which is normal in a broadcast network.
Routers achieve the FULL state with their DR and BDR in NBMA/broadcast media and FULL state with every neighbor in the remaining media such as point-to-point and point-to-multipoint.

Note: The DR and BDR that achieve FULL state with every router on the segment will display FULL/DROTHER when you enter the show ip ospf neighbor command on either a DR or BDR.
This simply means that the neighbor is not a DR or BDR, but since the router on which the command was entered is either a DR or BDR, this shows the neighbor as FULL/DROTHER.

  • OSPF Link State Advertisements

The Link-State Advertisements (LSAs) are used by routers running OSPF to exchange topology information. An LSA contains routing and topology information that describe a part of an OSPF network. Routers exchange LSAs and learn the complete topology of the network until all routers have the exact same topology database.

LSA Type 1: Router LSA (O)
Lists neighboring routers and the cost to each; flooded within an area.
Each router (all) will generate a router link for all of its interfaces.

LSA Type 2: Network LSA (O)
Generated by a DR; lists all routers on an adjacent segment; flooded within an area.

LSA Type 3: Summary LSA (IA)
Generated by an ABR into the backbone to advertise the presence of an ASBR within an area.

LSA Type 4: ASBR Summary LSA (IA)
Injected by an ABR into the backbone to advertise the presence of an ASBR within an area.

LSA Type 5: ASBR External LSA (E1/E2)
Generated by an ASBR and flooded throughout the AS to advertise a route external to OSPF.

LSA Type 6: Group Membership LSA

LSA Type 7: Not So Stubby Area (NSSA) External LSA
Generated by an ASBR in a not-so-stubby area; converted into a type 5 LSA by the ABR when leaving the area.

LSA Type 8: External Attributes LSA (OSPFv2) / Link Local LSA (OSPFv3)

Type 9~11 (Opaque LSAs are commonly used to support OSPF traffic engineering.)
LSA Type 9: Link Scope Opaque (OSPFv2) / Intra Area Prefix LSA (OSPFv3)

LSA Type 10: Area Scope Opaque LSA

LSA Type 11: AS Scope Opaque LSA

* Refer to OSPF LSA Types - Purpose and Function of Every OSPF LSA (Firewall.cx)


  • OSPF Network Types

The Hello and Dead timers must match to form a neighbor relationship in OSPF, even if the network type is different.
To configure the OSPF network type for an interface, use the ip ospf network command.
To change the hello interval, use the ip ospf hello-interval command.










  • OSPF Packet Types

Type Packet Name Protocol Function
1 Hello Discovers and maintains neighbors
2 Database Description (DBD, DDP) Summarize database contents
3 Link State Request (LSR) Database download
4 Link State Update (LSU) Database update
5 Link State Ack (LSAck) Flooding acknowledgement


* Recommended Resources and URLs
OSPF Cheat Sheets (PacketLife.net)

No comments: