The maximum packet size of a TCP connection——Maximum Packet Size for a TCP Connection

1 Introduction

Transmission Control Protocol (TCP) is a useful protocol for sending files or messages over a connected network. Each file is split into packets on the sending network. Packets are coalesced when they reach the receiving network. The maximum size of a TCP packet is 64K (65535 bytes ). Typically, the packet size is limited by the Maximum Transmission Unit (MTU) of the network resource. The MTU is the maximum size of the data transfer limit set by the network hardware. The packet size should not exceed the MTU. In this tutorial, we will try to explain the concepts behind these terms and explore various aspects of them.

2 TCP connections

A TCP connection uses TCP, one of the core protocols in the Internet protocol suite that provides a reliable digital communication protocol. TCP receives messages from network resources (such as servers, routers, switches), splits them into packets, and forwards them to the destination network resource. Almost all connections involving the internet use TCP connections. We'll explain more about how packets work in a later section. Let us understand TCP communication by taking email communication as an example:

 We can see from the figure above that an email is processed through the seven layers of the OSI model. Each tier of the source server communicates with the corresponding tier of the target server.

  • Application Layer : When we send an email, the email client communicates with the email server using the SMTP protocol.
  • The presentation layer converts our mail to ASCII and images.
  • The session layer establishes and maintains a connection with the target server.
  • The transport layer splits the message into packets and adds the source and destination server port information.
  • The network layer defines the routing path of the data packets by adding the corresponding IP address. Interestingly, even though each packet is destined for the same destination, they may take different routing paths.
  • Data Link Layer Prepares packets for transmission on Ethernet
  • The physical layer ultimately transmits frames over a physical connection such as LAN cable, WiFi, or broadband.

The following diagram explains the above process:

 

When the packet reaches the physical layer of the destination network (Host2 in the diagram above), each layer of the destination email server processes the packet to retrieve the data and display our email in the destination inbox.

3 Frames and packets

Digital data exchange within computer networks uses frames and packets. The key difference between frame and packet is that a frame is a serial collection of bits whereas a packet is segmented data encapsulated in a frame. A packet is a single unit of data within the network layer in the OSI model. Each packet usually consists of a header and a payload. The header has the ports and IP addresses of the source and destination network devices. Data or message content is the payload. For example, when we transfer an image file, the file is split into several packets. These packets contain parts of the image, transmitted separately. The receiving network device reconnects these packets to reconstruct the image file. Finally, they merge to retrieve the same image file:

 Packets contain information to direct them to their destination and to check for transmission errors and data integrity . Efficiently segmenting data helps networks manage different network parameters such as bandwidth, routing, and device connectivity.

4 Why does packet size matter?

The packet loss rate depends on the packet size. The larger the packet, the higher the chance of loss .

Packet size has different effects on communication network parameters such as packet loss rate and throughput.

We have to keep packet size below MTU for better TCP connection performance.

The maximum packet size should be between 1500 bytes (broadband) and 576 bytes (dial-up). The router can obtain the MTU of the target connection from the interface configuration information.

4.1. Advantages

The advantages of packet-based TCP communication are as follows:

  • Effective use of network bandwidth.
  • Use variable packet sizes according to communication standards.
  • Each packet is transmitted independently according to the best network route.
  • A dedicated channel is not required to route packets, but any network path available to reach the destination network is used.
  • Configure the packet size using the capabilities of your operating system.
  • Small packet size can provide better network latency

4.2. Disadvantages The disadvantages of packet-based TCP connections are as follows:

  • Configuring packet size higher than MTU may cause jitter.
  • Small packet sizes may result in slow transfers.
  • Performance is affected when the maximum packet size exceeds the physical MTU of the network.

A packet cannot be fragmented while the Do Not Fragment (DF) flag is active. If the DF state is inactive, the router can split a packet into multiple fragments. The target device can reconnect these fragments later. It will return unfragmented packets to the source network. Pv6: The router cannot fragment the packet and return it to the source network.

5 Fragmentation of packets under different MTU

Suppose a source device communicating using TCP sends an IP packet over the network. This packet size must be smaller than the MTU of the destination and intermediate networks . This limit is determined by the network data link layer and the hardware MTU. So what happens if the packet is larger than the MTU of the intermediate network or destination device?

The answer is to split that packet further in half, a process called fragmentation . The individual pieces are fragmented and then reconnected at the destination network to retrieve the full packet. However, depending on the type of IP protocol, such as IPv4 and IPv6, the following may occur:

  • IPv4: Packets cannot be fragmented when the Do Not Fragment (DF) flag is active. If the DF state is inactive, the router can split a packet into multiple fragments. The target device can reconnect these fragments later. It will return unfragmented packets to the source network.
  • Pv6: The router cannot fragment the packet and return it to the source network.

Let's see how sharding works. The diagram below shows a source data link or MTU of 1500 bytes and a destination MTU of 1200 bytes. Considering that fragmentation is allowed, a 1400 byte packet is split into 1200 bytes and 200 bytes:

What happens to the original packet during fragmentation?

They are discarded and the data in them is fragmented.

5.1. Advantages

  1. reduce overhead
  2. No overhead of Path MTU Discovery (PMTUD) is required.

5.2. Disadvantages

  1. The loss of a fragment may require resending the packet and restarting fragmentation.
  2. Only the first fragment contains the header, which can cause problems with devices that rely on checking the header.
  3. Fragments may need to be reordered, especially if only a few packets are fragmented.

6. The importance of MTU

MTU is a unit that represents the maximum size of a data packet that a network resource can effectively accept. It is the most important parameter that other networks must know when establishing a TCP connection. A larger MTU allows more data to be transmitted in fewer packets, improving transfer speed and performance. However, if a communication error occurs, packets take longer to retransmit. A smaller MTU improves network latency.

7 Conclusion

This article describes the maximum packet size for TCP connections. First, we discussed the concept of packet size. Then we talked about the importance of knowing the packet size. Information about the packet size of a TCP connection is helpful in understanding TCP connection performance. In summary, the source network must ensure that the packet size does not exceed the MTU of the destination network.

 

Guess you like

Origin blog.csdn.net/usstmiracle/article/details/132228616