Z
Z
zeleniy872011-01-15 00:33:55
linux
zeleniy87, 2011-01-15 00:33:55

Shaper on tc, how?

Wrote a script for traffic shaping for one machine on the local network, eth0-looks in the local area, eth1-in the direction of the provider. Tell me why the shaper does not work? Shaper.sh
script code :

# show<br/>
if [ &quot;$1&quot; = &quot;show&quot; ]; then<br/>
 /sbin/tc -s qdisc show dev eth0<br/>
 /sbin/tc -s class show dev eth0<br/>
 /sbin/tc -s filter show dev eth0<br/>
 /sbin/tc -s filter show dev eth0 parent 12:<br/>
 exit;<br/>
fi<br/>
<br/>
if [ &quot;$1&quot; = &quot;stop&quot; ]; then<br/>
 echo &quot;Stopped.&quot;<br/>
 # clean<br/>
 /sbin/tc qdisc del dev eth0 root 2&gt;/dev/null<br/>
 /sbin/tc qdisc del dev eth1 root 2&gt;/dev/null<br/>
 /sbin/tc qdisc del dev eth0 ingress 2&gt; /dev/null<br/>
<br/>
exit<br/>
fi<br/>
<br/>
if [ &quot;$1&quot; = &quot;start&quot; ]; then<br/>
<br/>
echo &quot;Started.&quot;<br/>
<br/>
/sbin/tc qdisc add dev eth0 root handle 1: prio bands 3<br/>
/sbin/tc qdisc add dev eth0 parent 1:1 handle 10: pfifo<br/>
/sbin/tc qdisc add dev eth0 parent 1:2 handle 11: pfifo<br/>
/sbin/tc qdisc add dev eth0 parent 1:3 handle 12: htb default 0<br/>
<br/>
/sbin/tc filter add dev eth0 parent 12: prio 3 handle 1: protocol ip u32 divisor 256<br/>
/sbin/tc filter add dev eth0 protocol ip parent 12: prio 3 u32 match ip dst 172.16.0.0/24 hashkey mask 0x000000ff at 16 link 1:<br/>
<br/>
/sbin/tc class add dev eth0 parent 12: classid 12:101 htb rate 1024Kbit ceil 1024Kbit quantum 1514 mtu 16500<br/>
/sbin/tc qdisc add dev eth0 parent 12:101 handle 101: sfq perturb 5<br/>
/sbin/tc filter add dev eth0 protocol ip parent 12: prio 7 u32 ht 1:65: match ip dst 172.16.0.2 flowid 12:101<br/>
/sbin/tc filter add dev eth0 parent 1:0 protocol ip prio 4 u32 match ip dst 172.16.0.0/24 flowid 1:3<br/>
<br/>
exit<br/>
fi<br/>
<br/>
case &quot;$1&quot; in<br/>
start)<br/>
start<br/>
;;<br/>
stop)<br/>
stop<br/>
;;<br/>
restart)<br/>
stop<br/>
start<br/>
;;<br/>
list)<br/>
list<br/>
;;<br/>
stats)<br/>
list -s<br/>
;;<br/>
*)<br/>
echo &quot;Usage: $0 {start|stop|restart|list|stats}&quot;<br/>
exit 1<br/>
esac

Output from tc -s class show dev eth0 :
[email protected]://# tc -s class show dev eth0<br/>
class prio 1:1 parent 1: leaf 10:<br/>
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)<br/>
 backlog 0b 0p requeues 0<br/>
class prio 1:2 parent 1: leaf 11:<br/>
 Sent 84 bytes 2 pkt (dropped 0, overlimits 0 requeues 0)<br/>
 backlog 0b 0p requeues 0<br/>
class prio 1:3 parent 1: leaf 12:<br/>
 Sent 1287381 bytes 1545 pkt (dropped 0, overlimits 0 requeues 0)<br/>
 backlog 0b 0p requeues 0<br/>
class htb 12:101 root leaf 101: prio 0 rate 1024Kbit ceil 1024Kbit burst 16499b cburst 16499b<br/>
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)<br/>
 rate 0bit 0pps backlog 0b 0p requeues 0<br/>
 lended: 0 borrowed: 0 giants: 0<br/>
 tokens: 2014156 ctokens: 2014156<br/>
<br/>
class htb 12:102 root leaf 102: prio 0 rate 1024Kbit ceil 1024Kbit burst 16499b cburst 16499b<br/>
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)<br/>
 rate 0bit 0pps backlog 0b 0p requeues 0<br/>
 lended: 0 borrowed: 0 giants: 0<br/>
 tokens: 2014156 ctokens: 2014156

Answer the question

In order to leave comments, you need to log in

5 answer(s)
Y
Yur4eg, 2011-01-17
@zeleniy87

This is because the PRIO queue does not shape, but only looks at the TOS field of the packet, queues traffic by priority.
You need to use HTB
tc qdisc add dev eth0 root handle 1: htb default 12
tc class add dev eth0 parent 1: classid 1:10 htb rate 1024Kbit burst 10k
tc filter add dev eth0 parent 1: protocol ip u32 match ip dst 172.16.0.0/24 flowid 1:10
HTB manual luxik.cdi.cz/~devik/qos/htb/manual/userg.htm should have started from him

Y
Yur4eg, 2011-01-16
@Yur4eg

All traffic on 172.16.0.0/24 is wrapped in the prio 1:3 class, what exactly is not to like?

P
Puma Thailand, 2011-01-15
@opium

With your shaper, you can break your head, use htb.init, it is simpler and easier to understand.

Z
zeleniy87, 2011-01-16
@zeleniy87

on a computer with an ip-address, the speed is at full speed, i.e. traffic from this address is not shaping

Z
zeleniy87, 2011-01-24
@zeleniy87

everything figured out, the ht parameter must correspond to the table where the hash is entered and the last octet of the destination address (in hexadecimal notation). Those. for the shaper to work you need:
/sbin/tc qdisc add dev eth0 root handle 1: prio bands 3
/sbin/tc qdisc add dev eth0 parent 1:1 handle 10: pfifo
/sbin/tc qdisc add dev eth0 parent 1:2 handle 11 : pfifo
/sbin/tc qdisc add dev eth0 parent 1:3 handle 12: htb default 0
/sbin/tc filter add dev eth0 parent 12: prio 3 handle 1: protocol ip u32 divisor 256
/sbin/tc filter add dev eth0 protocol ip parent 12: prio 3 u32 match ip dst 172.16.0.0/24 hashkey mask 0x000000ff at 16 link 1:
/sbin/tc class add dev eth0 parent 12: classid 12:101 htb rate 1024Kbit ceil 1024Kbit quantum 1514 mtu 16500
/sbin/tc qdisc add dev eth0 parent 12:101 handle 101: sfq perturb 5
/sbin/tc filter add dev eth0 protocol ip parent 12: prio 7 u32 ht 1:2: match ip dst 172.16.0.2 flowid 12:101
/sbin/tc filter add dev eth0 parent 1:0 protocol ip prio 4 u32 match ip dst 172.16.0.0/24 flowid 1 :3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question