Kaigai Blog living abroad in my twenties

【My Study Note】IP Datagrams and Encapsulation

Infotech Networking

IP Datagrams and Encapsulation


Just like all the data packets at the Ethernet layer have a specific name, Ethernet frames, so do packets at the network layer. Under the IP protocol, a packet is usually referred to as an IP datagram.

The two primary sections of an IP datagram are the header and the payload. You’ll notice that an IP datagram header contains a lot more data than an Ethernet frame header does.

Version

The very first field is 4 bits and indicates what version of Internet protocol is being used. The most common version of IP is version four or IPv4. But Version six or IPv6 is rapidly seeing more widespread adoption.

Header Length

After the version field, we have the Header Length field. This is also a 4 bits field that declares how long the entire header is.

This is almost always 20 bytes in length when dealing with IPv4. In fact, 20 bytes is the minimum length of an IP header. You couldn’t fit all the data you need for a properly formatted IP header in any less space.

Service Type

These 8 bits can be used to specify details about the QoS (Quality of Service) technologies. The important takeaway about QoS is that there are services that allow routers to make decisions about which IP datagram may be more important than others.

Total Length

This is 16 bits and it’s used to indicate the total length of the IP datagram it’s attached to.

Identification

An identification field is a 16 bits number used to group messages together.

IP datagrams have a maximum size and you might already be able to figure out what that is. Since the Total Length field is 16 bits, and this field indicates the size of an individual datagram, the maximum size of a single datagram is the largest number you can represent with 16 bits: 65,535.

If the total amount of data that needs to be sent is larger than what can fit in a single datagram, the IP layer needs to split this data up into many individual packets. When this happens, the identification field is used so that the receiving end understands that every packet with the same value in that field is part of the same transmission.

Flag and Fragmentation Offset

The flag field and the Fragmentation Offset field are closely related fields.

The flag field is used to indicate if a datagram is allowed to be fragmented or to indicate that the datagram has already been fragmented.

Fragmentation is the process of taking a single IP datagram and splitting it up into several smaller datagrams. While most networks operate with similar settings in terms of what size an IP datagram is allowed to be, sometimes, this could be configured differently.

If a datagram has to cross from a network allowing a larger datagram size to one with a smaller datagram size, the datagram would have to be fragmented into smaller ones. The fragmentation offset field contains values used by the receiving end to take all the parts of a fragmented packet and put them back together in the correct order.

TTL (Time to Live)

TTL (Time to Live) field is an 8-bit field that indicates how many routers hops a datagram can traverse before it’s thrown away.

Every time a datagram reaches a new router, that router decrements the TTL field by one. Once this value reaches zero, a router knows it doesn’t have to forward the datagram any further.

The main purpose of this field is to make sure that when there’s a misconfiguration in routing that causes an endless loop, datagrams don’t spend all eternity trying to reach their destination.

An endless loop could be when router A thinks router B is the next hop, and router B thinks router A is the next hop.

この場合、AとBの間を無限に行き来することになってしまうから。

Protocol

This is another 8-bit field that contains data about what transport layer protocol is being used. The most common transport layer protocols are TCP and UDP.

Header Checksum

This field is a checksum of the contents of the entire IP datagram header. It functions very much like the Ethernet checksum field. Since the TTL field has to be recomputed at every router datagram touch, the checksum field necessarily changes, too.

The Source and Destination IP Address

After all of that, we finally get to two vital fields, the source, and destination IP address fields. Remember that an IP address is a 32 bits number, so it should come as no surprise that these fields are each 32 bits long.

IP options

The IP options field is an optional field and is used to set special characteristics for datagrams primarily used for testing purposes.

Padding

The IP options field is usually followed by a padding field. Since the IP options field is both optional and variable in length, the padding field is just a series of zeros used to ensure the header is the correct total size.

Encapsulation


The data payload section of an Ethernet frame is exactly what the IP datagram is, and this process is known as encapsulation. The entire contents of an IP datagram are encapsulated as the payload of an Ethernet frame.

Additionally, our IP datagram also has a payload section. The contents of this payload are the entirety of a TCP or UDP packet.