newspaint

Documenting Problems That Were Difficult To Find The Answer To

Prioritising VoIP on OpenWRT/OpenLEDE

Following the advice at the Network Traffic Control (QOS) page on the OpenWRT wiki I installed the tc package:

opkg install tc
opkg install kmod-sched-core

I wanted to set up 4 queues:

  ---[traffic to Australian Phone Company]---
                                             \
  ---[tiny packets <64 bytes]-----------------> router ---[ADSL]--- ISP
                                             /
  ---[small packets <256 bytes]-------------/
                                           /
  ---[everything else]---------------------

I needed a root qdisc with no limitations on it, and a top-level class with a maximum bandwidth of the upload speed to my ISP (around 1,400 kilobits per second).

Beneath this I set up 4 classes with differing priorities and each with a guaranteed minimum bandwidth of 100 kilobits per second each.

#!/bin/sh

DEV=pppoe-adsl
BWMAX=1400kbit

# ensure 32-bit classifier is available
insmod cls_u32
# ensure HTB scheduler is available
insmod sch_htb

echo "Clearing existing root qdisc on $DEV"
tc qdisc del dev $DEV root

echo "Adding root qdisc on $DEV"
tc qdisc add dev $DEV root       handle 1:    htb default 99

echo "Adding top class on $DEV with rate $BWMAX"
tc class add dev $DEV parent 1:  classid 1:1  htb rate $BWMAX ceil $BWMAX burst 6k


# Classes
echo "Creating VoIP class"
tc class add dev $DEV parent 1:1 classid 1:10 htb rate 100kbit ceil $BWMAX burst 6k prio 1

echo "Creating tiny packet class <64 bytes"
tc class add dev $DEV parent 1:1 classid 1:20 htb rate 100kbit ceil $BWMAX burst 6k prio 1

echo "Creating small packet class <256 bytes"
tc class add dev $DEV parent 1:1 classid 1:30 htb rate 100kbit ceil $BWMAX burst 6k prio 3

echo "Creating default class"
tc class add dev $DEV parent 1:1 classid 1:99 htb rate 100kbit ceil $BWMAX burst 6k prio 6


# Filters
echo "Creating VoIP filter to Australian Phone Company only (highest priority traffic)"
tc filter add dev $DEV parent 1: protocol ip prio 2 u32 match ip dst 103.12.10.97/32 flowid 1:10

echo "Creating tiny packet filter <64 bytes (for acknowledgements)"
echo "  allows bottom 6 bits to be anything (2^6 = 64) but all higher bits must be zero"
tc filter add dev $DEV parent 1: protocol ip prio 3 u32 match u16 0x0000 0xffc0 at 2 flowid 1:20

echo "Creating small packet filter <256 bytes (for traffic more likely to be real-time)"
echo "  allows bottom 8 bits to be anything (2^8 = 256) but all higher bits must be zero"
tc filter add dev $DEV parent 1: protocol ip prio 4 u32 match u16 0x0000 0xff00 at 2 flowid 1:30

Viewing the state of the system was straight-forward.

Seeing how many bytes and packets made it through the root qdisc:

# tc -s qdisc show dev $DEV
qdisc htb 1: root refcnt 2 r2q 10 default 99 direct_packets_stat 0 direct_qlen 3
 Sent 20016888 bytes 166952 pkt (dropped 175, overlimits 1496 requeues 0) 
 backlog 0b 0p requeues 0

I could also view the classes to see how many packets had made their way through each one:

# tc -s class show dev $DEV
class htb 1:1 root rate 1400Kbit ceil 1400Kbit burst 6Kb cburst 1599b 
 Sent 20154394 bytes 167785 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
 lended: 6096 borrowed: 0 giants: 0
 tokens: 544990 ctokens: 139271

class htb 1:10 parent 1:1 prio 1 rate 100Kbit ceil 1400Kbit burst 6Kb cburst 1599b 
 Sent 218765 bytes 394 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
 lended: 394 borrowed: 0 giants: 0
 tokens: 6248750 ctokens: 40610

class htb 1:20 parent 1:1 prio 1 rate 100Kbit ceil 1400Kbit burst 6Kb cburst 1599b 
 Sent 5800369 bytes 112832 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
 lended: 109430 borrowed: 3402 giants: 0
 tokens: 7630000 ctokens: 139271

class htb 1:30 parent 1:1 prio 3 rate 100Kbit ceil 1400Kbit burst 6Kb cburst 1599b 
 Sent 4727569 bytes 40204 pkt (dropped 16, overlimits 0 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
 lended: 38041 borrowed: 2163 giants: 0
 tokens: 7586250 ctokens: 136146

class htb 1:99 parent 1:1 prio 6 rate 100Kbit ceil 1400Kbit burst 6Kb cburst 1599b 
 Sent 9407691 bytes 14355 pkt (dropped 159, overlimits 0 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
 lended: 13824 borrowed: 531 giants: 0
 tokens: 6747500 ctokens: 76235

Actually class 1:99 is displayed first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: