Emulation of the impact of global networks

    Usually articles are written in this blog where Linux appears to be user-friendly, the text below refers more likely to the section “Linux is not for everyone” and will be of interest to a much narrower circle of habrachitateli.

    Often there is a task to study the influence of delays, losses and jitter on the operation of a network application. A similar task is primarily faced by specialists who are involved in the development or implementation of VoIP solutions, network games, and streaming media content. With the widespread use of wireless data networks such as GPRS, CDMA, satellite communications systems, studies of the impact of data network parameters on application performance are becoming especially important.

    Consider a scheme with which you can simulate the effect of various parameters of a data network on the application under study. For modeling, it is very convenient to use the GNU / Linux operating system, in which all the necessary tools exist. The linux kernel includes the netem module, which provides functionality for emulating WANs. The current version of the module has the following functions:

    delay emulation, with a different distribution function,
    loss
    emulation, packet retry
    emulation, packet mixing
    emulation, packet distortion emulation

    This module is included by default in most modern distributions based on the kernel of the Linux 2.6 operating system (Fedora, OpenSuse, Gentoo, Debian, Mandriva, Ubuntu) and is controlled using the tc command from the iproute2 package. If your distribution does not include this module, then you can enable it yourself: To study the effect of transport network parameters on the application, it is easiest to use a dedicated computer that works according to the scheme shown in Fig. 1. On a dedicated computer, the ports are connected into an ethernet bridge, which allows transparently transfer packets from one interface to another and act as a switch. This solution is optimal, since now we can filter traffic, as well as change the required parameters of the transport stream.

    Networking -->
    Networking Options -->
    QoS and/or fair queuing -->
    Network emulator






    In order to configure the bridge, the bridge-utils package must be installed on the system. To create the proposed configuration, you need to create a bridge:

    #brctl add br0

    Add the necessary interfaces to it:

    #brctl addif br0 eth0
    #brctl addif br0 eth1

    Set the address on the br0 interface to access the computer over the network:

    #ifconfig br0 <адрес>

    After this, the ethernet frames coming to one interface will be sent to another. It is worth noting that forwarded packets pass through netfilter, so filtering traffic can be controlled using iptables at the network level and ebtables at the channel level of the OSI model.

    Packet Delay Emulation

    The simplest example is the addition of a root qdisc that emulates delay.

    # tc qdisc add dev eth1 root netem delay 800ms

    It is worth remembering that we can only control outgoing traffic, so this command in our scheme will set the delay of data that goes in the direction from server-client to 800ms. To make our scenario more realistic, you can add a standard deviation. In the future, we will change the root qdisc.

    # tc qdisc change dev eth0 root netem delay 800ms 100ms

    Now the delay will change with a deviation of 100ms.

    In the netem module, it is possible to specify an uneven delay distribution. For example, to specify a normal distribution function, you need to do the following:

    # tc qdisc change dev eth0 root netem delay 100ms 20ms distribution normal

    Other distribution tables (normal, pareto, paretonormal) are installed with iproute2 in the / usr / lib / tc directory. It will not be difficult to generate your own distribution table, which reflects the delays in the communication channel, based on experimental data.

    Emulation of packet flow changes

    Random packet loss is specified as a percentage.

    # tc qdisc change dev eth0 root netem loss 0.1%

    This will result in a loss of 1 out of 1000 packets. As an option, packet loss correlation can be added. This will cause the random number generator to be "less random." This can be used to emulate packet burst.

    # tc qdisc change dev eth0 root netem loss 0.5% 25%

    In this example, 0.5% of packets will be lost, and the probability of packet loss increases by a quarter if the previous one was lost.

    Duplication of packets is defined in the same way as loss.

    # tc qdisc change dev eth0 root netem duplicate 1%

    In newer kernels (2.6.16 and older), it is possible to add white noise to packets. This feature is specified as well as packet loss:

    # tc qdisc change dev eth0 root netem corrupt 0.1%

    Another situation that occurs in networks with delays is packet shuffling, when a previously sent packet arrives later than a packet sent after it. There are two mixing techniques in the netem module. The simplest is the gap method. This method mixes every Nth packet.

    # tc qdisc change dev eth0 root netem gap 5 delay 10ms

    In this example, every 5th packet will be sent immediately, while the rest will be delayed by 10ms. This will cause packets to arrive in a different order than how they were sent. This behavior is useful for simple debugging of the transport protocol.
    The following reoder method is much closer to real life. Using it, you can specify what percentage of packets can be mixed.

    # tc qdisc change dev eth0 root netem delay 10ms reorder 25% 50%

    In this example, 25% of packets (with a correlation of 50%) will be sent immediately, while the rest will be delayed by 10ms.

    The third possible mixing option.

    # tc qdisc change dev eth0 root netem delay 100ms 75ms

    If one packet receives a delay of 100ms, and the next packet sent 1ms later receives a delay of 50ms (100ms - 50ms jitter), then the second packet will be sent earlier.

    It is worth noting that to implement any of the methods you need to use a delay.

    The netem module is a discipline of traffic management, so it can be used in conjunction with other disciplines, such as TBF, CBQ, etc. You can also build chain of disciplines and apply various filters to them. In this example, we create the root discipline of priorities, attach the netem discipline to the third priority, and then add speed shaping.


    # tc qdisc add dev eth0 root handle 1: prio
    # tc qdisc add dev eth0 parent 1:3 handle 30: netem \
    delay 200ms 10ms distribution normal
    # tc qdisc add dev eth0 parent 30:1 tbf rate 20kbit buffer 1600 limit 3000
    # tc filter add dev eth0 protocol ip parent 1:0 prio 3 u32 \
    match ip dst 65.172.181.4/32 flowid 1:3




    As we can see, the Linux tools allow us to simulate any anomalies that may occur on the network. Thus, any system administrator can perform the necessary testing when deploying distributed services and introducing new protocols.

    Source used http://www.linux-foundation.org/en/Net:Netem

    Crosspost from my blog: m0sia.ru/node/67

    If you point out my mistakes, I will be grateful.

    Also popular now: