Help prioritizing games with alternative qdisc design

Uploading: Capture d’écran 2020-11-23 à 21.54.52.png...

like this ?

No, you changed the rule for the "default" traffic... change the 2nd and 3rd rule, leave the 1st rule the way it was.

1 Like

Here is code you can try:


if [ "$cont" = "y" ]; then


    ## change these if you use drr or prio instead of pfifo
    iptables -t mangle -A POSTROUTING -j CLASSIFY --set-class 3:1 # default everything to 3:1,  the "non-game" qdisc
    if [ "$gameqdisc" = "pfifo" ]; then
	
	iptables -t mangle -A POSTROUTING -p udp -s ${GAMINGIP} -j CLASSIFY --set-class 2:0
	iptables -t mangle -A POSTROUTING -p udp -d ${GAMINGIP} -j CLASSIFY --set-class 2:0
    else
	echo "YOU MUST PLACE CLASSIFIERS FOR YOUR GAME TRAFFIC HERE"
	echo "SEND TRAFFIC TO 2:1 (high) or 2:2 (medium) or 2:3 (normal)"
    fi
else
    cat <<EOF
Check the rules and come back when you're ready.
EOF

based on the man pages, this is the issue. I will post a full version of the script that can be tested as soon as you confirm if it works.

your script has an error ligne 194

i have modified like this

maybe is more just i don't knw i learn

#!/bin/sh

## "atm" for old-school DSL or change to "DOCSIS" for cable modem, or "other" for everything else

LINKTYPE="atm"

WAN=eth0.2 # change this to your WAN device name
UPRATE=16000 #change this to your kbps upload speed
LAN=eth0.1
DOWNRATE=56000 #change this to about 80% of your download speed (in kbps)

## how many kbps of UDP upload and download do you need for your games
## across all gaming machines? 

GAMEUP=450
GAMEDOWN=1200

## set this to "pfifo" or if you want to differentiate between game
## packets into 3 different classes you can use either "drr" or "qfq"
## be aware not all machines will have drr or qfq available

gameqdisc="pfifo"

GAMINGIP="192.168.2.167" ## change this



cat <<EOF

This script prioritizes the UDP packets from / to a set of gaming
machines into a real-time HFSC queue with guaranteed total bandwidth 

Based on your settings:

Game upload guarantee = $GAMEUP kbps
Game download guarantee = $GAMEDOWN kbps

Download direction only works if you install this on a *wired* router
and there is a separate AP wired into your network, because otherwise
there are multiple parallel queues for traffic to leave your router
heading to the LAN.

Based on your link total bandwidth, the **minimum** amount of jitter
you should expect in your network is about:

UP = $(((1500*8)*3/UPRATE)) ms

DOWN = $(((1500*8)*3/DOWNRATE)) ms

In order to get lower minimum jitter you must upgrade the speed of
your link, no queuing system can help.

Please note for your display rate that:

at 30Hz, one on screen frame lasts:   33.3 ms
at 60Hz, one on screen frame lasts:   16.6 ms
at 144Hz, one on screen frame lasts:   6.9 ms

This means the typical gamer is sensitive to as little as on the order
of 5ms of jitter. To get 5ms minimum jitter you should have bandwidth
in each direction of at least:

$((1500*8*3/5)) kbps

The queue system can ONLY control bandwidth and jitter in the link
between your router and the VERY FIRST device in the ISP
network. Typically you will have 5 to 10 devices between your router
and your gaming server, any of those can have variable delay and ruin
your gaming, and there is NOTHING that your router can do about it.

EOF




setqdisc () {
DEV=$1
RATE=$2
OH=26
MTU=1500
highrate=$((RATE*90/100))
lowrate=$((RATE*10/100))
gamerate=$3
useqdisc=$4


tc qdisc del dev "$DEV" root

case $LINKTYPE in
    "atm")
	tc qdisc replace dev "$DEV" handle 1: root stab mtu 2047 tsize 512 mpu 68 overhead ${OH} linklayer atm hfsc default 3
	;;
    "DOCSIS")
	tc qdisc replace dev "$DEV" stab overhead 25 linklayer ethernet handle 1: root hfsc default 3
	;;
    *)
	tc qdisc replace dev "$DEV" stab overhead 40 linklayer ethernet handle 1: root hfsc default 3
	;;
esac
     



#limit the link overall:
tc class add dev "$DEV" parent 1: classid 1:1 hfsc ls m2 "${RATE}kbit" ul m2 "${RATE}kbit"

# high prio class
tc class add dev "$DEV" parent 1:1 classid 1:2 hfsc rt m1 "${highrate}kbit" d 80ms m2 "${gamerate}kbit"

# other prio class
tc class add dev "$DEV" parent 1:1 classid 1:3 hfsc ls m1 "${lowrate}kbit" d 80ms m2 "${highrate}kbit"


## set this to "drr" or "qfq" to differentiate between different game
## packets, or use "pfifo" to treat all game packets equally

case $useqdisc in
    "drr")
	tc qdisc add dev "$DEV" parent 1:2 handle 2:0 drr
	tc class add dev "$DEV" parent 2:0 classid 2:1 drr quantum 8000
	tc class add dev "$DEV" parent 2:0 classid 2:2 drr quantum 4000
	tc class add dev "$DEV" parent 2:0 classid 2:3 drr quantum 1000
	## with this send high priority game packets to 2:1, medium to 2:2 and normal to 2:3
	## games will not starve but be given relative importance based on the quantum parameter
    ;;

    "qfq")
	tc qdisc add dev "$DEV" parent 1:2 handle 2:0 qfq
	tc class add dev "$DEV" parent 2:0 classid 2:1 qfq weight 8000
	tc class add dev "$DEV" parent 2:0 classid 2:2 qfq weight 4000
	tc class add dev "$DEV" parent 2:0 classid 2:3 qfq weight 1000
	## with this send high priority game packets to 2:1, medium to 2:2 and normal to 2:3
	## games will not starve but be given relative importance based on the weight parameter

    ;;

    *)
	PFIFOLEN=$((1 + 40*RATE/(MTU*8))) # at least 1 packet, plus 40ms worth of additional packets
	tc qdisc add dev "$DEV" parent 1:2 handle 2:1 pfifo limit $PFIFOLEN
	## send game packets to 2:1, they're all the same
	
    ;;
esac

if [ $((MTU * 8 * 10 / RATE > 50)) -eq 1 ]; then ## if one MTU packet takes more than 5ms
    echo "adding PIE qdisc for non-game traffic due to slow link"
    tc qdisc add dev "$DEV" parent 1:3 handle 3:1 pie limit  $((RATE * 200 / (MTU * 8))) target 80ms ecn tupdate 40ms bytemode
else ## we can have queues with multiple packets without major delays, fair queuing is more meaningful
    echo "adding fq_codel qdisc for non-game traffic due to fast link"
    tc qdisc add dev "$DEV" parent 1:3 handle 3:1 fq_codel limit $((RATE * 200 / (MTU * 8))) quantum $((MTU * 2))
fi

}




setqdisc $WAN $UPRATE $GAMEUP $gameqdisc

## uncomment this to do the download direction via output of LAN
setqdisc $LAN $DOWNRATE $GAMEDOWN $gameqdisc

## we want to classify packets, so use these rules

cat <<EOF

We are going to add classification rules via iptables to the
POSTROUTING chain. You should actually read and ensure that these
rules make sense in your firewall before running this script. 

Continue? (type y or n and then RETURN/ENTER)
EOF

read -r cont

if [ "$cont" = "y" ]; then


    ## change these if you use drr or prio instead of pfifo
    iptables -t mangle -A POSTROUTING -j CLASSIFY --set-class 3:1 # default everything to 3:1,  the "non-game" qdisc
    if [ "$gameqdisc" = "pfifo" ]; then
	
	iptables -t mangle -A POSTROUTING -p udp -s ${GAMINGIP} -j CLASSIFY --set-class 2:0
	iptables -t mangle -A POSTROUTING -p udp -d ${GAMINGIP} -j CLASSIFY --set-class 2:0
    
else
	echo "YOU MUST PLACE CLASSIFIERS FOR YOUR GAME TRAFFIC HERE"
	echo "SEND TRAFFIC TO 2:1 (high) or 2:2 (medium) or 2:3 (normal)"
    fi
else
    cat <<EOF
Check the rules and come back when you're ready.
EOF
fi

echo "DONE!"

tc -s qdisctc

Ok, I see I need to do some other stuff too, for later when people are trying drr or qfq

I will try to fix and post a full script!!! OMG so many scripts!

1 Like

ahah nous allons y arriver, :stuck_out_tongue:

keep me inform

tc is really complicated I always wind up doing a lot of debugging, hopefully this script works fine and will also work fine later when qfq or drr are available.

#!/bin/sh

## "atm" for old-school DSL or change to "DOCSIS" for cable modem, or "other" for everything else

LINKTYPE="atm"

WAN=veth0 # change this to your WAN device name
UPRATE=6500 #change this to your kbps upload speed
LAN=veth1
DOWNRATE=30000 #change this to about 80% of your download speed (in kbps)

## how many kbps of UDP upload and download do you need for your games
## across all gaming machines? 

GAMEUP=450
GAMEDOWN=1200

## set this to "pfifo" or if you want to differentiate between game
## packets into 3 different classes you can use either "drr" or "qfq"
## be aware not all machines will have drr or qfq available

gameqdisc="pfifo"

GAMINGIP="192.168.1.111" ## change this



cat <<EOF

This script prioritizes the UDP packets from / to a set of gaming
machines into a real-time HFSC queue with guaranteed total bandwidth 

Based on your settings:

Game upload guarantee = $GAMEUP kbps
Game download guarantee = $GAMEDOWN kbps

Download direction only works if you install this on a *wired* router
and there is a separate AP wired into your network, because otherwise
there are multiple parallel queues for traffic to leave your router
heading to the LAN.

Based on your link total bandwidth, the **minimum** amount of jitter
you should expect in your network is about:

UP = $(((1500*8)*3/UPRATE)) ms

DOWN = $(((1500*8)*3/DOWNRATE)) ms

In order to get lower minimum jitter you must upgrade the speed of
your link, no queuing system can help.

Please note for your display rate that:

at 30Hz, one on screen frame lasts:   33.3 ms
at 60Hz, one on screen frame lasts:   16.6 ms
at 144Hz, one on screen frame lasts:   6.9 ms

This means the typical gamer is sensitive to as little as on the order
of 5ms of jitter. To get 5ms minimum jitter you should have bandwidth
in each direction of at least:

$((1500*8*3/5)) kbps

The queue system can ONLY control bandwidth and jitter in the link
between your router and the VERY FIRST device in the ISP
network. Typically you will have 5 to 10 devices between your router
and your gaming server, any of those can have variable delay and ruin
your gaming, and there is NOTHING that your router can do about it.

EOF




setqdisc () {
DEV=$1
RATE=$2
OH=37
MTU=1500
highrate=$((RATE*90/100))
lowrate=$((RATE*10/100))
gamerate=$3
useqdisc=$4


tc qdisc del dev "$DEV" root

case $LINKTOP in
    "atm")
	tc qdisc replace dev "$DEV" handle 1: root stab mtu 2047 tsize 512 mpu 68 overhead ${OH} linklayer atm hfsc default 3
	;;
    "DOCSIS")
	tc qdisc replace dev $DEV stab overhead 25 linklayer ethernet handle 1: root hfsc default 3
	;;
    *)
	tc qdisc replace dev $DEV stab overhead 40 linklayer ethernet handle 1: root hfsc default 3
	;;
esac
     



#limit the link overall:
tc class add dev "$DEV" parent 1: classid 1:1 hfsc ls m2 "${RATE}kbit" ul m2 "${RATE}kbit"

# high prio class
tc class add dev "$DEV" parent 1:1 classid 1:2 hfsc rt m1 "${highrate}kbit" d 80ms m2 "${gamerate}kbit"

# other prio class
tc class add dev "$DEV" parent 1:1 classid 1:3 hfsc ls m1 "${lowrate}kbit" d 80ms m2 "${highrate}kbit"


## set this to "drr" or "qfq" to differentiate between different game
## packets, or use "pfifo" to treat all game packets equally

REDMIN=$((gamerate*30/8)) #30 ms of data
REDMAX=$((gamerate*200/8)) #200ms of data

case $useqdisc in
    "drr")
	tc qdisc add dev "$DEV" parent 1:2 handle 2:0 drr
	tc class add dev "$DEV" parent 2:0 classid 2:1 drr quantum 8000
	tc qdisc add dev "$DEV" parent 2:1 handle 10: red limit 150000 min $REDMIN max $REDMAX probability 1.0
	tc class add dev "$DEV" parent 2:0 classid 2:2 drr quantum 4000
	tc qdisc add dev "$DEV" parent 2:2 handle 20: red limit 150000 min $REDMIN max $REDMAX probability 1.0
	tc class add dev "$DEV" parent 2:0 classid 2:3 drr quantum 1000
	tc qdisc add dev "$DEV" parent 2:3 handle 30: red limit 150000 min $REDMIN max $REDMAX probability 1.0
	## with this send high priority game packets to 10:, medium to 20:, normal to 30:
	## games will not starve but be given relative importance based on the quantum parameter
    ;;

    "qfq")
	tc qdisc add dev "$DEV" parent 1:2 handle 2:0 qfq
	tc class add dev "$DEV" parent 2:0 classid 2:1 qfq weight 8000
	tc qdisc add dev "$DEV" parent 2:1 handle 10: red limit 150000 min $REDMIN max $REDMAX probability 1.0
	tc class add dev "$DEV" parent 2:0 classid 2:2 qfq weight 4000
	tc qdisc add dev "$DEV" parent 2:2 handle 20: red limit 150000 min $REDMIN max $REDMAX probability 1.0
	tc class add dev "$DEV" parent 2:0 classid 2:3 qfq weight 1000
	tc qdisc add dev "$DEV" parent 2:3 handle 30: red limit 150000 min $REDMIN max $REDMAX probability 1.0
	## with this send high priority game packets to 10:, medium to 20:, normal to 30:
	## games will not starve but be given relative importance based on the weight parameter

    ;;

    *)
	PFIFOLEN=$((1 + 40*RATE/(MTU*8))) # at least 1 packet, plus 40ms worth of additional packets
	tc qdisc add dev "$DEV" parent 1:2 handle 10: pfifo limit $PFIFOLEN
	## send game packets to 10:, they're all treated the same
	
    ;;
esac

if [ $((MTU * 8 * 10 / RATE > 50)) -eq 1 ]; then ## if one MTU packet takes more than 5ms
    echo "adding PIE qdisc for non-game traffic due to slow link"
    tc qdisc add dev "$DEV" parent 1:3 handle 3: pie limit  $((RATE * 200 / (MTU * 8))) target 80ms ecn tupdate 40ms bytemode
else ## we can have queues with multiple packets without major delays, fair queuing is more meaningful
    echo "adding fq_codel qdisc for non-game traffic due to fast link"
    tc qdisc add dev "$DEV" parent 1:3 handle 3: fq_codel limit $((RATE * 200 / (MTU * 8))) quantum $((MTU * 2))
fi

}


setqdisc $WAN $UPRATE $GAMEUP $gameqdisc

## uncomment this to do the download direction via output of LAN
setqdisc $LAN $DOWNRATE $GAMEDOWN $gameqdisc

## we want to classify packets, so use these rules

cat <<EOF

We are going to add classification rules via iptables to the
POSTROUTING chain. You should actually read and ensure that these
rules make sense in your firewall before running this script. 

Continue? (type y or n and then RETURN/ENTER)
EOF

read -r cont

if [ "$cont" = "y" ]; then
    iptables -t mangle -F POSTROUTING
    iptables -t mangle -A POSTROUTING -j CLASSIFY --set-class 3:0 # default everything to 3:,  the "non-game" qdisc
    if [ "$gameqdisc" = "pfifo" ]; then
	iptables -t mangle -A POSTROUTING -p udp -s ${GAMINGIP} -j CLASSIFY --set-class 10:0
	iptables -t mangle -A POSTROUTING -p udp -d ${GAMINGIP} -j CLASSIFY --set-class 10:0
    else
	echo "YOU MUST PLACE CLASSIFIERS FOR YOUR GAME TRAFFIC HERE"
	echo "SEND TRAFFIC TO 10: (high) or 20: (medium) or 30: (normal)"
    fi
else
    cat <<EOF
Check the rules and come back when you're ready.
EOF
fi

echo "DONE!"

tc -s qdisc

@juju1366, I added one more line here to flush the POSTROUTING mangle table first...

what is wrong in my settings i just changed the veth in eth ?

pfifo send always not

maybe etc/sysconf/ i add defaut pfifo

yes it's work now pfifo i don't know why :stuck_out_tongue:

Continue? (type y or n and then RETURN/ENTER)
y
DONE!
qdisc noqueue 0: dev lo root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc pfifo 8001: dev eth0 root refcnt 2 limit 1000p
 Sent 29026629 bytes 60451 pkt (dropped 0, overlimits 0 requeues 4)
 backlog 0b 0p requeues 4
qdisc noqueue 0: dev br-lan root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc hfsc 1: dev eth0.1 root refcnt 2 default 3
 Sent 136822 bytes 368 pkt (dropped 0, overlimits 10 requeues 0)
 backlog 0b 0p requeues 0
qdisc pfifo 10: dev eth0.1 parent 1:2 limit 164p
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 3: dev eth0.1 parent 1:3 limit 816p flows 1024 quantum 3000 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 136604 bytes 367 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
  maxpacket 3002 drop_overlimit 0 new_flow_count 106 ecn_mark 0
  new_flows_len 0 old_flows_len 2
qdisc hfsc 1: dev eth0.2 root refcnt 2 default 3
 Sent 11563 bytes 33 pkt (dropped 0, overlimits 3 requeues 0)
 backlog 0b 0p requeues 0
qdisc pfifo 10: dev eth0.2 parent 1:2 limit 44p
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 3: dev eth0.2 parent 1:3 limit 216p flows 1024 quantum 3000 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 11563 bytes 33 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
  maxpacket 1931 drop_overlimit 0 new_flow_count 20 ecn_mark 0
  new_flows_len 1 old_flows_len 1
root@OpenWrt:~#

you confirm is correct ?

It's making the qdiscs, so now you need to game and see if packets get transferred on the pfifo.

1 Like

ok top just how make in startup because when i restart the router the classify class delelte firewall after reboot

First, does it work?

i'm on game i'm verify just after :slight_smile:

root@OpenWrt:~# tc -s qdisc
qdisc noqueue 0: dev lo root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 0: dev eth0 root refcnt 2 limit 10240p flows 1024 quantum 1514 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 35673025 bytes 101618 pkt (dropped 0, overlimits 0 requeues 3)
 backlog 0b 0p requeues 3
  maxpacket 3028 drop_overlimit 0 new_flow_count 88 ecn_mark 0
  new_flows_len 0 old_flows_len 0
qdisc noqueue 0: dev br-lan root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc hfsc 1: dev eth0.1 root refcnt 2 default 3
 Sent 26444323 bytes 56504 pkt (dropped 0, overlimits 1515 requeues 0)
 backlog 0b 0p requeues 0
qdisc pfifo 10: dev eth0.1 parent 1:2 limit 164p
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 3: dev eth0.1 parent 1:3 limit 816p flows 1024 quantum 3000 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 26444105 bytes 56503 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
  maxpacket 4450 drop_overlimit 0 new_flow_count 8952 ecn_mark 0
  new_flows_len 1 old_flows_len 3
qdisc hfsc 1: dev eth0.2 root refcnt 2 default 3
 Sent 10600243 bytes 38374 pkt (dropped 1, overlimits 2300 requeues 0)
 backlog 0b 0p requeues 0

no he dosent work :confused:

Ok, then I think iptables classify must want the CLASS not the qdisc... so we change...

#!/bin/sh

## "atm" for old-school DSL or change to "DOCSIS" for cable modem, or "other" for everything else

LINKTYPE="atm"

WAN=veth0 # change this to your WAN device name
UPRATE=6500 #change this to your kbps upload speed
LAN=veth1
DOWNRATE=30000 #change this to about 80% of your download speed (in kbps)

## how many kbps of UDP upload and download do you need for your games
## across all gaming machines? 

GAMEUP=450
GAMEDOWN=1200

## set this to "pfifo" or if you want to differentiate between game
## packets into 3 different classes you can use either "drr" or "qfq"
## be aware not all machines will have drr or qfq available

gameqdisc="pfifo"

GAMINGIP="192.168.1.111" ## change this



cat <<EOF

This script prioritizes the UDP packets from / to a set of gaming
machines into a real-time HFSC queue with guaranteed total bandwidth 

Based on your settings:

Game upload guarantee = $GAMEUP kbps
Game download guarantee = $GAMEDOWN kbps

Download direction only works if you install this on a *wired* router
and there is a separate AP wired into your network, because otherwise
there are multiple parallel queues for traffic to leave your router
heading to the LAN.

Based on your link total bandwidth, the **minimum** amount of jitter
you should expect in your network is about:

UP = $(((1500*8)*3/UPRATE)) ms

DOWN = $(((1500*8)*3/DOWNRATE)) ms

In order to get lower minimum jitter you must upgrade the speed of
your link, no queuing system can help.

Please note for your display rate that:

at 30Hz, one on screen frame lasts:   33.3 ms
at 60Hz, one on screen frame lasts:   16.6 ms
at 144Hz, one on screen frame lasts:   6.9 ms

This means the typical gamer is sensitive to as little as on the order
of 5ms of jitter. To get 5ms minimum jitter you should have bandwidth
in each direction of at least:

$((1500*8*3/5)) kbps

The queue system can ONLY control bandwidth and jitter in the link
between your router and the VERY FIRST device in the ISP
network. Typically you will have 5 to 10 devices between your router
and your gaming server, any of those can have variable delay and ruin
your gaming, and there is NOTHING that your router can do about it.

EOF




setqdisc () {
DEV=$1
RATE=$2
OH=37
MTU=1500
highrate=$((RATE*90/100))
lowrate=$((RATE*10/100))
gamerate=$3
useqdisc=$4


tc qdisc del dev "$DEV" root

case $LINKTOP in
    "atm")
	tc qdisc replace dev "$DEV" handle 1: root stab mtu 2047 tsize 512 mpu 68 overhead ${OH} linklayer atm hfsc default 3
	;;
    "DOCSIS")
	tc qdisc replace dev $DEV stab overhead 25 linklayer ethernet handle 1: root hfsc default 3
	;;
    *)
	tc qdisc replace dev $DEV stab overhead 40 linklayer ethernet handle 1: root hfsc default 3
	;;
esac
     



#limit the link overall:
tc class add dev "$DEV" parent 1: classid 1:1 hfsc ls m2 "${RATE}kbit" ul m2 "${RATE}kbit"

# high prio class
tc class add dev "$DEV" parent 1:1 classid 1:2 hfsc rt m1 "${highrate}kbit" d 80ms m2 "${gamerate}kbit"

# other prio class
tc class add dev "$DEV" parent 1:1 classid 1:3 hfsc ls m1 "${lowrate}kbit" d 80ms m2 "${highrate}kbit"


## set this to "drr" or "qfq" to differentiate between different game
## packets, or use "pfifo" to treat all game packets equally

REDMIN=$((gamerate*30/8)) #30 ms of data
REDMAX=$((gamerate*200/8)) #200ms of data

case $useqdisc in
    "drr")
	tc qdisc add dev "$DEV" parent 1:2 handle 2:0 drr
	tc class add dev "$DEV" parent 2:0 classid 2:1 drr quantum 8000
	tc qdisc add dev "$DEV" parent 2:1 handle 10: red limit 150000 min $REDMIN max $REDMAX probability 1.0
	tc class add dev "$DEV" parent 2:0 classid 2:2 drr quantum 4000
	tc qdisc add dev "$DEV" parent 2:2 handle 20: red limit 150000 min $REDMIN max $REDMAX probability 1.0
	tc class add dev "$DEV" parent 2:0 classid 2:3 drr quantum 1000
	tc qdisc add dev "$DEV" parent 2:3 handle 30: red limit 150000 min $REDMIN max $REDMAX probability 1.0
	## with this send high priority game packets to 10:, medium to 20:, normal to 30:
	## games will not starve but be given relative importance based on the quantum parameter
    ;;

    "qfq")
	tc qdisc add dev "$DEV" parent 1:2 handle 2:0 qfq
	tc class add dev "$DEV" parent 2:0 classid 2:1 qfq weight 8000
	tc qdisc add dev "$DEV" parent 2:1 handle 10: red limit 150000 min $REDMIN max $REDMAX probability 1.0
	tc class add dev "$DEV" parent 2:0 classid 2:2 qfq weight 4000
	tc qdisc add dev "$DEV" parent 2:2 handle 20: red limit 150000 min $REDMIN max $REDMAX probability 1.0
	tc class add dev "$DEV" parent 2:0 classid 2:3 qfq weight 1000
	tc qdisc add dev "$DEV" parent 2:3 handle 30: red limit 150000 min $REDMIN max $REDMAX probability 1.0
	## with this send high priority game packets to 10:, medium to 20:, normal to 30:
	## games will not starve but be given relative importance based on the weight parameter

    ;;

    *)
	PFIFOLEN=$((1 + 40*RATE/(MTU*8))) # at least 1 packet, plus 40ms worth of additional packets
	tc qdisc add dev "$DEV" parent 1:2 handle 10: pfifo limit $PFIFOLEN
	## send game packets to 10:, they're all treated the same
	
    ;;
esac

if [ $((MTU * 8 * 10 / RATE > 50)) -eq 1 ]; then ## if one MTU packet takes more than 5ms
    echo "adding PIE qdisc for non-game traffic due to slow link"
    tc qdisc add dev "$DEV" parent 1:3 handle 3: pie limit  $((RATE * 200 / (MTU * 8))) target 80ms ecn tupdate 40ms bytemode
else ## we can have queues with multiple packets without major delays, fair queuing is more meaningful
    echo "adding fq_codel qdisc for non-game traffic due to fast link"
    tc qdisc add dev "$DEV" parent 1:3 handle 3: fq_codel limit $((RATE * 200 / (MTU * 8))) quantum $((MTU * 2))
fi

}


setqdisc $WAN $UPRATE $GAMEUP $gameqdisc

## uncomment this to do the download direction via output of LAN
setqdisc $LAN $DOWNRATE $GAMEDOWN $gameqdisc

## we want to classify packets, so use these rules

cat <<EOF

We are going to add classification rules via iptables to the
POSTROUTING chain. You should actually read and ensure that these
rules make sense in your firewall before running this script. 

Continue? (type y or n and then RETURN/ENTER)
EOF

read -r cont

if [ "$cont" = "y" ]; then

    iptables -t mangle -F POSTROUTING
    iptables -t mangle -A POSTROUTING -j CLASSIFY --set-class 1:3 # default everything to 1:3,  the "non-game" qdisc
    if [ "$gameqdisc" = "pfifo" ]; then
	iptables -t mangle -A POSTROUTING -p udp -s ${GAMINGIP} -j CLASSIFY --set-class 1:2
	iptables -t mangle -A POSTROUTING -p udp -d ${GAMINGIP} -j CLASSIFY --set-class 1:2
    else
	echo "YOU MUST PLACE CLASSIFIERS FOR YOUR GAME TRAFFIC HERE"
	echo "SEND TRAFFIC TO 2:1 (high) or 2:2 (medium) or 3:3 (normal)"
    fi
else
    cat <<EOF
Check the rules and come back when you're ready.
EOF
fi

echo "DONE!"

tc -s qdisc
1 Like
root@OpenWrt:~# tc -s qdisc
qdisc noqueue 0: dev lo root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 0: dev eth0 root refcnt 2 limit 10240p flows 1024 quantum 1514 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 47169224 bytes 125154 pkt (dropped 0, overlimits 0 requeues 7)
 backlog 0b 0p requeues 7
  maxpacket 3028 drop_overlimit 0 new_flow_count 270 ecn_mark 0
  new_flows_len 0 old_flows_len 0
qdisc noqueue 0: dev br-lan root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc hfsc 1: dev eth0.1 root refcnt 2 default 3
 Sent 556582 bytes 1532 pkt (dropped 0, overlimits 42 requeues 0)
 backlog 0b 0p requeues 0
qdisc pfifo 10: dev eth0.1 parent 1:2 limit 174p
 Sent 1183 bytes 8 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 3: dev eth0.1 parent 1:3 limit 866p flows 1024 quantum 3000 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 555070 bytes 1522 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
  maxpacket 3002 drop_overlimit 0 new_flow_count 440 ecn_mark 0
  new_flows_len 1 old_flows_len 4
qdisc hfsc 1: dev eth0.2 root refcnt 2 default 3
 Sent 43963 bytes 150 pkt (dropped 0, overlimits 15 requeues 0)
 backlog 0b 0p requeues 0
qdisc pfifo 10: dev eth0.2 parent 1:2 limit 57p
 Sent 1128 bytes 10 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 3: dev eth0.2 parent 1:3 limit 283p flows 1024 quantum 3000 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 42835 bytes 140 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
  maxpacket 1988 drop_overlimit 0 new_flow_count 70 ecn_mark 0
  new_flows_len 1 old_flows_len 9

is seems goods ?

after deathmatch party cod

root@OpenWrt:~# tc -s qdisc
qdisc noqueue 0: dev lo root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 0: dev eth0 root refcnt 2 limit 10240p flows 1024 quantum 1514 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 47169224 bytes 125154 pkt (dropped 0, overlimits 0 requeues 7)
 backlog 0b 0p requeues 7
  maxpacket 3028 drop_overlimit 0 new_flow_count 270 ecn_mark 0
  new_flows_len 0 old_flows_len 0
qdisc noqueue 0: dev br-lan root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc hfsc 1: dev eth0.1 root refcnt 2 default 3
 Sent 556582 bytes 1532 pkt (dropped 0, overlimits 42 requeues 0)
 backlog 0b 0p requeues 0
qdisc pfifo 10: dev eth0.1 parent 1:2 limit 174p
 Sent 1183 bytes 8 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 3: dev eth0.1 parent 1:3 limit 866p flows 1024 quantum 3000 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 555070 bytes 1522 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
  maxpacket 3002 drop_overlimit 0 new_flow_count 440 ecn_mark 0
  new_flows_len 1 old_flows_len 4
qdisc hfsc 1: dev eth0.2 root refcnt 2 default 3
 Sent 43963 bytes 150 pkt (dropped 0, overlimits 15 requeues 0)
 backlog 0b 0p requeues 0
qdisc pfifo 10: dev eth0.2 parent 1:2 limit 57p
 Sent 1128 bytes 10 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 3: dev eth0.2 parent 1:3 limit 283p flows 1024 quantum 3000 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 42835 bytes 140 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
  maxpacket 1988 drop_overlimit 0 new_flow_count 70 ecn_mark 0
  new_flows_len 1 old_flows_len 9
root@OpenWrt:~# tc -s qdisc
qdisc noqueue 0: dev lo root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 0: dev eth0 root refcnt 2 limit 10240p flows 1024 quantum 1514 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 54783301 bytes 149845 pkt (dropped 0, overlimits 0 requeues 7)
 backlog 0b 0p requeues 7
  maxpacket 3028 drop_overlimit 0 new_flow_count 315 ecn_mark 0
  new_flows_len 0 old_flows_len 0
qdisc noqueue 0: dev br-lan root refcnt 2
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc hfsc 1: dev eth0.1 root refcnt 2 default 3
 Sent 6737979 bytes 16315 pkt (dropped 0, overlimits 290 requeues 0)
 backlog 0b 0p requeues 0
qdisc pfifo 10: dev eth0.1 parent 1:2 limit 174p
 Sent 4242699 bytes 9643 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 3: dev eth0.1 parent 1:3 limit 866p flows 1024 quantum 3000 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 2494951 bytes 6670 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
  maxpacket 4299 drop_overlimit 0 new_flow_count 1881 ecn_mark 0
  new_flows_len 0 old_flows_len 8
qdisc hfsc 1: dev eth0.2 root refcnt 2 default 3
 Sent 2454615 bytes 10058 pkt (dropped 0, overlimits 282 requeues 0)
 backlog 586b 1p requeues 0
qdisc pfifo 10: dev eth0.2 parent 1:2 limit 57p
 Sent 2153242 bytes 9194 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc fq_codel 3: dev eth0.2 parent 1:3 limit 283p flows 1024 quantum 3000 target 5.0ms interval 100.0ms memory_limit 4Mb ecn
 Sent 301373 bytes 864 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 586b 1p requeues 0
  maxpacket 4474 drop_overlimit 0 new_flow_count 283 ecn_mark 0 memory_used 2016
  new_flows_len 0 old_flows_len 4
root@OpenWrt:~#

:wink: now a last things i think for the boot script at the startup and we are finish ^^

1 Like

YAY now it's working. Now play game.

1 Like

it should work to just do:

echo "y" | /root/qosgaming.sh
1 Like

The big question is... how is the response? How well does your game feel? hitreg, lag, etc?

how does it feel if another machine does speed tests during game?

1 Like