Introduction to Networking

### Line Coding

The datagram is a part of the IPV4 Header. It represents the Header and payload size. Datagram of IPV4 is a 16-bit field, which is equal to 65535 bytes. IPV4 Datagram is the combination of header size and payload  (data). IPV4 Datagram will always be in the range of 20 bytes to 65535 bytes (216 bytes).

The minimum size of the header is 20 bytes or 160 bits, and a maximum of 60 bytes or 480 bits. The first five rows of the IPV4 header are mandatory, having a total size of 20 bytes.

Each row is of 4-byte. So, first five rows size will be 20 bytes which is minimum size of IPV4 header.

The minimum size of Payload  (Data) is 0 bytes and a maximum of 65515 bytes.

## IPv4 Datagram Header Size Calculations

• If the header size is 20 bytes (minimum) and the payload  is 0 bytes (minimum), then the datagram size = 20 bytes
• If the header size is 20 bytes (minimum) and the payload is 65515 (maximum), then the datagram size = 65535 bytes
• If the header size is 60 bytes, then the payload maximum value will be 65475 because 65475 + 60 bytes are equal to the maximum IPV4 datagram size, which is equal to 65535.

Note: If the header size is 60 bytes (maximum) and the payload is 65515 (maximum), then the datagram size = 65575 bytes. it cannot be represented by 16 bits field of a datagram.

The IPv4 Datagram Header diagram is given below

1. VERSION: The version of the IP protocol is of 4 bits. These 4 bits are always fixed as 0100 to represent 4 in decimal for IPv4.

2. HLEN: IV4P header length is 4 bits. The minimum value for this field is 5, and the maximum is 15 bytes.

• header length can be calculated by the following formula

Examples

If the header length field contains the decimal value 11 (represented in binary 1011) then Header length = 11 x 4 = 44 bytes

Note: So decimal range of 4-bits will becomes [5 -15] to represent header length [20-60]

3. Type Of Service: it is 8 8-bit field that is used for Quality of Service. The division of 8-bits is explained under

• Precedence (3 bits): The first 3 bits define the precedence. Precedence means priority, i.e., immediate, routine, etc. If a router is congested and needs to discard packets, it will discard packets having the lowest priority first. Bits values will be 0 or 1.
• Delay (1 bit): if we want a minimum delay in data packets, then this field will be 1; otherwise, it is 0. It is Mostly in video calling where there is no delay.
• Throughput (1 bit): If it needs high output, then its field bit will be 1; otherwise, it will be 0.
• Reliability (1 bit): if it needs high reliability, then its field bit will be 1. Otherwise, it is 0. It is used where no data loss is tolerated.
• Cost (1 bit): if it needs low cost, then its field bit will be 1 otherwise 0. It requires when to select the shortest path to its destination.
• The last bit is reserved for future purposes, which mostly controls the congestion Notification. Congestion means it informs the sender to minimize the speed of sending data.

4. Total Length: It is the Total length of the datagram. it is a 16-bit field that can represent 216 = 65536 value. It has a minimum size of 20 bytes and a max value of 65535 bytes. As we already discussed in the datagram topic, that

5. Identification

• It is a 16-bit field. It is helpful for the identification of the fragments of an original datagram.
• When an IP datagram is fragmented, each fragmented datagram is assigned the same identification header number.
• This header number is useful during the re-assembly of fragmented datagrams.

6. Flag Bits: It uses 3 flag bits

• The first flag bit is Reserved.
• Second Flag bit (DF Bit). DF bit stands for Do Not Fragment bit. DF value may be 0 or 1.

When the DF value is 0, then It gives permission to the intermediate devices (i.e., routers) to fragment the datagram if required.

When the DF value is 1, then It indicates the intermediate devices (i.e., router) not to fragment the datagram at any cost.

• The third flag bit is MF. MF bit stands for More Fragments bit. MF value may be 0 or 1.

When MF bit value is 0 then It tells to the receiver that the current datagram-fragment is the last fragment and no more segment will appear of same datagram.

When MF bit value is 1 then it tells more fragments are still to come after this fragment. MF bit is set to 1 for all the fragments except the last one.

7. Fragment Offset: Fragment Offset is a 13-bit field. It tells the position of a fragmented datagram in the original un-fragmented IP datagram.

Fragment offset for a given fragmented IP datagram = Number of data bytes ahead of it in the original un-fragmented IP datagram

Hence, The 1st fragmented datagram has a fragment offset of zero.

8. Time to live: It is an 8-bit field that prevents the datagram from going to loop. If a datagram goes to a loop, then congestion can happen, which causes the problem. So, Time to Live (TTL) is avoided in such stations.

According to TTL, 8-bit can represent 256 nodes. Therefore, datagram is self-loop can goes to 256 nodes, when datagram goes to a node, it is decremented by 1 in values. As the value reaches 0, the datagram is terminated.

9. Protocol: it is an 8-bit number that defines what protocol is used inside the IP packet. TCP, UDP, ICMP, or IGMP protocols can be filtered, although they are most common. The protocol number of ICMP is 1 (in binary 00000001), IGMP is 2 (in binary 00000010), TCP is 6, and UDP is 17.

10. Header Checksum: it is a 16-bit field. It is used for checking errors in the datagram header. At the receiving end, it is used to know whether the receiving data is corrupted or not because data can be lost or corrupted while passing through the network.