Community discussions

MikroTik App
 
IntrusDave
Forum Guru
Forum Guru
Topic Author
Posts: 1286
Joined: Fri May 09, 2014 4:36 am
Location: Rancho Cucamonga, CA

DSCP mangle and queue trees

Sat Jul 30, 2016 8:57 pm

More human readable creation of DSCP Mangles and Queue Tree.
Set the wanInterfaceName and uploadBandwidth. 
:local wanInterfaceName "wan0"
:local uploadBandwidth 4200k

:local queueName ("DSCP_" . $wanInterfaceName)
:local dscpClass [:toarray "Network Control,Internetwork Control,Critical,Flash Override,Flash,Immedate,Priority,Routine"]
:local dscp 64

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

/queue tree add max-limit=$uploadBandwidth name=$queueName parent=$wanInterfaceName priority=1

:for thisDscp from=0 to=7 do={
	:local subClass ([:pick $dscpClass $thisDscp] . " (" . $wanInterfaceName . ")")
	/queue tree add \ 
		name=($thisDscp+1 . ". " . $subClass ) parent=$queueName priority=($thisDscp+1) queue=ethernet-default
	:for thisQueue from=0 to=7 do={
		:set dscp ($dscp-1)
		/queue tree add name=($subClass . " (Pri: " . $thisQueue+1 .")") \
		parent=($thisDscp+1 . ". " . $subClass) priority=($thisQueue+1) \
		packet-mark=("dscp_" . $dscp) queue=ethernet-default comment=("dscp_" . $dscp)
	}
}
 
pe1chl
Forum Guru
Forum Guru
Posts: 10240
Joined: Mon Jun 08, 2015 12:09 pm

Re: DSCP mangle and queue trees

Sat Jul 30, 2016 9:23 pm

It may not be a good plan to create 64 mange rules that all have to be processed...
I normally use this trick to directly use the top 3 bits of the DSCP:

/ip firewall mangle
add action=set-priority chain=postrouting comment="From dscp high 3 bits" \
    new-priority=from-dscp-high-3-bits
add action=mark-packet chain=postrouting comment="Priority 0" \
    new-packet-mark=prio0 priority=0
add action=mark-packet chain=postrouting comment="Priority 1" \
    new-packet-mark=prio1 priority=1
add action=mark-packet chain=postrouting comment="Priority 2" \
    new-packet-mark=prio2 priority=2
add action=mark-packet chain=postrouting comment="Priority 3" \
    new-packet-mark=prio3 priority=3
add action=mark-packet chain=postrouting comment="Priority 4" \
    new-packet-mark=prio4 priority=4
add action=mark-packet chain=postrouting comment="Priority 5" \
    new-packet-mark=prio5 priority=5
add action=mark-packet chain=postrouting comment="Priority 6" \
    new-packet-mark=prio6 priority=6
add action=mark-packet chain=postrouting comment="Priority 7" \
    new-packet-mark=prio7 priority=7
 
IntrusDave
Forum Guru
Forum Guru
Topic Author
Posts: 1286
Joined: Fri May 09, 2014 4:36 am
Location: Rancho Cucamonga, CA

Re: DSCP mangle and queue trees

Sat Jul 30, 2016 9:37 pm

I don't think that is a good direction. If you have DSCP compliant hardware and apps, use DSCP. If you have simple hardware, use priorities. 
I suppose if you have a low end router, then you can use that. I use the script above on RB2011's and up with 150M WAN's without issue and a CPU load less than 5%
 
IntrusDave
Forum Guru
Forum Guru
Topic Author
Posts: 1286
Joined: Fri May 09, 2014 4:36 am
Location: Rancho Cucamonga, CA

Re: DSCP mangle and queue trees

Sat Jul 30, 2016 9:44 pm

Thanking about it - both ways work. I like the fine-grained control. Most of my routers that really need this are CCR's. I use the same on my home RB3011. 
 
pe1chl
Forum Guru
Forum Guru
Posts: 10240
Joined: Mon Jun 08, 2015 12:09 pm

Re: DSCP mangle and queue trees

Sat Jul 30, 2016 11:04 pm

I use this on a network to have different priorities for VoIP, normal and background traffic.
We mostly use only 3 DSCP values:
- Expedited Forwarding (2e) for VoIP traffic
- Normal (00) as a default
- Background (08) for background transfers like backups
But we have 8 queues in the queue tree to have some more room for future use

It works very well, VoIP is not affected at all by a backup running over the same link.
It is unfortunate that the queue tree cannot use "priority" value as a selector.   Plain Linux can do it, but RouterOS not.
So the tagging of priority values back to packet marks is required.
 
mjsabri
Trainer
Trainer
Posts: 109
Joined: Sat Dec 12, 2015 10:55 am

Re: DSCP mangle and queue trees

Sat Jul 30, 2016 11:14 pm

i think you Should use HTB for this work
 
IntrusDave
Forum Guru
Forum Guru
Topic Author
Posts: 1286
Joined: Fri May 09, 2014 4:36 am
Location: Rancho Cucamonga, CA

Re: DSCP mangle and queue trees

Sun Jul 31, 2016 1:20 am

i think you Should use HTB for this work
I believe the Queue Tree is HTB.
 
mjsabri
Trainer
Trainer
Posts: 109
Joined: Sat Dec 12, 2015 10:55 am

Re: DSCP mangle and queue trees

Sun Jul 31, 2016 8:27 am

Yes, it is.
 
User avatar
frank333
Member
Member
Posts: 330
Joined: Mon Dec 18, 2017 12:17 pm
Location: S.Marino Router model: RB3011UiAS-RM+RBM11G

Re: DSCP mangle and queue trees

Wed Jan 10, 2018 6:05 pm

beautiful script intrusDave!!!
  • it is correct to use the pppoe-out1 interface in wanInterfaceName when using a pppoeclient ?
  • My ISP gives me a 30megabits download/3megabits upload connection ,it is correct to write 3000k in uploadBandwidth, or the value should be reduced by 10%?



my conf
# jan/09/2018 01:58:09 by RouterOS 6.41
# software id = 
#
# model = RouterBOARD 3011UiAS
# serial number = 
/interface bridge
add admin-mac=xxxxx auto-mac=no comment=defconf name=bridge
/interface ethernet
set [ find default-name=ether1 ] bandwidth=30720k/3072k mac-address=\
    xxxxxxxxx name=ether1-WAN
set [ find default-name=ether2 ] name=ether2-LOCOM2
set [ find default-name=ether3 ] name=ether3-TV
set [ find default-name=ether4 ] name=ether4-SERVER
set [ find default-name=ether5 ] disabled=yes
set [ find default-name=ether6 ] disabled=yes
set [ find default-name=ether7 ] disabled=yes
set [ find default-name=ether8 ] disabled=yes
set [ find default-name=ether9 ] name=ether9-ROCKET
set [ find default-name=ether10 ] name=ether10-M900
set [ find default-name=sfp1 ] disabled=yes
/interface pppoe-client
add add-default-route=yes disabled=no interface=ether1-WAN name=pppoe-out1 \
    password=xxxxx use-peer-dns=yes user=xxxxx
/interface vlan
add interface=bridge name=vlan10 vlan-id=10
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
add exclude=dynamic name=discover
add name=mactel
add name=mac-winbox
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/ip dhcp-server option
add code=6 name=dnsantipub1 value="'xxx''xxxxx'"
add code=252 name=autoproxy value="'http://10.0.0.202/wpad.dat'"
/ip dhcp-server option sets
add name=wpad_dnsstop options=autoproxy,dnsantipub1
/ip firewall layer7-protocol
add comment="Siti bloccati" name=sitibloccati regexp="^.+(twitter.com|facebook\
    .com|skype.com|whatsapp.com|messenger.com|hangouts.google.com).*\$"
/ip pool
add name=dhcp ranges=10.0.0.100-10.0.0.254
add name=pool_vlan10 ranges=172.16.10.100-172.16.10.254
/ip dhcp-server
add address-pool=dhcp disabled=no interface=bridge lease-time=12h10m name=\
    defconf
 
 
Gombeen666
Member Candidate
Member Candidate
Posts: 224
Joined: Tue Jun 25, 2019 5:33 pm

Re: DSCP mangle and queue trees

Wed Feb 12, 2020 2:23 pm

I have a few questions and maybe some could comment?
(1) We have PPPoE Vlan's will DSCP or priorities work on that interface
(2) For Mikrotik CPE's that have public IP assigned is "DSCP" a better option
(3) Where CPE does not have public IP but is assigned to TP-link router connected to CPE ether interface is "Priorities" best
 
Gombeen666
Member Candidate
Member Candidate
Posts: 224
Joined: Tue Jun 25, 2019 5:33 pm

Re: DSCP mangle and queue trees

Thu Feb 13, 2020 6:40 pm

I use this on a network to have different priorities for VoIP, normal and background traffic.
We mostly use only 3 DSCP values:
- Expedited Forwarding (2e) for VoIP traffic
- Normal (00) as a default
- Background (08) for background transfers like backups
But we have 8 queues in the queue tree to have some more room for future use

It works very well, VoIP is not affected at all by a backup running over the same link.
It is unfortunate that the queue tree cannot use "priority" value as a selector.   Plain Linux can do it, but RouterOS not.
So the tagging of priority values back to packet marks is required.
I am trying to evaluate the best approach for CPE's and on reading https://wiki.mikrotik.com/wiki/DSCP_based_QoS_with_HTB which is informative, I also think that having 64 mangle rules
is a bit too much, can I ask what is your queue trees
 
Gombeen666
Member Candidate
Member Candidate
Posts: 224
Joined: Tue Jun 25, 2019 5:33 pm

Re: DSCP mangle and queue trees

Sat Feb 15, 2020 4:17 pm

How do I work around bridged VLAN's that carry the PPPoE interface on a CPE ?

Who is online

Users browsing this forum: No registered users and 40 guests