LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Quality of Service with tc (https://www.linuxquestions.org/questions/linux-networking-3/quality-of-service-with-tc-787084/)

Yakideo 02-04-2010 04:03 PM

Quality of Service with tc
 
Hi,

Can the SFQ queue be used to divide bandwidth not only per connections but also per computer? e.g. if two computers download something each computer gets half of the bandwidth.

I'm trying to do my own script based on wondershaper and would want to divide the bandwidth between all devices so that one device can't saturate the uplink.

Yakideo 02-08-2010 04:27 PM

I've made a QoS script based on wondershaper however it doesn't quite work as expected. As see in the code bellow the class 1:10 doesn't have anything assigned to it and the default class is 1:40. The problem is that some (or even many) packages still end up in the 1:10 class. I think I must be doing something wrong. What can I do to fix it, improve or otherwise make it work?

Currently I'm on a ADSL link soon to become a cable link.

Code:

#!/bin/bash
#
# shape - DSL/Cable modem outbound traffic shaper and prioritizer.
#            Based on the ADSL/Cable wondershaper (www.lartc.org)
#
# Written by * (2010/02/07)
#
# Set the following values to somewhat less than your actual download
# uplink speed. In kilobits. Also set the device that is to be shaped.
DEV=eth0
RATEUP=668

# VoIP mac address
VoIPMAC="01:23:45:67:89:ab"

VoIPRATE=128

#########################################################

if [ "$1" = "status" ]
then
        tc -s qdisc ls dev $DEV
        tc -s class ls dev $DEV
        exit
fi

# clean existing uplink qdiscs, hide errors
tc qdisc del dev $DEV root 2> /dev/null > /dev/null
iptables -t mangle -D POSTROUTING -o $DEV -j MYSHAPER-OUT 2> /dev/null > /dev/null
iptables -t mangle -F MYSHAPER-OUT 2> /dev/null > /dev/null
iptables -t mangle -X MYSHAPER-OUT 2> /dev/null > /dev/null

if [ "$1" = "stop" ]
then
        echo "Shaping removed on $DEV."
        exit
fi

###### uplink

# add HTB root qdisc
tc qdisc add dev $DEV root handle 1: htb default 40

# add main rate limit classes
tc class add dev $DEV parent 1: classid 1:1 htb rate ${RATEUP}kbit


tc class add dev $DEV parent 1:1 classid 1:10 htb rate $[RATEUP/7]kbit ceil ${RATEUP}kbit prio 0    # ack
tc class add dev $DEV parent 1:1 classid 1:20 htb rate ${VoIPRATE}kbit ceil ${RATEUP}kbit prio 1  # VoIP
tc class add dev $DEV parent 1:1 classid 1:30 htb rate $[RATEUP/7]kbit ceil ${RATEUP}kbit prio 2    # Priority (ssh)
tc class add dev $DEV parent 1:1 classid 1:40 htb rate $[RATEUP/7]kbit ceil ${RATEUP}kbit prio 3    # normal (web, mail)
tc class add dev $DEV parent 1:1 classid 1:50 htb rate $[RATEUP/7]kbit ceil ${RATEUP}kbit prio 4    # bulk (P2P, FTP)

tc filter add dev $DEV parent 1:0 protocol ip handle 10 fw flowid 1:10
tc filter add dev $DEV parent 1:0 protocol ip handle 20 fw flowid 1:20
tc filter add dev $DEV parent 1:0 protocol ip handle 30 fw flowid 1:30
tc filter add dev $DEV parent 1:0 protocol ip handle 40 fw flowid 1:40
tc filter add dev $DEV parent 1:0 protocol ip handle 50 fw flowid 1:50

iptables -t mangle -N MYSHAPER-OUT
iptables -t mangle -I POSTROUTING -o $DEV -j MYSHAPER-OUT

# add fwmark entries to classify different types of traffic
#iptables -t mangle -A PREROUTING -p tcp -m length --length :64 -j MARK --set-mark 10 # small packets (probably just ACKs)
#iptables -t mangle -A MYSHAPER-OUT -p icmp -j MARK --set-mark 10              # ICMP (ping) - high prio, impress friends
#iptables -t mangle -A PREROUTING -p udp -j MARK --set-mark 10                # DNS name resolution (small packets)
#iptables -t mangle -A PREROUTING -p all -m mac --mac-source ${VoIPMAC} -j MARK --set-mark 20                # VoIP
#iptables -t mangle -A PREROUTING -p tcp --dport ssh -j MARK --set-mark 30    # secure shell
#iptables -t mangle -A PREROUTING -p tcp --sport ssh -j MARK --set-mark 30    # secure shell
#iptables -t mangle -A PREROUTING -m mark --mark 0 -j MARK --set-mark 40      # redundant- mark any unmarked packets as 26
#iptables -t mangle -A PREROUTING -p tcp --dport 20 -j MARK --set-mark 50    # ftp-data port, low prio

echo "Outbound shaping added to $DEV. Rate: ${RATEUP}Kbit/sec."


jomen 03-28-2010 11:32 AM

The r2q or the root qdisc is "10" by default - which is good for minimal rates of 120kbit
For slower links a lower value such as "1" is better or the results will not be as expected - its simply not accurate enough.
Took this from the htb documentation.
You use in almost all queues less than 100kbit


All times are GMT -5. The time now is 02:30 PM.