大网数据广告活动
服务器运维问答

Link bandwidth limiting by using tc

· 52CE 我爱测

I am a newbie network engineer. I am trying to understand the Linux command tc . I made a simple network, consisting of two hosts H1, H2 and a switch S1 connecting them by using Mininet. Then, I made H1 send UDP packets to H2, th…

问题原文

原帖链接 · nimdrak · CC BY-SA 4.0

I am a newbie network engineer.

I am trying to understand the Linux command tc.

I made a simple network, consisting of two hosts H1, H2 and a switch S1 connecting them by using Mininet.

Then, I made H1 send UDP packets to H2, through switch S1 by using iPerf2.

#H1
iperf -s -p 1212 -f m -i 1

#H2
iperf -c 10.0.0.1 -p 1212 -t 10000 -f m -b 70M -u

For limiting the link bandwidth, I made a simple bash script below.

#!/bin/bash

#s1-eth1 is outgoing port from H1 to H2
#its orginal bandwidth 100Mbit/s

sudo tc qdisc del dev s1-eth1 root 
sudo tc qdisc add dev s1-eth1 root handle 1:0 htb default 12
sudo tc qdisc add dev s1-eth1 parent 1:0 classid 1:1 htb rate 50Mbit
sudo tc filter add deb s1-eth1 protocol ip parent 1:0 prio 1 u32 match ip dport 1212 0xffff flowid 1:1


I expected that the rx rate of S1 became 50Mbit/s but it didn't.

It showed about 40Mbit/s.

When I changed the settings of this experiment, it showed a smaller value than I set by using the tc command.

Why did it happen? I looked over the kernel code of Linux tc but I cannot understand it.

Could you give me a little hint?

已采纳解答

原帖链接 · Anton Danilov · CC BY-SA 4.0

Hints and troubleshooting.

  1. You should understand the difference between queuing, shaping and policing.
  2. You should understand the difference between ingress and egress directions.
  3. Check the classifier (tc -p filter show dev <iface>)
  4. Check the classifier statistics (tc -s -s -d f ls dev <iface>) - 1st step of troubleshooting.
  5. Check the queue discipline statistics (tc -s -s -d qdisc list dev <iface> and tc -s -s -d c ls dev <iface>) - 2nd step of troubleshooting.
  6. Use the estimators to monitor the actual rate from the point of view of the qdisc. You should specify it at qdisc attachment. Some schedulers can create the default estimators, when the kernel module has been loaded with corresponded option (see modinfo sch_htb).
  7. You've specified the default class 1:12, but don't define it.
  8. Read the saga about HTB and examples of configuration.
  9. The QoS isn't a simple thing.
  10. You also can capture the traffic and analyze it with the wireshark. Investigate the window size changing of tcp connections to trace work of the shaper. But for UDP this way isn't much suitable.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-07-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。