Skip to content

Instantly share code, notes, and snippets.

@raphielscape
Created March 21, 2020 16:01
Show Gist options
  • Save raphielscape/ef9599710a0e798c9feda20cd1af2529 to your computer and use it in GitHub Desktop.
Save raphielscape/ef9599710a0e798c9feda20cd1af2529 to your computer and use it in GitHub Desktop.
Priority-based Quality of Service Service for Mikrotik Routerboard
#Set interface here
:local inboundInterface "bridge1"
:local outboundInterface "ether1"
#Set bandwidth of outgoing interface
:local ingoingInterfaceBandwidth '1000M'
#Set bandwidth of ingoing interface
:local outgoingInterfaceBandwidth '1000M'
#Set where in the chain the packets should be mangled
:local mangleChain "postrouting"
#Set Queue for inbound interface
:local inpacketQueue "pcq-upload-default"
#Set Queue for outbound interface
:local outpacketQueue "pcq-download-default"
#Don't mess with these. They set the parameters for what is to follow
:local outqueueName ("QoS_" . $outboundInterface)
:local inqueueName ("QoS_" . $inboundInterface)
:local qosClasses [:toarray "Network Control,Internetwork Control,Critical,Flash Override,Flash,Immedate,Priority,Routine"]
/ip firewall mangle add action=set-priority \
chain=$mangleChain new-priority=from-dscp-high-3-bits \
passthrough=yes comment="Respect DSCP tagging"
/ip firewall mangle add action=set-priority \
chain=$mangleChain priority=0 new-priority=8 \
passthrough=yes comment="Set Pri 8 on packets with no Priority"
/ip firewall mangle add action=set-priority \
chain=$mangleChain dscp=0 new-priority=8 \
passthrough=yes comment="Set Pri 8 on packets with no DSCP"
:for indexA from 0 to 7 do={
/ip firewall mangle add action=mark-packet chain=$mangleChain comment=("pri_" . $indexA+1) \
disabled=no priority=($indexA+1) new-packet-mark=("priority_" . $indexA+1) passthrough=no
}
/queue tree add max-limit=$outgoingInterfaceBandwidth name=$outqueueName parent=$outboundInterface priority=1
:for indexA from=0 to=7 do={
:local subClass ([:pick $qosClasses $indexA] )
/queue tree add \
name=($indexA+1 . ". " . $subClass . " - " . $outboundInterface ) \
parent=$outqueueName \
priority=($indexA+1) \
queue=$inpacketQueue \
packet-mark=("priority_" . $indexA+1) \
comment=("Priority " . $indexA+1 . " traffic")
}
/queue tree add max-limit=$ingoingInterfaceBandwidth name=$inqueueName parent=$inboundInterface priority=1
:for indexA from=0 to=7 do={
:local subClass ([:pick $qosClasses $indexA] )
/queue tree add \
name=($indexA+1 . ". " . $subClass . " - " . $inboundInterface ) \
parent=$inqueueName \
priority=($indexA+1) \
queue=$outpacketQueue \
packet-mark=("priority_" . $indexA+1) \
comment=("Priority " . $indexA+1 . " traffic")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment