Generic DSCP based QoS with equal bandwidth distribution

Will this be an acceptable generic QoS solution, including VoIP? I am only interested in prioritizing in/out traffic without specifying bandwidth since this is hard to do, specially on busy city wireless links with a lot of wifis around or ADSL lines without any ISP speed warranty.

:for x from=0 to=63 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=("dscp-" . $x) passthrough=no}

:for x from=0 to=7 do={/queue tree add disabled=no name=("dscp-" . $x) packet-mark=("dscp-" . $x) parent=global-out priority=8}
:for x from=8 to=15 do={/queue tree add disabled=no name=("dscp-" . $x) packet-mark=("dscp-" . $x) parent=global-out priority=7}
:for x from=16 to=23 do={/queue tree add disabled=no name=("dscp-" . $x) packet-mark=("dscp-" . $x) parent=global-out priority=6}
:for x from=24 to=31 do={/queue tree add disabled=no name=("dscp-" . $x) packet-mark=("dscp-" . $x) parent=global-out priority=5}
:for x from=32 to=39 do={/queue tree add disabled=no name=("dscp-" . $x) packet-mark=("dscp-" . $x) parent=global-out priority=4}
:for x from=40 to=47 do={/queue tree add disabled=no name=("dscp-" . $x) packet-mark=("dscp-" . $x) parent=global-out priority=3}
:for x from=48 to=55 do={/queue tree add disabled=no name=("dscp-" . $x) packet-mark=("dscp-" . $x) parent=global-out priority=2}
:for x from=56 to=63 do={/queue tree add disabled=no name=("dscp-" . $x) packet-mark=("dscp-" . $x) parent=global-out priority=1}

Is there a way to also add to the above dynamic equal bandwidth distribution between users without specifying link speeds?

You’ll probably save some resources by using mangle rules to make only 8 unique packet-marks, and have 8 queues (one for each mark) rather than 64 queues.

I was afraid of that also but I have been monitoring the CPU/memory load in a 450G board and surprisingly it doesn’t seem to have added as much as I would expect it to. I would probably say that for the past couple of days I have been playing around, it added around 2-3% CPU time with very stable VoIP even at full download speeds (12/1MBit ADSL) but I haven’t extensively tested the above with busy mutliuser network links yet. The reason for that, I suppose, is that not much traffic uses DSCP so actually very few queues (5-10) of all 64s are practically used.

So far, there is virtually no CPU difference at all between the two setups for a home ADSL network but I suppose in a large network you are probably right and it would most likely make some difference depending on the DSCP usage.

:for x from=0 to=7 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-8 passthrough=no}
:for x from=8 to=15 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-7 passthrough=no}
:for x from=16 to=23 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-6 passthrough=no}
:for x from=24 to=31 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-5 passthrough=no}
:for x from=32 to=39 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-4 passthrough=no}
:for x from=40 to=47 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-3 passthrough=no}
:for x from=48 to=55 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-2 passthrough=no}
:for x from=56 to=63 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-1 passthrough=no}

:for x from=1 to=8 do={/queue tree add disabled=no name=("queue-" . $x) packet-mark=("priority-" . $x) parent=global-out priority=$x}

The question still remains though, how would I dynamically and evenly distribute bandwidth between users? Can it be done in addition to the above?

UPDATED scripts:

:for x from=63 to=56 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-1 passthrough=no}
:for x from=55 to=48 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-2 passthrough=no}
:for x from=47 to=40 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-3 passthrough=no}
:for x from=39 to=32 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-4 passthrough=no}
:for x from=31 to=24 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-5 passthrough=no}
:for x from=23 to=16 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-6 passthrough=no}
:for x from=15 to=8 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-7 passthrough=no}
:for x from=7 to=0 do={/ip firewall mangle add action=mark-packet chain=postrouting disabled=no dscp=$x new-packet-mark=priority-8 passthrough=no}

This time mangling is done in reverse order (63->0) so higher priority packets are first served.

I will also create 8 queues per interface this time:

:for x from=1 to=8 do={/queue tree add disabled=no name=("queue-" . $x) packet-mark=("priority-" . $x) parent=ether1 priority=$x}
:for x from=9 to=16 do={/queue tree add disabled=no name=("queue-" . $x) packet-mark=("priority-" . ($x-8)) parent=wlan1 priority=($x-8)}
:for x from=17 to=24 do={/queue tree add disabled=no name=("queue-" . $x) packet-mark=("priority-" . ($x-16)) parent=wlan2 priority=($x-16)}

etc if you have more interfaces

In case you want to limit the bandwidth this can be very easily done by creating a master queue for each interface with 8 child ones:

/queue tree add disabled=no name=outgoing parent=pppoe-out priority=1 max-limit=950000
:for x from=1 to=8 do={/queue tree add disabled=no name=("queue-" . $x) packet-mark=("priority-" . $x) parent=outgoing priority=$x}

A similar aproatch can be followed in order to distribute bandwidth evenly by creating a pcq master queue.
http://www.mikrotik.com/testdocs/ros/3.0/qos/queue.php