In our FreePBX installs, we use the following upstream shaper based on DSCP markings. Modify the bandwidth and DSCP marking values as necessary for the site. Note that shaping traffic will disable offload on that direction of traffic. You can also use this shaper for UniFi environments by using config.gateway.json.
set traffic-policy shaper Upstream description "Upstream QoS policy"
set traffic-policy shaper Upstream bandwidth 100mbit
set traffic-policy shaper Upstream class 10 description "RTP"
set traffic-policy shaper Upstream class 10 bandwidth 10%
set traffic-policy shaper Upstream class 10 burst 15k
set traffic-policy shaper Upstream class 10 ceiling 100%
set traffic-policy shaper Upstream class 10 match VOIP-RTP ip dscp 46
set traffic-policy shaper Upstream class 10 priority 0
set traffic-policy shaper Upstream class 10 queue-type fair-queue
set traffic-policy shaper Upstream class 20 description "SIP"
set traffic-policy shaper Upstream class 20 bandwidth 10%
set traffic-policy shaper Upstream class 20 burst 15k
set traffic-policy shaper Upstream class 20 ceiling 100%
set traffic-policy shaper Upstream class 20 match VOIP-SIP ip dscp 24
set traffic-policy shaper Upstream class 20 priority 1
set traffic-policy shaper Upstream class 20 queue-type fair-queue
set traffic-policy shaper Upstream default bandwidth 90%
set traffic-policy shaper Upstream default ceiling 100%
Apply the policy to the internet interface.
set interfaces ethernet ethX traffic-policy out Upstream
In our usual deployments we don't shape downstream traffic, as it's typically counterproductive in an asynchronous or high bandwidth environment. However in some cases it's helpful, for instance with low bandwidth circuits. Use the script below to implement QoS on the downstream.
set traffic-policy shaper Downstream description "Downstream QoS policy"
set traffic-policy shaper Downstream bandwidth 100mbit
set traffic-policy shaper Downstream class 10 description "RTP"
set traffic-policy shaper Downstream class 10 bandwidth 10%
set traffic-policy shaper Downstream class 10 burst 15k
set traffic-policy shaper Downstream class 10 ceiling 100%
set traffic-policy shaper Downstream class 10 match VOIP-RTP ip dscp 46
set traffic-policy shaper Downstream class 10 priority 0
set traffic-policy shaper Downstream class 10 queue-type fair-queue
set traffic-policy shaper Downstream class 20 description "SIP"
set traffic-policy shaper Downstream class 20 bandwidth 10%
set traffic-policy shaper Downstream class 20 burst 15k
set traffic-policy shaper Downstream class 20 ceiling 100%
set traffic-policy shaper Downstream class 20 match VOIP-SIP ip dscp 24
set traffic-policy shaper Downstream class 20 priority 1
set traffic-policy shaper Downstream class 20 queue-type fair-queue
set traffic-policy shaper Downstream default bandwidth 90%
set traffic-policy shaper Downstream default ceiling 100%
Create an input interface, assign the shaper to the input and redirect the downstream to the input interface.
set interfaces ifb0 description "Downstream Input for QoS"
set interfaces ifb0 traffic-policy out Downstream
set interfaces ethernet ethX redirect ifb0
Additionally the smart queue feature works well, another alternative is to set it up on the Upstream interface. Here are optimizations for various bandwidth levels:
# 100mbps up
set traffic-control smart-queue QoS upload fq-quantum 1514
set traffic-control smart-queue QoS upload htb-quantum 8000
set traffic-control smart-queue QoS upload target 5ms
# 70mbps up
set traffic-control smart-queue QoS upload fq-quantum 1514
set traffic-control smart-queue QoS upload htb-quantum 5000
set traffic-control smart-queue QoS upload target 5ms
# 40mbps or less
set traffic-control smart-queue QoS upload fq-quantum 300
set traffic-control smart-queue QoS upload htb-quantum 1500
set traffic-control smart-queue QoS upload target 5ms
# 3mbps or less
set traffic-control smart-queue QoS upload fq-quantum 300
set traffic-control smart-queue QoS upload htb-quantum 1500
set traffic-control smart-queue QoS upload target 15ms
To troubleshoot your QoS implementation you can use the following commands:
sudo tc -s qdisc ls dev ethX
sudo tc -s class show dev ethX
DSCP reference chart: