In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces how to simulate the weak network environment in linux. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
In the process of operation and maintenance, the most complex problem is the problem of the network, and the most annoying problem of the network is that it can not be repeated. This article introduces a powerful network simulation tool, Netem.
Netem is a network simulation function module provided from the kernel version of linux 2.6. it is mainly used to simulate complex network transmission performance in a good network environment, such as low bandwidth, transmission delay, packet loss and other common network failures.
And Netem is controlled by the command line tool tc, tc we should be familiar with, tc is part of the iproute2 toolkit, its full name is traffic control (flow control), the most commonly used is to bounce shell through nc snooping.
Tc is mainly used for the flow control of the linux kernel, mainly by establishing a queue at the output port to achieve flow control. After the receiving packet comes in from the input interface, the data packet that does not conform to the specification is discarded after the flow limit, which is judged and selected by the input demultiplexer. If the purpose of the receiving packet is the local host, then the packet is sent to the upper layer for processing, otherwise it needs to be forwarded and handed over to the forwarding block for processing. The forwarding block also receives packets generated by the local upper layer (TCP, UDP, etc.). The forwarding block determines the next hop of the packets processed by looking at the routing table, and then arranges the packets to send them to the output interface. generally speaking, we can only limit the packets sent by the network card, but not the packets received by the network card, so we can control the transmission rate by changing the sending order. Linux flow control is mainly processed and implemented when the output interfaces are arranged.
With regard to linux internal network packet forwarding, there is a more detailed introduction in the article "where is nfstable better than iptables" sent before the official account, so you can click in and have a look at it if you are interested.
Back to the point, we mainly use the tc tool and Netem module to simulate the network condition, and take a look at the powerful function of the netem module.
Poor network conditions are usually shown as follows: delay, packet loss, disorder, repetition, errors, etc. We use netem to simulate these situations. It is recommended that you do not test the production environment and use it after you have mastered it.
In the operation of tc configuring netem, there are four main control parameters, namely add (indicating adding Netem configuration for the specified Nic), change (indicating modifying the existing Netem configuration), replace (indicating replacing the value of the existing Netem configuration), and del (indicating deleting the Netem configuration on the Nic). OK, and then start testing several situations.
Analog delayed transmission tc qdisc add dev eth0 root netem daly 100ms
Analog network, all messages delay 100ms transmission
In the above command, qdisc is a queuing rule. Before adding a rule, because it is a private network, ping delay is in 1ms. After adding delay, it is increased to 100ms.
In a real network environment, it is usually difficult to see a very stable delay and private network, so netem also takes this into account. The simulation delay parameters provide optional parameters to control the time distribution of the delay. The complete list of parameters is as follows:
As you can see, there are three optional parameters in addition to TIME:
JITTTER: network jitter, increasing the length of a random event to allow delayed events to occur in a certain range
CORRELATION: correlation coefficient, the correlation coefficient between the next message delay event and the previous message
Distribution: delay distribution. Optional values are uniform, normal, pareto, and paretonormal
Let's first take a look at JITTER. If it is set to 10ms, then the message delay event will be randomly selected between 100ms ±10ms. See the effect.
CORRELATION refers to the correlation between packets and packets, because the network condition changes smoothly, and the delay of adjacent messages in a short period of time should be similar, not completely random. This value is a percentage. If it is 100%, it is the case of fixed delay. If it is 0%, it is random delay. Then the configuration just now continues to see the effect.
On the other hand, distribution simulates the real network by means of normal distribution, and its parameters are several delay distribution methods. If you are interested, you can try it.
Simulated packet loss rate
Packet loss is the most common situation in the network. Packet loss will lead to retransmission, which will increase the traffic and delay of the network link. Netem provides loss parameters to simulate the packet loss rate.
Tc qdisc add dev eth0 root netem loss 50%
Let's see the effect.
Similar to delay, the packet loss rate has a parameter of correlation coefficient that can be set to indicate the correlation between the packet loss rate of the latter packet and its previous message.
Tc qdisc add dev eth0 root netem loss 50% 25%
The above command indicates that the packet loss rate is 50%, and the probability that the current message is discarded is 25% related to the previous message.
Simulation packet repetition
Simulation message repetition, using the duplicate parameter, the parameters of message repetition and packet loss are similar, that is, repetition rate and correlation, such as randomly generating 50% duplicated packets.
Tc qdisc add dev eth0 root netem duplicate 50%
Let's see the effect.
Correlation, like other parameters, can be tested if you are interested.
Simulated package damage
The parameter corrupt is used to simulate message damage, and the parameters of message damage and message duplication are also similar, such as randomly generating 30% damaged messages.
Tc qdisc add dev eth0 root netem corrupt 30%
View the effect
As can be seen from icmp_seq, corrupted messages lead to serious packet loss
Simulated packet disorder
We know that in order to ensure reliable transmission, TCP will add a sequence number to the message to ensure that the split packet can be reorganized after arrival, then the best case is that the packet can be transmitted in order to reduce the number of reordering. Although the impact of packet disorder is not as serious as the above, it is still often encountered. Netem also provides a method to simulate packet disorder.
Simulated message disorder is different from the previous parameters. The above operations are all for a single message, while disorder involves the reorganization of multiple messages, so there are two methods for Netem to simulate disorder.
The first is a fixed number of messages out of order every other time.
Tc qdisc add dev eth0 root netem reorder 50% gap 3 delay 100ms
The above one is sent normally every 3 packets, and the other packets delay sending by 100ms.
The second method is closer to the display, that is, random, using probability to select disordered messages.
Tc qdisc change dev eth0 root netem reorder 50% 15% delay 300ms
Look at the effect.
The above is that 50% of the messages are sent normally, and the other messages are delayed by 300ms.
View configured filter criteria
During the test, you definitely need to check which conditions are currently configured, which can be viewed through the show instruction of tc.
For the simulation of weak network environment, troubleshooting, this tool is essential, quickly collect!
On how to achieve the simulation of weak network environment in linux to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.