100% found this document useful (2 votes)
242 views5 pages

Dynamic QoS Script for PPPoE

The document contains scripts for implementing Quality of Service (QoS) on a PPPoE connection in Mikrotik RouterOS. The script dynamically creates individual QoS rules when a PPPoE connection is established. It analyzes the queue settings for the user's connection and generates QoS queue tree rules with different priorities based on packet size. Packets are marked and prioritized into five categories: 0-512KB, 512KB-5MB, 5MB-20MB, 20MB-50MB, and 50MB+. The rules are removed when the PPPoE connection disconnects.

Uploaded by

cabunga2014
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
242 views5 pages

Dynamic QoS Script for PPPoE

The document contains scripts for implementing Quality of Service (QoS) on a PPPoE connection in Mikrotik RouterOS. The script dynamically creates individual QoS rules when a PPPoE connection is established. It analyzes the queue settings for the user's connection and generates QoS queue tree rules with different priorities based on packet size. Packets are marked and prioritized into five categories: 0-512KB, 512KB-5MB, 5MB-20MB, 20MB-50MB, and 50MB+. The rules are removed when the PPPoE connection disconnects.

Uploaded by

cabunga2014
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
  • QoS PPPOE Script
  • Funcionamento Explicação
  • Implementation Notes

QoS PPPoE

Script (adicionar em Systema Scripts)


-----------------------------------------------------------------
PPPoE UP
-----------------------------------------------------------------
:foreach i in=[/queue simple find where name="<pppoe-$user>"] do={
:local qName [/queue simple get $i name];
:local rLimit [/queue simple get $i max-limit];
:local indexExplod [:find $rLimit "/"];
:local lenth [:len $rLimit];
:local rl [:pick $rLimit ($indexExplod + 1) ($lenth - 1)];
:local rlUnity [:pick $rLimit ($lenth - 1) $lenth];
:local burstl [/queue simple get $i burst-limit];
:local indexExplod [:find $burstl "/"];
:local lenth [:len $burstl];
:local bl [:pick $burstl ($indexExplod + 1) ($lenth - 1)];
:local blUnity [:pick $burstl ($lenth - 1) $lenth];
:local burstt [/queue simple get $i burst-time];
:local indexExplod [:find $burstt "/"];
:local lenth [:len $burstt];
:local bt [:pick $burstt ($indexExplod + 1) ($lenth - 1)];
:local indexExplod [:find $bt "m"];
:local lenth [:len $bt];
:local bt0 [:pick $bt 0];
:local bt1 [:pick $bt ($indexExplod + 1) $lenth];
:local burstth [/queue simple get $i burst-threshold];
:local indexExplod [:find $burstth "/"];
:local lenth [:len $burstth];
:local bth [:pick $burstth ($indexExplod + 1) ($lenth - 1)];
:local bthUnity [:pick $burstth ($lenth - 1) $lenth];
:local c512k [($rl * 55 / 100)];
:local c5M [($rl * 25 / 100)];
:local c20M [($rl * 20 / 100)];
:local c50M [($rl * 15 / 100)];
:local cInf [($rl * 10 / 100)];
:local cBt [(($bt0 * 60) + $bt1)];
:if ([:len $bl] != 0) do={
:log warning "QoS ADD === $qName";
# :log warning "Com Burst";
# :log warning "Max Limit === $rl $rlUnity";
# :log warning "Burst Limit === $bl $blUnity";
# :log warning "Burst Thr === $bth $bthUnity";
# :log warning "Burst Time=== $cBt";
/queue tree add name="QoS_$qName" parent="$interface" queue="default" max-limit="$
($rl)$rlUnity" burst-limit="$($bl)$blUnity" burst-time="$cBt" burst-threshold="$
($bth)$bthUnity" bucket-size=0.20;
/queue tree add name="2-512k_$qName" parent="QoS_$qName" packet-mark="QoS-
512K" queue="default" priority="4" limit-at="$($c512k)$rlUnity" max-limit="$($rl)
$rlUnity" burst-limit="$($bl)$blUnity" burst-time="$cBt" burst-threshold="$($bth)
$bthUnity";
/queue tree add name="4-5M_$qName" parent="QoS_$qName" packet-mark="QoS-5M"
queue="default" priority="5" limit-at="$($c5M)$rlUnity" max-limit="$($rl)$rlUnity";
/queue tree add name="6-20M_$qName" parent="QoS_$qName" packet-mark="QoS-
20M" queue="default" priority="6" limit-at="$($c20M)$rlUnity" max-limit="$($rl)
$rlUnity";
/queue tree add name="7-50M_$qName" parent="QoS_$qName" packet-mark="QoS-
50M" queue="default" priority="7" limit-at="$($c50M)$rlUnity" max-limit="$($rl)
$rlUnity";
/queue tree add name="8-Inf_$qName" parent="QoS_$qName" packet-mark="QoS-
Infinity" queue="default" priority="8" limit-at="$($cInf)$rlUnity" max-limit="$
($rl)$rlUnity";
} \
else={
:log warning "QoS ADD === $qName";
/queue tree add name="QoS_$qName" parent="$interface" queue="default" max-
limit="$($rl)$rlUnity" bucket-size=0.20;
/queue tree add name="2-512k_$qName" parent="QoS_$qName" packet-mark="QoS-
512K" queue="default" priority="2" limit-at="$($c512k)$rlUnity" max-limit="$($rl)
$rlUnity";
/queue tree add name="4-5M_$qName" parent="QoS_$qName" packet-mark="QoS-5M"
queue="default" priority="4" limit-at="$($c5M)$rlUnity" max-limit="$($rl)$rlUnity";
/queue tree add name="6-20M_$qName" parent="QoS_$qName" packet-mark="QoS-
20M" queue="default" priority="6" limit-at="$($c20M)$rlUnity" max-limit="$($rl)
$rlUnity";
/queue tree add name="7-50M_$qName" parent="QoS_$qName" packet-mark="QoS-
50M" queue="default" priority="7" limit-at="$($c50M)$rlUnity" max-limit="$($rl)
$rlUnity";
/queue tree add name="8-Inf_$qName" parent="QoS_$qName" packet-mark="QoS-
Infinity" queue="default" priority="8" limit-at="$($cInf)$rlUnity" max-limit="$
($rl)$rlUnity";

}
}

---------------------------------------------------------
PPPoE DOWN
---------------------------------------------------------
/queue tree remove [find where parent="QoS_<pppoe-$user>"]
/queue tree remove [find where name="QoS_<pppoe-$user>"]
:foreach a in=[/queue tree find where invalid] do={ /queue tree remove $a };

Marcação dos pacotes - QoS

/ip firewall mangle


add action=mark-connection chain=forward comment=QOS_CLIENTES new-connection-
mark=QoS_conn_Down out-interface=all-ppp passthrough=yes
add action=mark-packet chain=forward connection-bytes=0-524288 connection-
mark=QoS_conn_Down new-packet-mark=QoS-512K passthrough=yes
add action=mark-packet chain=forward connection-bytes=524289-5242880 connection-
mark=QoS_conn_Down new-packet-mark=QoS-5M passthrough=yes
add action=mark-packet chain=forward connection-bytes=5242881-20971520 connection-
mark=QoS_conn_Down new-packet-mark=QoS-20M passthrough=yes
add action=mark-packet chain=forward connection-bytes=20971521-52428800 connection-
mark=QoS_conn_Down new-packet-mark=QoS-50M passthrough=yes
add action=mark-packet chain=forward connection-bytes=52428801-0 connection-
mark=QoS_conn_Down new-packet-mark=QoS-Infinity passthrough=yes

/////////////////////////////////////////////////// OUTRO
SCRIPT///////////////////////////////////////////////////////////////

PPoE - QoS Dinâmico e Individual


Prezados,
De uns tempo pra cá, vira e mexe recebemos ligações de clientes reclamando que não
conseguem acessar nada ou que está extremamente lento, e quando vamos ver a
conexão, o consumo de banda do cliente está em 100%.
Em 90% dos casos é com destino a IP da Microsoft, o que nos leva a crer ser
atualização.

Sendo que desde o lançamento do Windows 10, a quantidade de ligações desse tipo
aumentou.

Diante de tal problema, resolvi ir atrás de alguma solução de QoS individual e


automático.
Consegui achar alguns exemplos de scripts na internet, fiz algumas modificações
para poder gerar QoS automático para clientes com ou sem Burst.

O que ele faz?


A cada nova conexão, ele analisa os dados da Simple Queue desse cliente, e cria
algumas regras no Queue Tree, com 5 tipos de priorização, conforme o tamanho do
pacote (independente de site, protocolo ou serviço).

A principio tem funcionado bem.

Segue abaixo o script:

Código :

/ip firewall mangle


add action=mark-connection chain=forward comment=QoS-Andriopj_Client_PPPoE
new-connection-mark=QoS_conn_Down out-interface=all-ppp passthrough=yes
add action=mark-packet chain=forward connection-bytes=0-524288 connection-
mark=QoS_conn_Down new-packet-mark=QoS-Andriopj_512K passthrough=yes
add action=mark-packet chain=forward connection-bytes=524289-5242880
connection-mark=QoS_conn_Down new-packet-mark=QoS-Andriopj_5M passthrough=yes
add action=mark-packet chain=forward connection-bytes=5242881-20971520
connection-mark=QoS_conn_Down new-packet-mark=QoS-Andriopj_20M passthrough=yes
add action=mark-packet chain=forward connection-bytes=20971521-52428800
connection-mark=QoS_conn_Down new-packet-mark=QoS-Andriopj_50M passthrough=yes
add action=mark-packet chain=forward connection-bytes=52428801-0 connection-
mark=QoS_conn_Down new-packet-mark=QoS-Andriopj_Infinity passthrough=yes

Esse você adiciona em PPP > Profile


Abra cada um dos Profiles > aba Scripts > On Up
Código :

:foreach i in=[/queue simple find where name="<pppoe-$user>"] do={


:local NamePPP [/queue simple get $i name];
:local RateLimit [/queue simple get $i max-limit];
:local indexExplod [:find $RateLimit "/"];
:local lenth [:len $RateLimit];
:local rl [:pick $RateLimit ($indexExplod + 1) ($lenth - 1)];
:local RateLimitUn [:pick $RateLimit ($lenth - 1) $lenth];
:local BurstLimit [/queue simple get $i burst-limit];
:local indexExplod [:find $BurstLimit "/"];
:local lenth [:len $BurstLimit];
:local bl [:pick $BurstLimit ($indexExplod + 1) ($lenth - 1)];
:local BurstLimitUn [:pick $BurstLimit ($lenth - 1) $lenth];
:local BurstTime [/queue simple get $i burst-time];
:local indexExplod [:find $BurstTime "/"];
:local lenth [:len $BurstTime];
:local bt [:pick $BurstTime ($indexExplod + 1) ($lenth - 1)];
:local indexExplod [:find $bt "m"];
:local lenth [:len $bt];
:local bt0 [:pick $bt 0];
:local bt1 [:pick $bt ($indexExplod + 1) $lenth];
:local BurstTh [/queue simple get $i burst-threshold];
:local indexExplod [:find $BurstTh "/"];
:local lenth [:len $BurstTh];
:local bth [:pick $BurstTh ($indexExplod + 1) ($lenth - 1)];
:local BurstThUn [:pick $BurstTh ($lenth - 1) $lenth];
:local c512k [($rl * 55 / 100)];
:local c5M [($rl * 25 / 100)];
:local c20M [($rl * 20 / 100)];
:local c50M [($rl * 15 / 100)];
:local cInf [($rl * 10 / 100)];
:local cBt [(($bt0 * 60) + $bt1)];
:if ([:len $bl] != 0) do={
:log warning "QoS ADD === $NamePPP";
# :log warning "Com Burst";
# :log warning "Max Limit === $rl $RateLimitUn";
# :log warning "Burst Limit === $bl $BurstLimitUn";
# :log warning "Burst Thr === $bth $BurstThUn";
# :log warning "Burst Time=== $cBt";
/queue tree add name="QoS_$NamePPP" parent="$interface" queue="default" max-
limit="$($rl)$RateLimitUn" burst-limit="$($bl)$BurstLimitUn" burst-time="$cBt"
burst-threshold="$($bth)$BurstThUn" bucket-size=0.20;
/queue tree add name="2-512k_$NamePPP" parent="QoS_$NamePPP" packet-
mark="QoS-Andriopj_512K" queue="default" priority="4" limit-at="$($c512k)
$RateLimitUn" max-limit="$($rl)$RateLimitUn" burst-limit="$($bl)$BurstLimitUn"
burst-time="$cBt" burst-threshold="$($bth)$BurstThUn";
/queue tree add name="4-5M_$NamePPP" parent="QoS_$NamePPP" packet-
mark="QoS-Andriopj_5M" queue="default" priority="5" limit-at="$($c5M)$RateLimitUn"
max-limit="$($rl)$RateLimitUn";
/queue tree add name="6-20M_$NamePPP" parent="QoS_$NamePPP" packet-
mark="QoS-Andriopj_20M" queue="default" priority="6" limit-at="$($c20M)
$RateLimitUn" max-limit="$($rl)$RateLimitUn";
/queue tree add name="7-50M_$NamePPP" parent="QoS_$NamePPP" packet-
mark="QoS-Andriopj_50M" queue="default" priority="7" limit-at="$($c50M)
$RateLimitUn" max-limit="$($rl)$RateLimitUn";
/queue tree add name="8-Inf_$NamePPP" parent="QoS_$NamePPP" packet-
mark="QoS-Andriopj_Infinity" queue="default" priority="8" limit-at="$($cInf)
$RateLimitUn" max-limit="$($rl)$RateLimitUn";
} \
else={
:log warning "QoS ADD === $NamePPP";
/queue tree add name="QoS_$NamePPP" parent="$interface" queue="default"
max-limit="$($rl)$RateLimitUn" bucket-size=0.20;
/queue tree add name="2-512k_$NamePPP" parent="QoS_$NamePPP" packet-
mark="QoS-Andriopj_512K" queue="default" priority="2" limit-at="$($c512k)
$RateLimitUn" max-limit="$($rl)$RateLimitUn";
/queue tree add name="4-5M_$NamePPP" parent="QoS_$NamePPP" packet-
mark="QoS-Andriopj_5M" queue="default" priority="4" limit-at="$($c5M)$RateLimitUn"
max-limit="$($rl)$RateLimitUn";
/queue tree add name="6-20M_$NamePPP" parent="QoS_$NamePPP" packet-
mark="QoS-Andriopj_20M" queue="default" priority="6" limit-at="$($c20M)
$RateLimitUn" max-limit="$($rl)$RateLimitUn";
/queue tree add name="7-50M_$NamePPP" parent="QoS_$NamePPP" packet-
mark="QoS-Andriopj_50M" queue="default" priority="7" limit-at="$($c50M)
$RateLimitUn" max-limit="$($rl)$RateLimitUn";
/queue tree add name="8-Inf_$NamePPP" parent="QoS_$NamePPP" packet-
mark="QoS-Andriopj_Infinity" queue="default" priority="8" limit-at="$($cInf)
$RateLimitUn" max-limit="$($rl)$RateLimitUn";

}
}

-------------------------------------------------------------------------------

Esse você adiciona em PPP > Profile


Abra cada um dos Profiles > aba Scripts > On Down
Código :

/queue tree remove [find where parent="QoS_<pppoe-$user>"]


/queue tree remove [find where name="QoS_<pppoe-$user>"]
:foreach a in=[/queue tree find where invalid] do={ /queue tree remove $a };

-----------------------------------------------------------------------------------
-

Pronto, agora seu concentrador já deve estar criando o QoS automaticamente para
cada cliente que se conectar/reconectar.

Common questions

Powered by AI

The burst configurations in these scripts allow temporary bandwidth spikes by setting higher limits than the normal rate. This enables improved performance for applications requiring higher bandwidth and reduces bottlenecks during short-term high demand by setting parameters for burst limits, burst thresholds, and burst times .

Burst time in the QoS configuration is calculated using the burst time string, which is split into its major and minor components (minutes and seconds). The formula then converts this time into total seconds by taking the major component multiplied by 60 and adding the minor seconds, yielding a unified burst time duration applicable in the QoS settings .

The script automates QoS provisioning by dynamically analyzing the user's simple queue data upon each connection. It then applies predefined rules in the queue tree with different priority levels based on packet size, independent of the specific site or protocol. This allows the creation of tailored QoS settings for each connection without manual intervention .

The QoS scripts address the problem of bandwidth saturation caused by Windows 10 updates. Many users report slow network performance when updates are consuming maximum bandwidth. The scripts combat this by establishing QoS rules to limit bandwidth allocated to those updates, thereby maintaining available bandwidth for other concurrent user activities, reducing overall user experience latency during update periods .

The scripts address challenges of excessive bandwidth consumption, particularly issues where users experience slow connection speeds due to reaching their maximum allotted bandwidth. This is especially prevalent with large data transfers, such as Windows 10 updates. By assigning individualized and dynamic bandwidth management through QoS rules, the scripts help alleviate network congestion caused by simultaneous high-data demand .

Packet marking plays a crucial role in categorizing network traffic into various priority queues according to the connection byte size. This categorization allows the scripts to manage bandwidth dynamically, ensuring that smaller, latency-sensitive packets get more immediate attention, while larger packets are handled according to their assigned priorities. This system aids in balancing the load and optimizing the network for different data types .

Implementing dynamic and individual QoS allows network administrators to offer optimized and tailored bandwidth allocation per user, accommodating fluctuations in user demand without manual adjustments. It significantly improves network efficiency and user experience by dynamically adjusting QoS settings based on real-time analysis of each user's connection. This minimizes network congestion and maximizes resource usage, providing competitive advantages to administrators managing heavy or unpredictable traffic patterns .

The script calculates different bandwidth limits using preset percentages of a user's maximum rate limit (rl). These calculations include specific percentages assigned for different bandwidth categories: 55% for 512K connections, 25% for 5M, 20% for 20M, 15% for 50M, and 10% for infinity connections, all derived from the maximum rate limit specified for the user .

When a PPPoE connection goes down, the scripts systematically remove the QoS queue tree entries associated with that user. It identifies the queue trees with the specified parent linked to the user's QoS name and removes those entries. Additionally, it checks for and removes any invalid queue tree entries to maintain clean and efficient queue management .

The scripts implement traffic prioritization by using packet marking based on their size ranges. Connection bytes are marked with different priorities - from 512K up to infinity - allowing finer control over how each type of traffic is handled in the network's queue. This ensures that more critical traffic can be prioritized over less essential large bandwidth tasks, offering optimized performance for diverse user demands .

QoS PPPoE
Script (adicionar em Systema Scripts)
-----------------------------------------------------------------
PPPoE UP
--
/queue tree add name="8-Inf_$qName" parent="QoS_$qName" packet-mark="QoS-
Infinity" queue="default" priority="8" limi
De uns tempo pra cá, vira e mexe recebemos ligações de clientes reclamando que não 
conseguem acessar nada ou que está extrem
:local bt [:pick $BurstTime ($indexExplod + 1) ($lenth - 1)];
    :local indexExplod [:find $bt "m"];
    :local lenth [:
/queue tree add name="8-Inf_$NamePPP" parent="QoS_$NamePPP" packet-
mark="QoS-Andriopj_Infinity" queue="default" prio

You might also like