You are on page 1of 2

#QoS PPPoE

#Script (adicionar em Systema Scripts)


#-----------------------------------------------------------------
#Crear dos scripts este sería el 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";

}
}

#FIN DEL SCRIPT 1 (up)

#---------------------------------------------------------
#PPPoE DOWN INICIO DEL SCRIPT 2 (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 };
#FIN DEL SCRIPT 2 (down)

#---------------------------------------------------------
#Marcado de Paquetes - 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

#Ahora deben colocarlos según corresponda en /PPP Profile Scripts On Up (up), On Down (down)
Raul Cespedes Ichazo

You might also like