Shubho.dev logo
Network LAN Cable

OSPF Packet Formats

Here are my notes on OSPF Packet Formats.

I briefly wrote about OSPF yesterday. As we saw OSPF packets are encapsulated in the IP Packets with protocol number 89. However, how does OSPF establishes adjacency, and how does it exchanges the link-state database? The process is maybe part of another post. However, before we go into those details, we must first know the composition of OSPF packets. This will give us an insight of what information they carry and later we can put all these pieces together and get to know when and why each of these packet contents are used?

What are the various types of packets?

  1. Hello Packets
  2. Database Description (DBD) Packets
  3. Link State Request (LSR) Packets
  4. Link State Update (LSU) Packets
  5. Link State Acknowledgement (LSAck) Packets

Each OSPF packets have a common OSPF Header. Other than Hello Packets, all other packets are LSA related. Each such LSA packet type has a standard LSA header. The DBD, LSR and LSA packets carry only this header, while the LSU packets carry the entire LSA. In a future post, I will post my notes on various types of LSAs.

OSPF Packet Header

The OSPF Packet Header is of 24 bytes length. Each OSPF packet carries this. The header gives all information necessary that enables routers to know whether the packet should be processed further or not.

OSPF Packet Header
OSPF Packet Header

OSPF Packet Header

Version No – This field specifies the version number of OSPF. OSPFv2 is what is widely used. For IPv6, it is OSPFv3.

Type – This states the type of OSPF Packet. We have 1 (Hello), 2 (DBD), 3 (LSR), 4 (LSU) and 5 (LSAck).

Packet Length - This is the length of the complete OSPF Packet including the header.

Router ID - The Router ID of the source. Each router in an OSPF Domain must have a unique Router ID as described here. It is a 4 byte IP Address format.

Area ID - The area to which the packet belongs too. Each OSPF packet belongs to 1 area. A 4 byte IP Address format is used to denote it. For the backbone area packet, the area ID is 0.0.0.0 For other areas like area 1 it contains the value as 0.0.0.1 and so on.

Checksum - This is the standard IP checksum of the entire OSPF packet excluding the Authentication field. It is calculated as 16-bit one’s complement of all 16-bit words present. The packet needs to be padded with extra 0s at the end if the packet is not a multiple of 16-bit words.

Auth Type – The type of authentication done between the neighbors. Current values are 0 (null or no authentication), 1 (Plain text password), and 2 (cryptographic or MD5 hashing based password). IANA reserves all other values.

Authentication – This is a 64 bit (8 bytes) field and contains the actual authentication information if enabled.

For all the OSPF Packets described below, the above OSPF Header is always present. Only the extra distinct fields of the specific packet types are being mentioned below.

Hello Packets

Hello Packets are notified in the header by type 1. They are sent at periodic intervals (default 30 secs) over all the OSPF enabled interfaces. The purpose of these packets is for dynamic discovery of neighbors, establishing and maintaining neighborship. Routers in a common network negotiate few standard parameters. These parameter values are carried in the Hello Packets. The parameters are Network Mask, Hello interval, and Dead Interval.

OSPF Hello Packet Format
OSPF Hello Packet Format

OSPF Hello Packet Format

Network Mask - The network mask that is associated with the interface. This should match on both sides of a link for adjacency to come up.

Hello Interval – The time interval between successive hello packets sent by a router.

Options – The optional capabilities supported by the router. These are described at the end of this post.

Router Priority - This is the priority value of the router. This is used in case of DR-BDR election. If priority value is 0, then the router doesn’t take part in DR-BDR election.

Dead Interval - The number of seconds to wait before declaring a router as down. This starts when a router misses a Hello Message from its neighbor. By default, it is 3 times the Hello Interval.

Designated Router - The router ID of the DR as seen by the router. Initially, this is set to 0.0.0.0, and once it is elected, it changes this value.

Backup Designated Router - Same as above, this field specifies the router ID of the BDR.

Neighbor(s) – The router IDs of all the neighbors from whom a Hello Message has been received within the last Dead Interval seconds. This is a variable field, and initially, it contains no router IDs.

Database Description (DBD) Packets

The DBD packets are exchanged during the initialization of the adjacency. They are OSPF Packet Type 2. The master/slave mechanism is used for exchanging the DBD Packets. During the Exstart state of OSPF, an empty DBD packet is exchanged where the Master/Slave is elected per link and the initial sequence number to be used by the master is decided. During the Exchange state, the DBD packets contain the LSA headers and using these the routers make a list of LSAs that they are going to request from their neighbors.

OSPF Database Description Packet Format
OSPF Database Description Packet Format

OSPF Database Description Packet Format

Interface MTU - The maximum size of IP packets that can be sent over the link. This value should match on both the routers for the adjacency to come up.

Options - The optional capabilities that are explained below.

I Bit – The init bit which states that this is the first of the DBD packets.

M Bit - The more bit which states that there are more DBD packets after the current packet.

MS Bit – The Master/Slave bit. If it is set to 1, it implies that the router is a Master else the router is a slave.

DD Sequence Number - This is the sequence number for the DBD packets. The Master can only increment this, and the initial value is set when the I bit is set.

LSA Headers - The remaining field contains the list of LSA headers. This can be a partial list too, and hence multiple DBD packets are needed.

Link State Request (LSR) Packets

The LSR Packets are of OSPF Packet Type 3. Once the DBD packets are exchanged, each router checks the LSA Headers against its database, and if it finds it doesn’t have up to date information for any LSA, it creates the LSR packets and sends it to its neighbor asking for the updated LSAs. The LSA instance is defined by the LS sequence number, Checksum, and LS Age. However, the response to the LSR can be a more updated instance of the LSA.

OSPF Link State Request Packet Format
OSPF Link State Request Packet Format

OSPF Link State Request Packet Format

The LSR packets, however, do not contain the LSA instance-related fields but the LSA identification fields.

LS Type - The type of Link State being asked for.

Link State ID - Each LSA has an ID. This is mentioned in this field.

Advertising Router - The router that has originated the LSA.

There can be 1 or more LSA request fields in each LSR packet.

Link State Update (LSU) Packets

Link State Update (LSU) packets contain the actual complete LSAs. The various types of LSAs and their formats will be described in a later post. Each LSU packet contains a field that mentions the total number of LSAs contained in that packet. The LSU packets are OSPF Packet Type 4.

Link State Acknowledgement (LSAck) Packets

The LSAck packets help in reliable transmission of the LSAs. Each LSAs are explicitly acknowledged. The LSAck packets are OSPF Type 5, and they can contain acknowledgments for multiple LSAs. The LSA header is contained in the LSAck packet, and this suffices for the acknowledgment for the corresponding LSA.

The Options Field

The Options field is present in the Hello Packets, Database Description Packets, and in each LSAs. Each router uses the options field for advertising the capabilities it supports to all its neighbors. The options field in Hello Packets enables each router to reject adjacency request due to the capabilities mismatch. When used in the DBD packets, the Options field lets a router decide whether it has to forward an LSA or not due to its reduced capability. In LSAs, the Options helps routers by enabling it to take proper forwarding decisions by bypassing the LSAs with reduced capabilities.

Out of the 8 bits in the options field, the first, second, and eight bits are reserved and not used. The other bits from 3rd to the 7th bit in a sequence are:

DC Bit - This specifies the handling mechanisms for Demand Circuits.
EA Bit - This specifies that the routers can handle External Attributes LSAs.
N/P Bit - This is used for handling Type-7 LSAs which are used in case of NSSA areas.
MC Bit - This bit is used for handling Multicast Packets.
E Bit - This bit specifies how the AS External LSAs are flooded in the OSPF domain.

In later posts, we will see how some of the options are implemented and used. As I have mentioned before, a significant part of the packet formats are the LSA types.

Featured Image courtesy Jordan Harrison at Unsplash