thombashi / tcconfig

A tc command wrapper. Make it easy to set up traffic control of network bandwidth/latency/packet-loss/packet-corruption/etc. to a network-interface/Docker-container(veth).
https://tcconfig.rtfd.io/
MIT License
792 stars 85 forks source link

how to use --shaping-algo config #146

Closed NickUESTC closed 4 years ago

NickUESTC commented 4 years ago

Describe the bug

sudo tcset ens33 --delay 200ms --rate 100Kbps --shaping-algo tbf --network 192.168.232.149 I want to use tbf algo 。 and when execute above cmd . tcshow return this message, rate config is None. { "ens33": { "outgoing": { "dst-network=192.168.232.149/32, protocol=ip": { "loss": "None", "duplicate": "None", "delay": "200.0ms", "rate": "None", "filter_id": "800::801", "corrupt": "None", "delay-distro": "None", "reorder": "None" } }, "incoming": {} } }

iperf test get msg: [ 3] local 192.168.232.133 port 42960 connected with 192.168.232.149 port 5001 [ ID] Interval Transfer Bandwidth [ 3] 0.0-10.0 sec 6.67 GBytes 5.73 Gbits/sec

so the rate limit is not valid

Expected behavior

how can I limit rate 200kbps use 'tbf' alg?
Thx!!!

To Reproduce

Steps to reproduce the behavior:

Environments

Please complete the following information:

Additional context

Add any other context (logs, error output, etc.) about the problem here.

thombashi commented 4 years ago

tcshow can not parse rate when using tbf. You can check the rate by the following command:

tc qdisc show dev enp0s3
NickUESTC commented 4 years ago

tcshow can not parse rate when using tbf. You can check the rate by the following command:

tc qdisc show dev enp0s3

Thx a lot,I follow your suggestion, the config worked use cmd

sudo tcset ens33 --delay 200ms --rate 100Kbps --shaping-algo tbf --network 192.168.232.133 && tc qdisc 

return msg like this:

qdisc noqueue 0: dev lo root refcnt 2 
qdisc prio 1f87: dev ens33 root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
qdisc netem 1f91: dev ens33 parent 1f87:1 limit 1000 delay 200.0ms
qdisc tbf 20: dev ens33 parent 1f91:1 rate 100Kbit burst 1600b lat 672.0ms

but, there is another question。how to use tcset to set lat or burst parameter?

thombashi commented 4 years ago

tcset command automatically calculates a burst value, and there is no interface to customize the value. I would recommend using --tc-command option that generates raw tc commands equivalent to the tcset command execution.

e.g.

$ tcset ens33 --delay 200ms --rate 100Kbps --shaping-algo tbf --network 192.168.232.133 --tc-command 
/sbin/tc qdisc add dev ens33 root handle 1f87: prio
/sbin/tc qdisc add dev ens33 parent 1f87:1 handle 1f91: netem delay 200.0ms
/sbin/tc qdisc add dev ens33 parent 1f91:1 handle 20: tbf rate 100.0kbit buffer 1600 limit 10000
/sbin/tc filter add dev ens33 protocol ip parent 1f87: prio 2 u32 match ip dst 0.0.0.0/0 flowid 1f87:2
/sbin/tc filter add dev ens33 protocol ip parent 1f87: prio 5 u32 match ip dst 192.168.232.133/32 match ip src 0.0.0.0/0 flowid 1f87:1

Then edit burst value (buffer 1600) of command and execute tc commands.