zoukankan      html  css  js  c++  java
  • linux 下使用 tc 模拟网络延迟和丢包-使用 linux 模拟广域网延迟

    tc 是linux 内置的命令;使用man pages 查看 我们看到,其功能为 show / manipulate traffic control settings,可对操作系统进行流量控制;

    netem 与 tc:

    netem 是 Linux 2.6 及以上内核版本提供的一个网络模拟功能模块。该功能模块可以用来在性能良好的局域网中,模拟出复杂的互联网传输性能,诸如低带宽、传输延迟、丢包等等情况。使用 Linux 2.6 (或以上) 版本内核的很多发行版 Linux 都开启了该内核功能,比如 Fedora、Ubuntu、Redhat、OpenSuse、CentOS、Debian 等等。 tc 是Linux 系统中的一个工具,全名为 traffic control(流量控制)。tc 可以用来控制 netem 的工作模式,也就是说,如果想使用 netem ,需要至少两个条件,一个是内核中的 netem 功能被包含,另一个是要有 tc 。

    需要注意的是:本文介绍的流控只能控制发包动作,不能控制收包动作,同时,它直接对物理接口生效,如果控制了物理的 eth0,那么逻辑网卡(比如 eth0:1)也会受到影响,反之,如果您在逻辑网卡上做控制,该控制可能是无效的。(注:虚拟机中的多个网卡可以在虚拟机中视为多个物理网卡)。

    DESCRIPTION
           NetEm  is  an  enhancement  of the Linux traffic control facilities that allow to add delay, packet loss,
           duplication and more other characteristics to packets outgoing from a selected network  interface.  NetEm
           is built using the existing Quality Of Service (QOS) and Differentiated Services (diffserv) facilities in
           the Linux kernel.

    Linux下用tc控制网络延时和丢包率:

    tc修改网络延时:
    
    sudo tc qdisc add dev eth0 root netem delay 1000ms
    
    删除策略:
    
    sudo tc qdisc del dev eth0 root netem delay 1000ms
    
    修改丢包率:
    sudo tc qdisc add dev eth0 root netem loss 10%
    
    删除策略:
    sudo tc qdisc del dev eth0 root netem loss 10%

    配置确认:
    sudo tc qdisc show dev enp2s0

    配置删除:
    sudo tc qdisc del dev enp2s0 root
    NetEm (already enabled in the Linux kernel) provides Network Emulation functionality for testing protocols by emulating the properties of wide area networks. 
    
    To simulate an additional latency of 80 ms, just type sudo tc qdisc add dev eth0 root netem delay 80ms 
    It just adds a fixed amount of delay to all packets going out of the local Ethernet. 
    
    To stop the additional latency, just type sudo tc qdisc change dev eth0 root netem delay 0ms 
    
    Lines to add to the file /etc/rc.local before exit 0, to add 40ms of latency :
    
    # Add +40ms latency tc qdisc add dev eth0 root netem delay 40ms
    
    Note: If your network interface is not eth0, replace eth0 with the name of your network interface
    NetEm相关

    在调研 iperf 的时候,偶然看到。对项目很有帮助。

    原文链接:https://iperf.fr/iperf-servers.php#netem 

    扩展阅读:https://www.cnblogs.com/Dev0ps/p/8985778.html 

    https://blog.csdn.net/huuinn/article/details/80970079 

    https://wiki.linuxfoundation.org/networking/netem 

    https://wiki.linuxfoundation.org/networking/netem#emulating_wide_area_network_delays (更多万维网模拟相关) 

    tc 高级用法:

    延迟有波动并成正态分布趋势:

    tc qdisc add dev eth0 root netem delay 100ms 20ms distribution normal
     
  • 相关阅读:
    spring注解方式AOP
    struts2 值栈的理解
    JAVA自定义注解
    JS学习随笔。
    使用Jsoup解析html网页
    Struts迭代器(iterator)遍历List常用的4种例子
    Maven 结合 Spring profile对不同的部署环境打包部署
    打印插件LODOP使用介绍
    Linux下查看CPU信息、机器型号等硬件信息
    验证码的生成和验证
  • 原文地址:https://www.cnblogs.com/xuyaowen/p/netem.html
Copyright © 2011-2022 走看看