Linux network traffic control tool-Netem
Article 1: Concepts
Netem is a network simulation function module provided by Linux 2.6 and later kernel versions. This function module can be used to simulate complex Internet transmission performance in a LAN with good performance, such as low bandwidth, transmission latency, and packet loss. Many released Linux versions that use the Linux 2.6 (or later) kernel have enabled this kernel function, such as Fedora, Ubuntu, Redhat, OpenSuse, CentOS, and Debian.
Tc is a tool in Linux. Its full name is traffic control (traffic control ). Tc can be used to control the working mode of netem. That is to say, if you want to use netem, you need at least two conditions, one is that the netem function in the kernel is included, and the other is that tc is required.
Article 2: Principles
TC is used to control traffic in Linux kernel. It is mainly used to control traffic by establishing a queue at the output port.
After receiving packets come in from the Input Interface, Ingress discarding does not conform to the specified data packet, which is determined by the Input multi-path distributor (Input De-Multiplexing: if the purpose of receiving a packet is the host, the packet is sent to the upper layer for processing; otherwise, the receiving packet must be forwarded to the Forwarding Block for processing. The forwarding block also receives packets generated by the upper layer of the host (such as TCP and UDP. The next hop of the processed package is determined by viewing the route table. Then, arrange the packages to send them to the Output Interface ). Generally, we can only limit the number of data packets sent by the network adapter, but not the number of data packets received by the Network Adapter. Therefore, we can control the transmission rate by changing the sending order. Linux traffic control is mainly implemented when the output interfaces are arranged.
Article 3: Application
The tool can complete the following functions: (fault simulation)
Simulate latency, packet loss, repeated packets, and out-of-order.
1. Simulate Delayed Transmission
# Tc qdisc add dev eth0 root netem delay 100 ms
This command sets the transmission latency of the eth0 Nic to 100 milliseconds.
In a more real situation, the latency value is not so accurate and there will be certain fluctuations. We can use the following situations to simulate the latencies with volatility:
# Tc qdisc add dev eth0 root netem delay 100 ms 10 ms
This command sets the transmission latency of the eth0 Nic to 100 ms + 10 ms (90 ~ Any value between 110 ms.
The randomness of such fluctuations can be further enhanced:
# Tc qdisc add dev eth0 root netem delay 100 ms 10 ms 30%
This command sets the eth0 Nic transmission to 100 ms. At the same time, about 30% of packets will be sent with a latency of ms.
2. Simulate packet loss
# Tc qdisc add dev eth0 root netemloss1 %
This command sets the eth0 Nic transmission to randomly discard 1% of the packets. You can also set the success rate of packet loss:
# Tc qdisc add dev eth0 root netemloss1 % 30%
This command sets the eth0 Nic transmission to randomly discard 1% of data packets, with a success rate of 30%.
3. Duplicate simulated packages
# Tc qdisc add dev eth0 root netemduplicate1 %
This command sets the eth0 Nic transmission to randomly generate 1% duplicate packets.
4. Damaged simulated package
# Tc qdisc add dev eth0 root netemcorrupt0.2 %
This command sets the transmission of the eth0 Nic to randomly generate 0.2% corrupted packets. (The kernel version must be later than 2.6.16)
5. Simulate unordered packets
# Tc qdisc change dev eth0 root netem delay 10 ms reorder 25% 50%
This command sets the eth0 Nic transmission to: 25% of packets (related to 50%) will be sent immediately, and the other delay is 10 seconds. In the new version, the following command will also disrupt the packet sending order to some extent: # tc qdisc add dev eth0 root netem delay 100 ms 10 ms
1. http://blog.csdn.net/wind0513/archive/2010/03/02/5339127.aspx
2, netem official description: http://www.linuxfoundation.org/collaborate/workgroups/networking/netem