Linux – Link Bandwidth Limiting Using tc

bandwidthbandwidth-controllinuxlinux-networkingtc

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?

Best Answer

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.