What is the MTU

Maximum Transmission Unit (MTU).

What layer of network is this concept?

As you can see from the table below, MTU is the concept of data link layer in layer 7 network protocols. MTU limits the payload at the data link layer, which is the size of upper-layer protocols, such as IP addresses and ICMP.

Layer of the OSI function TCP/IP protocol family
The application layer File transfer, E-mail, file services, virtual terminals TFTP, HTTP, SNMP, FTP, SMTP, DNS, Telnet
The presentation layer Data formatting, code conversion, data encryption No agreement
The session layer To release or establish a connection with another contact No agreement
The transport layer Provide an end-to-end interface TCP, UDP
The network layer Select a route for the packet IP, ICMP, RIP, OSPF, BGP, IGMP
Data link layer Transmission of addressed frames and error detection SLIP, CSLIP, PPP, ARP, RARP, MTU
The physical layer The transmission of data over physical media as binary data ISO2110, IEEE802, IEEE802.2

What’s the use of MTU?

In the simplest scenario, you are at home surfing the Internet on your laptop, using a router that connects to the telecom network and then visits www.baidu.com. An Ethernet data frame from your laptop passes through the following routes:

Notebook -> Router -> Telecom room -> ServerCopy the code

Each node has an MTU value as follows:

Laptop -> Router -> Telecom room -> ServerCopy the code

Suppose I set the maximum MTU of my laptop to 1700 and then sent a large IP packet (2000). At this time, when transmitting on the external network, it would be split into two packets, one 1700 and one 300, and then add header information for transmission.

Laptop -> Router -> Telecom room -> ServerCopy the code

The router received a frame of 1700 and found that it was larger than the maximum value it had set: 1500, if the IP packet DF flag bit is 1, which is not allowed to subcontract, they put this package discarded router directly, don’t reach the telecom room, also can’t to the server, so here we shall find that MTU is actually in each node control value, as long as it is greater than the value of data frames, or fragmentation, Or just throw it away.

Why 1500?

In fact, a standard Ethernet data frame size is: 1518, the header information is 14 bytes, the tail checksum FCS is 4 bytes, so the real size for the upper layer protocol transmission is: 1518-14-4 = 1500, so where does the value 1518 come from?

Let’s say I take a larger value

If the MTU value is the same as the IP packet size, and the size of an IP packet is 65535, then the size of an Ethernet frame is 65535 + 14 + 4 = 65553, which seems perfect. The sender does not need to unpack and the receiver does not need to reassemble.

So let’s say our current bandwidth is: 100Mbps, because Ethernet frames are the smallest identifiable unit in transmission, and then the optical signal corresponding to 0101, we can only send one Ethernet frame at a time. If multiple frames are sent at the same time, the peer end will not be able to reassemble into a single Ethernet frame. At 100Mbps bandwidth (assuming no intermediate loss), let’s calculate the time required to send this frame:

(65553 * 8)/(100 * 1024 * 1024) ≈ 0.005(s)Copy the code

It takes 5ms to transmit a frame on a 100M network, which means no other process can send any data. If you dial an earlier phone and the network speed is only 2M:

(65553 * 8)/(2 * 1024 * 1024) ≈ 0.100(s)Copy the code

100ms, this is a nightmare. In fact, this is like a traffic light, the time to set a reasonable, alternate traffic, otherwise the same direction if the green light has been, then the other direction will be blocked into xiang.

Since it’s not ok to make it bigger, is it ok to make it smaller?

Assuming the MTU value is set to 100, the time for a single frame to be transmitted at 2Mbps bandwidth requires:

(100 * 8)/(2 * 1024 * 1024) * 1000 ≈ 5(ms)Copy the code

No matter what the MTU is set to, the size of the Ethernet header frame and the end frame is fixed, 14 + 4. Therefore, when the MTU is 100, the transmission efficiency of an Ethernet frame is:

(100-14-4) / 100 = 82%Copy the code

The formula is: (t-14-4)/T, when T tends to infinity, the transmission efficiency is close to 100%, that is, the larger the MTU value is, the highest transmission efficiency, but based on the transmission time of the previous point, let’s compromise, since the head plus the tail is 18, let’s make a whole 1500, the total size is 1518, transmission efficiency:

1500/1518 = 98.8%Copy the code

100Mbps Transmission time:

(1518 * 8)/(100 * 1024 * 1024) * 1000 = 0.11(ms)Copy the code

2Mbps Transmission time:

(1518 * 8)/(2 * 1024 * 1024) * 1000 = 5.79(ms)Copy the code

Overall the time is acceptable

The minimum is limited to 64

Why 64?

This is actually related to the collision of Ethernet frames in half duplex, interested students can search by themselves.

Why did I change the MTU to 1480 when I was playing the game?

The default value of most routers is 1500, theoretically there is no problem, so why can I change it to 1480 when playing the game? The reason is that I was using ADSL Internet access, ADSL using PPPoE protocol.

PPPoE

PPPoE is between Ethernet and IP. The PPPoE Protocol is divided into two parts: Point to Point Protocol (PPP) and Over Ethernet (oE). The PPPoE header is as follows:

| VER(4bit) | TYPE(4bit) | CODE(8bit) | SESSION-ID(16bit) | LENGTH(16bit) |
Copy the code

So we have 48 bits, which is 6 bytes, so what are the other 2 bytes? The ANSWER is the PPP ID, which occupies two bytes. Therefore, in the PPPoE environment, the optimal MTU value should be: 1500-6-2 = 1492.

The way I surf the Internet

My Internet access was as follows:

PC -> Router -> TelecomCopy the code

I dial up from the router, and then the PC connects to the router for Internet access.

Root cause

For router dial-up, the PC encapsulates Ethernet frames according to MTU:1492. Even if the packets pass the router, the router only forwards the packets without unpacking them.

When dial-up with the router, the PC does not know the communication mode of the router and encapsulates Ethernet frames with the MTU of 1500 by default set by the network card. When it arrives at the router, the router needs to encapsulate PPPoE and add 8-byte header information. In this way, the packet must be unpacked. The router split this frame into two frames, one frame is 1492 and the other frame is 8, and then added the PPPoE header to each frame.

Usually there is no card when playing games, because the router can still process the amount of data, and when carrying out AOE for group monsters, because the amount of data in a short time is too large, the router can not process it, there will be packet loss and delay, and it will be disconnected.

The 1480 mentioned in the post may be set as small as possible to avoid another PPPoE encapsulation caused by the second dial-up, because the time is long, there is no way to go back to the scene at that time to capture packets.

conclusion

The value 1518 is a compromise value for transmission efficiency and transmission time. In addition, because there are too many nodes in the current network link, if the MTU value of one node is different from that of other nodes, it is easy to cause the problem of packet unpacking and reassembly, or even failure to send.