- The Internet Layer
- Internet Protocol
- Format of an IP Datagram
- Transmission of Datagrams
- Summary
Format of an IP Datagram
The format of data that can be recognized by IP is called an IP datagram. It consists of two components, namely, the header and data, which need to be transmitted. The fields in the datagram, except the data, have specific roles to perform in the transmission of data. Every field in the IP datagram has a fixed size except for the IP Options field, which can be 2060 bytes in length. The sending computer sends a message to the protocol in the same layer on the destination computer by using the header. The format of an IP datagram is displayed in Figure 3.3.
Figure 3.3 The fields in the IP datagram are used for transmitting data.
In the sections that follow, the fields in an IP datagram are discussed in detail.
Version
This field specifies the version of IP used for transferring data. The size of the Version field is 4 bits. Both the sender and the receiver must use the same version of IP to ensure proper interpretation of the fields in the datagram.
Header Length
The size of the Header Length or the IHL field is 4 bits. The Header Length field is used to specify the length of header, which can range from 20 to 60 bytes. You must multiply the value in this field by four to get the length of the IP header. For example, if the value in this field is 3, the length of the header is 3*4, which is 12 bytes.
Total Length
The Total Length field specifies the total length of the datagram. The size of the field is 16 bits. The Total Length field can be calculated as follows:
Total length of the datagram = Length of the header + Length of the data
If a datagram can be accommodated in a frame, data transmission becomes very simple. However, if the size of the datagram is more than the value that can be accommodated in the frame, the datagram must be divided into logical groups called fragments. In few cases, the size of a datagram will be much less than the size of the data that can be passed over the physical medium at one point in time. In that case, padding is done to fill in extra spaces. To find the exact length of the data that is sent over the frame, the Total Length field is used.
Service Type
The Service Type field is used to set priorities or precedence for data transmission. The size of the field is 8 bits. This field is also used to determine the type of service that is required for a particular application. The priority is set using the first three bits and the service type is set using the next three bits. The last two bits are reserved for future use. The Service Type field has two components, Precedence and Types of Service. In the sections that follow, the components of the Service Type field are explained in detail.
Precedence
The component of the Service Type field that is used to set priorities is called Precedence. This component is 3 bits long. Therefore, eight priority values ranging from 0 (000) to 7 (111) can be set. IP specifies the rules for deciding when a packet must be discarded. For example, if congestion occurs on the network, IP identifies the packets that need to be sent immediately and the packets that can be delayed depending on the priority assigned to the packet. If IP is not able to find an alternative, it can discard the packets. If data packets are discarded, ICMP generates an error message and sends it to the Transport layer. The Precedence field was created for programs that were created for the Department of Defense.
Types of Service
The Types of Service (ToS) component is used to determine the type of service that must be provided by the Internet layer depending on the type of application for which the data transfer needs to be done. The types of services that can be provided by IP are maximizing reliability and throughput and minimizing cost and delay. The size of the ToS component is 4 bits. The Transport layer provides the value of this field to the Internet layer. However, the values in these bits are just guidelines and not rules. The devices that operate from the Internet layer use these values to transfer data. The values that can be assigned to this component and a description of each value is provided in Table 3.1. For example, if the application is an Online Transaction Processing (OLTP) system, it will require the delay to be minimized and therefore the value would be 10002. However, in a situation where a bulk transfer of data is to be done, maximizing throughput will be appreciated and thus the value will be 01002.
NOTE
Throughput refers to the capacity of a network to transmit data and is measured by recording the total size of data that is transmitted over a network within a fixed time limit. This is also referred to as bandwidth.
Table 3.1 Values the Types of Service Component Can Take
Binary Value |
Description |
0000 |
Normal |
0001 |
Minimizing cost |
0010 |
Maximize reliability |
0100 |
Maximize throughput |
1000 |
Minimize delay |
NOTE
0000 is the default value of the Type of Service component.
NOTE
Only one of the ToS bits can be set at any point of time. A value, such as 11002 is invalid. Another important point to be noted is that the TOS bits will be meaningful only if the network devices through which a datagram is routed are programmed to support and provide a quality of service.
Time to Live
The Time to Live (TTL) field is used to specify the time for which a datagram must be retained on the network. This field is 8 bits long. TTL is measured in seconds. The TTL field can be used to improve the performance of a network because it is used to prevent the data packets from remaining indefinitely on the network. TTL values must be set according to the type of service that is required by the network and the speed of the network.
Consider a situation in which a datagram needs to be transmitted over a slow speed network. Considering the fact that the speed of the network is slow, the TTL value must be set to a higher value compared to the one that is set for transmitting the datagram over a high-speed network. If the TTL value is low, the datagram might not reach the intended recipient on time and might eventually be discarded. Another factor that influences the value of the TTL is the type of service that is required by the Application layer.
The TTL value is decremented by every router through which the data packet passes. The TTL value is measured in seconds. The routers decrement the value of the TTL field by 1 second. If the TTL value is 0 before the datagram reaches the destination, the datagram is discarded. After the datagram is discarded, ICMP sends an error message to the Transport layer protocols. The Transport layer then decides whether the data needs to be retransmitted.
Protocol
The Protocol field is used to specify the protocol used to create the data present in the Data field. The size of this field is 8 bits. The values that are assigned to the Protocol field are provided in Table 3.2. IP receives data from all the higher layer protocols. Each layer in the TCP/IP reference model adds information to the data that will be interpreted by the peer protocols to implement certain tasks. Thus, the data part of an IP datagram contains the original data that has to be sent in addition to the headers added by the higher layer protocols. When the datagram is received at the destination, the data needs to be redirected to the appropriate protocol that is operating in the higher layer. For example, IP can interact with TCP or UDP in the higher layers. The protocol plays an important role because messages can be interpreted only by the protocol that created them.
Table 3.2 Values the Protocol Component Can Take
Value (Decimal) |
Protocol |
1 |
Internet Control Message Protocol (ICMP) |
2 |
Internet Group Management Protocol (IGMP) |
3 |
Gateway-to-Gateway Protocol (GGP) |
4 |
Internet Protocol (IP) |
6 |
Transmission Control Protocol (TCP) |
8 |
Exterior Gateway Protocol (EGP) |
9 |
Interior Gateway Protocol (IGP) |
17 |
User Datagram Protocol (UDP) |
41 |
Internet Protocol Version 6 (IPv6) |
86 |
Dissimilar Gateway Protocol (DGP) |
88 |
Interior Gateway Routing Protocol (IGRP) |
89 |
Open Shortest Path First (OSPF) |
Source Address
The Source Address or the Source IP Address field is 32 bits long and is used to identify the sender of the data. This field is used to redirect error messages to the source in case the datagram is discarded before reaching the destination. The error messages are generated by an ICMP, which also operates from the Internet layer. The address that is specified in this field represents the originator of the message.
Destination Address
The Destination Address or the Destination IP Address field is 32 bits long. This field specifies the final destination of a data packet. However, this field does not provide information about the intermediate devices through which a data packet passes.
NOTE
The details of the intermediate paths that a datagram can take are stored in the local routing table.
To know more about routing tables, see "Routing Concepts," p. 260
Data
The Data field holds the data that needs to be transmitted over the network. The data part of the IP datagram also includes the header information that is sent by the higher layer protocols, such as TCP, HTTP, and so on.
Header Checksum
The Header Checksum field contains the checksum, which is used by the destination to check for the integrity of the transmitted data by applying an algorithm on the IP header. The size of this field is 16 bits. The Header Checksum value is calculated by the sender and is sent along with the IP header. The sender uses a specific algorithm for arriving at the checksum value. When the datagram reaches the destination, the checksum is calculated by the destination by using the same algorithm. If the value that is calculated is not equal to the specified Header Checksum value in the header of the datagram, the packet is discarded. The Header Checksum value is calculated only with the header values and not by using the data. Every intermediate device that receives the data must calculate the Header Checksum value before forwarding it.
NOTE
The Header Checksum value is not calculated based on the data because every intermediate device through which the datagram passes will require more time to calculate the Header Checksum for all the bits in the data part. Calculating the checksum based on data will also reduce the efficiency of the network because the datagrams will be held by the intermediate device for a long time.
NOTE
In addition, the data part of an IP datagram consists of headers created by the higher layer protocols. Performing the check on the data will mean that the intermediate devices must understand the data formats of other protocols and calculate the Header Checksum, which will bring down the performance.
To know more about the C/C++ programming structures implementing an IP datagram, see "Programming Structures For Data Formats," p. 447
Algorithm to Calculate the Header Checksum
The sender uses the following steps to calculate the Header Checksum:
The header part of the IP datagram is divided into sections of 16 bits each.
The values in the sections are added using the one's complement arithmetic. The sum is then complemented and the result forms the Header Checksum.
NOTE
When the Header Checksum is calculated at the sender's end, the value of the Header Checksum is taken as 0.
The following are the steps used by the receiver to check whether the Header Checksum is correct:
- The header part of the IP datagram that is received from the sender is divided into sections of 16 bits each.
NOTE
Normally, the size of each section that is created must be 16 bits.
- The data in all the sections are added using one's complement arithmetic. The sum obtained is complemented.
NOTE
At the receiving end, all the sections in the IP header are included, whereas at the sender's end the Header Checksum value is taken as 0.
- If the result is zero, it means that the data is intact and the packet is retained. Otherwise, it means that the data has undergone a change during the transmission and the packet is discarded.
For example, if the header is 48 bytes long, it will first be divided into different sections of 16 bits each. The values in all the sections are added together by using one's complement arithmetic.
NOTE
One's complement of a binary number can be found by inverting the bits in a binary number. Inversion refers to converting 0s to 1s and vice versa. On the other hand, One's complement arithmetic is a method that specifies the rules for adding two binary numbers. The rules specify that if two 1s are added, the result would be 0 and a carry of 1 would be generated. On the other hand, if three 1s are added, the result would be a 1 and a carry of 1 would be generated. If the addition of the numbers in the last column results in a carry, the sum must be added with 1 to obtain the result.
Calculation of the Header Checksum at the sender's might appear as:
1111 1110 1001 0110 --------------------------(Section 1) 1101 1111 1001 0001 -------------------------- (Section 2) 0000 0000 0000 0000 -------------------------- (Checksum)
Note that the value of the checksum section is taken as zero when the Header Checksum value is calculated at the sender's end. The sum of Section 1, Section 2, and Checksum is
11101 1110 0010 0111
As the sum that is derived has a carryover of 1, the sum is added to 1 once again.
11101 1110 0010 0111 ---------------------------- (Sum) 1
The Header Checksum calculated by the sender is
0010 0001 1101 0111
The Header Checksum at the receiver's end is calculated as:
1111 1110 1001 0110 --------------------------(Section 1) 1101 1111 1001 0001 ---------------------------(Section 2) 0010 0001 1101 0111 ---------------------------(Checksum)
The receiver takes the value of the checksum field from the IP header unlike the sender, which assumes the same to be 0. The sum of Section 1, Section 2, and Checksum is
11111 1111 1111 1110
The sum obtained has a carryover of 1; therefore, the sum is added to 1 once again.
11111 1111 1111 1110 -------------------------(Sum) 1
The result of the above operation is
1111 1111 1111 1111
As one's complement of the result, 1111 1111 1111 1111, is performed. If the value that is arrived at is 0, the data packet is retained. Otherwise, the data packet is rejected and an error message is reported to the source.
NOTE
The complement of a number is obtained by converting all 1s to 0s and vice versa.
An IP datagram has a few more fields that are used for fragmentation. These fields are discussed in the following section.