playing with TOS vs. DiffServ bits


Re-compile your kernel for enabling the ALTQ options.


Evaluate maximum bandwidth by means of physical device capability

dmesg | grep ^vioif
dmesg | grep ^xennet

and against some network path (another network vs public) to take intermediate hops into account including modems

By means of FTP (choose your closest mirror)

export PKG_PATH=
#export PKG_PATH=
export PASSIVE_FTP=yes
ftp -a $PKG_PATH

By means of iPerf

pkg_add -v iperf3
pkg_info | grep iperf3

Routing & ECN

sysctl -w net.inet.ip.forwarding=1      
sysctl -w net.inet6.ip6.forwarding=1
sysctl -w net.inet.tcp.ecn.enable=1  

cat >> /etc/sysctl.conf <<-EOF

Setting up ALTQ

Start with a very low overall bandwidth just for testing. Here PRIQ for simplicity. ICMP and UDP priority, from 0 to 15, the latter being the highest priority. Choose your protocol number^ipnum carefully.

vi /etc/altq.conf # new file

interface xennet0 bandwidth xxxK priq
class priq xennet0 classicmp NULL priority 14
class priq xennet0 classudp NULL priority 13
class priq xennet0 classlow NULL priority 0 default
filter xennet0 classicmp 0 0 0 0 1
filter xennet0 classudp 0 0 0 0 0 17

interface xennet1 bandwidth xxxK priq
class priq xennet1 classicmp NULL priority 14
class priq xennet1 classudp NULL priority 13
class priq xennet1 classlow NULL priority 0 default
filter xennet1 classicmp 0 0 0 0 1
filter xennet1 classudp 0 0 0 0 17

Now if you tag the packets from another router or yourself, using a conditioner, eventually get rid of the protocol number (write 0 instead) and add the tos keyword and value to further classify your network stream. Beware about ToS vs. DiffServ.

ICMP -- 1
TCP -- 6
UDP -- 17

tos -- 0x10
tos -- 0x60
tos -- 0x

The manual says that class name must be unique per interface, this means we can use same name for differents interfaces.

echo altqd=yes >> /etc/rc.conf
/etc/rc.d/altqd start


ALTQ provides some statistics by itself

altqstat -i xennet0
altqstat -i xennet1

TCP first

iperf3 --time 0 -c x.x.x.x

meanwhile UDP

iperf3 --time 0 -u -c x.x.x.x -p 5202

then ICMP

ping -f x.x.x.x

You might need to change the UDP bandwidth manually, see the iperf3 manual. Also notice there are two more columns with the UDP output of iperf3.

Additional notes


tcpdump -i NETIF host ENDPOINT -vvv

Alternatives to iPerf3

pkgsrc -- net/netperf
pkgsrc -- net/aria2



QoS Resources


Public iPerf3 servers

Public Iperf3 servers


Protocol Numbers

altqd traffic shaping example

altq.conf – ALTQ configuration file

ALTQ: Alternate Queueing for BSD UNIX (version 3.1)


(deprecated –> NPF)



ping – send ICMP ECHO_REQUEST packets to network hosts –> Flood

Change between iPerf 2.0, iPerf 3.0 and iPerf 3.1 –> Setting DSCP/TOS bit vectors (-S)

iPerf 3 user documentation –> -S, –tos n

benchmarks/netperf - The NetBSD Packages Collection

net/aria2 - The NetBSD Packages Collection

List of IP protocol numbers