AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 523600
Accepted
JenyaKh
JenyaKh
Asked: 2019-06-08 10:11:32 +0800 CST2019-06-08 10:11:32 +0800 CST 2019-06-08 10:11:32 +0800 CST

在 tcpdump 记录中未看到 Tc qdisc 延迟

  • 772

我有两个用 veth 对连接的 linux 容器。在一个容器的 veth-interface 上,我设置了 tc qdisc netem 延迟并将流量从它发送到另一个容器。如果我使用 tcpdump/wireshark 观察双方的流量,可以看出发送方和接收方的同一数据包的时间戳不会因所选延迟而有所不同。

我想更详细地了解 libpcap 将时间戳放入对应于 tc qdisc 的出口流量。我在互联网上搜索了一个方案/图像,但没有找到。我找到了这个主题(wireshark 数据包捕获点),但它建议通过多一个容器/接口来引入间接性。在我的情况下,这不是一个可能的解决方案。有没有什么方法可以解决这个问题,而不是引入额外的中间接口(即不改变拓扑),并且只通过在已经给定的 veth-interface 上记录但以可以看到延迟的方式来解决这个问题?

更新:

我太快了,所以弄错了。我的解决方案(与@AB 的答案的第一个变体相同)和@AB 的 IFB 解决方案(我已经检查过)都不能解决我的问题。a1-eth0问题是拓扑中发送方接口的传输队列溢出:

[a1-br0 ---3Gbps---a1-eth0]---100Mbps---r1---100Mbps---r2

我太快了,只检查了a1-eth0和 router之间链接的延迟 10ms r1。今天我试图让延迟更高:100 毫秒、200 毫秒,结果(我得到的每个数据包延迟和速率图)对于上面的拓扑和普通拓扑开始有所不同:

[a1-eth0]---100Mbps---r1---100Mbps---r2

所以不,当然,对于准确的测试,我不能有额外的链接:Linux 桥、这个 IFB 和任何其他第三方系统都没有引入。我测试拥塞控制方案。我想在一个特定的拓扑中做到这一点。而且我不能仅仅为了绘图而改变拓扑——我的意思是,如果我的速率和延迟结果/图同时发生变化。

更新 2:

所以看起来解决方案已经找到了,如下图所示(NFLOG解决方案)。

更新 3:

这里描述了 NFLOG 解决方案的一些缺点(大的 Link-Layer 标头和错误的 TCP 校验和,用于零负载的出口 TCP 数据包),并提出了一个更好的解决方案,使用 NFQUEUE 没有任何这些问题:零长度出口数据包的 TCP 校验和错误(使用 iptables 捕获)。然而,对于我的任务(测试拥塞控制方案),NFLOG 和 NFQUEUE 都不适合。正如同一个链接所解释的,当从内核的 iptables 捕获数据包时,发送速率会受到限制(这就是我的理解)。因此,当您通过从接口捕获(即定期)在发送方进行记录时,您将获得 2 GB 转储,而如果您通过从 iptables 捕获在发送方进行记录,您将获得 1 GB 转储。大致说来。

更新 4:

最后,在我的项目中,我使用了我自己的答案中描述的 Linux 桥接解决方案。

networking tcpdump
  • 2 2 个回答
  • 1415 Views

2 个回答

  • Voted
  1. Best Answer
    A.B
    2019-06-29T01:15:27+08:002019-06-29T01:15:27+08:00

    根据Netfilter 和 General Networking示意图中的数据包流,tcpdump在egress ( qdisc ) 之后捕获 ( AF_PACKET ) 。所以在 tcpdump 中看不到延迟是正常的:延迟在初始捕获时已经存在。

    您必须提前一步捕获它,因此涉及第三个系统:

    S1:system1,在传出接口上运行 tcpdump
    R:路由器(或网桥,在您方便时,这不会改变任何内容),运行 qdisc netem
    S2:system2,在传入接口上运行 tcpdump

     __________________     ________________     __________________
    |                  |   |                |   |                  |
    | (S1) -- tcpdump -+---+- (R) -- netem -+---+- tcpdump -- (S2) |
    |__________________|   |________________|   |__________________|
    

    这意味着涉及 3 个网络堆栈,它们是真实的、vm、网络命名空间(包括ip netns、LXC、...)


    或者,也可以通过使用带有镜像流量的 IFB 接口来欺骗和移动路由器(或网桥)上的每个特殊设置:允许通过一个技巧(专用于这种情况)插入 netem 排序后的入口而不是 on出口:

     _______     ______________________________________________     _______
    |       |   |                                              |   |       |         
    | (S1) -+---+- tcpdump -- ifb0 -- netem -- (R) -- tcpdump -+---+- (S2) |
    |_______|   |______________________________________________|   |_______|
    

    tc mirred 手册页中有一个基本的 IFB 用法示例:

    使用 ifb 接口,可以通过 sfq 的实例发送入口流量:

    # modprobe ifb
    # ip link set ifb0 up
    # tc qdisc add dev ifb0 root sfq
    # tc qdisc add dev eth0 handle ffff: ingress
    # tc filter add dev eth0 parent ffff: u32 \
      match u32 0 0 \
      action mirred egress redirect dev ifb0
    

    只需在ifb0上使用 netem 而不是 sfq (在非初始网络命名空间中,ip link add name ifbX type ifb工作正常,没有 modprobe)。

    这仍然需要 3 个网络堆栈才能正常工作。


    使用NFLOG

    根据 JenyaKh 的建议,事实证明可以使用tcpdump在出口之前(因此在 qdisc 之前)然后在出口(在 qdisc 之后)捕获数据包:通过使用iptables(或nftables)将完整数据包记录到 netlink 日志基础设施,并且仍然使用tcpdump读取它们,然后在出口接口上再次使用tcpdump 。这仅需要 S1 上的设置(不再需要路由器/网桥)。

    因此,在 S1 上使用iptables,类似于:

    iptables -A OUTPUT -o eth0 -j NFLOG --nflog-group 1
    

    应该添加特定的过滤器以匹配完成的测试,因为tcpdump过滤器在 nflog 接口上受到限制(wireshark 应该更好地处理它)。

    如果需要捕获答案(此处在不同的组中完成,因此需要额外的tcpdump):

    iptables -A INPUT -i eth0 -j NFLOG --nflog-group 2
    

    根据需要,也可以将它们移至raw/OUTPUT和raw/PREROUTING。

    使用tcpdump:

    # tcpdump -i nflog:1 -n -tt ...
    

    如果使用不同的组 (= 2) 进行输入:

    # tcpdump -i nflog:2 -n -tt ...
    

    然后像往常一样同时:

    # tcpdump -i eth0 -n -tt ...
    
    • 6
  2. JenyaKh
    2019-06-29T09:45:59+08:002019-06-29T09:45:59+08:00

    更新:

    所以我最终使用了这个解决方案。它存在于我的解决方案中。毕竟对我来说效果很好。


    我(主题启动者)已经使用 Linux 桥解决了我的问题。在这里 [ https://www.linuxquestions.org/questions/linux-networking-3/transferring-all-traffic-through-an-extra-interface-4175656515 ] 我写道,我设法使用了 Linux 桥接器,但排除了这种可能性:“但是这个解决方案不适合我的需求,因为实际上在 h1-br0 和 h1-eth0 接口之间有一个额外的以太网链路。我需要这些东西来进行性能测量,所以我不能有任何额外的以太网链路。我的意思是这个解决方案桥通过引入额外的链接弄乱了我的拓扑。”

           a1
    -----------------
    |a1-br0---a1-eth0|---------local network
    ------------------
    

    为什么我首先忽略了解决方案?最初,我的拓扑是:

    a1---3Gbps---r1---100Mbps---r2
    

    在链接上,r1---r2我将 netem 速率设置为 100 Mbps,在链接a1---r1上没有速率限制。由于将路由器r1连接到路由器的传输队列是 1000 个数据包,因此当从到r2发送流量时,我有队列溢出的影响(一些数据包被丢弃)。这没关系。这就是它在现实世界中发生的方式,在出现瓶颈链路的情况下,路由器队列会溢出。a1r2

    现在我做所有这些研究以增加延迟和速率限制a1---r1。所以我想出了这个使用 Linux 桥的解决方案。但我认为这个解决方案行不通。您可以在下面看到带有 Linux 网桥的新拓扑:

    [a1-br0 ---3Gbps---a1-eth0]---100Mbps---r1---100Mbps---r2
    

    所以我对解决方案的问题是我预计队列溢出现在会出现在 interface 的传输队列中a1-eth0。也就是说,这与上图中溢出在r1连接它的接口处的方式相同r2。类似地。

    我不想要这种溢出。因为在正常拓扑中——没有使用 Linux 桥接器来测量延迟——我们没有任何传输队列溢出a1-eth0:

    [a1-eth0]---100Mbps---r1---100Mbps---r2
    

    a1但是昨天我再次使用 Linux 桥(上图的第三个拓扑)创建了拓扑,并在从到的拓扑中启动了流量r2。我检查了以 500 毫秒间隔循环a1-eth0调用命令的传输队列的积压(队列中的当前数据包数)和使用类似命令的传输队列的积压。tc -s qdisc show dev a1-eth0a1-br0

    这就是我看到的a1-eth0,我收到了消息:

    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 9461862 bytes 6393 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 133380b 90p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 15280534 bytes 10323 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 133380b 90p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 21110722 bytes 14257 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 118560b 80p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 26952766 bytes 18199 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 102258b 69p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 32788882 bytes 22137 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 103740b 70p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 38635372 bytes 26082 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 102258b 69p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 44477416 bytes 30024 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 102258b 69p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 50332798 bytes 33975 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 102258b 69p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 56157058 bytes 37905 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 125970b 85p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 61969532 bytes 41828 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 133380b 90p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 67784900 bytes 45752 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 133380b 90p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 73600268 bytes 49676 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 133380b 90p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 79415636 bytes 53600 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 133380b 90p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 85244342 bytes 57533 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 120042b 81p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 91080458 bytes 61471 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 102258b 69p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 96923984 bytes 65414 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 102258b 69p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 102761582 bytes 69353 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 102258b 69p requeues 0 
    
    qdisc netem 8112: root refcnt 2 limit 1000 delay 10.0ms
     Sent 108606590 bytes 73297 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 103740b 70p requeues 0 
    

    这就是我看到的a1-br0,我收到了消息:

    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    qdisc noqueue 0: root refcnt 2 
     Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    

    因此可以看出,没有发生溢出a1-eth0,实际上它“看起来”不像a1-br0发送任何东西,尽管实际上它发送了。因此 and 之间的a1-bro链接与和 routera1-eth0之间的链接不同(第 veth 对链接)。我不知道为什么会这样。这很奇怪,因为我检查了我可以将 netem 延迟设置设置为-- 所以它就像一个普通的界面。a1r1a1-br0

    无论如何,我检查了桥的解决方案是否满足我的所有需求。不过,我还没有探索它为什么会起作用(我的意思是在我上面解释的意义上——队列溢出等)。


    这是我在主机上运行的命令以a1供参考。不过,我知道,如果没有上下文,很难完全理解它们。但是,也许,它会在未来帮助某人:

    brctl addbr a1-br0
    brctl addif a1-br0 a1-eth0
    ip link set dev a1-br0 up
    ip addr add dev a1-br0 11.0.0.1/30
    ip addr flush dev a1-eth0
    route add default gw 11.0.0.2 dev a1-br0
    ifconfig a1-eth0 0.0.0.0 up
    ethtool -K a1-br0 tx off sg off tso off ufo off
    

    我应用了命令的 IP 地址拓扑也出现在此处:Pinging an interface of Linux router by another interface by this router。这是拓扑:

    ------                           ------                            ------
    | a1 |                           | r1 |                            | r2 |
    |    | a1-eth0-----------r1-eth0 |    |r1-eth1--------------r2-eth1|    |
    -----(11.0.0.1/30)   (11.0.0.2/30)----(11.0.0.9/30)   (11.0.0.10/30)----- 
    
    • 1

相关问题

  • 查找与端口关联的线程/脚本?

  • 关于网络挂载文件的问题

  • IP地址可以以255结尾而不是广播IP地址吗?

  • 无法识别arp命令或ip命令哪个MAC地址输出正确

  • 奇怪的路由器与centos 6一起工作[关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve