Community discussions

MikroTik App
 
User avatar
danz9370
just joined
Topic Author
Posts: 22
Joined: Sun Mar 27, 2005 1:21 pm
Location: Philippines
Contact:

PPPoE user script (ala F.A.P) Fair Access Policy

Thu Oct 19, 2006 1:41 am

here's another script for PPPoE users

This script will drop the user's download speed by 1/4 of it's assigned speed.

i.e. if a user is assigned of 128000/256000 then the 256000 is divided intto 4 and it will be deducted from the download speed.

i.e 256000 / 4 = 64000

256000 - 64000 = 192000

Hence, the new speed is now 128000/192000

Here how it works.

the PPPoE user was originally assigned of 128000/512000 bandwidth, in less than 30 minutes of online time, the user already downloaded a size of more than 10MB, the script will reduce his speed down to 128000/384000.

the same user was now online for more 30 minutes but less than 1 hour and downloaded more than 15MB, the speed will now be reduced to 128000/288000


again, the same user is now online for more than 1 hour but less than 5 hour and downloaded more than 50mb, the speed will now be dropped to
128000/216000

you can expand the code to reduced more based on your FAP policy.

i hope you liked it!.

:foreach i in=[/ppp active find] \

   do= { \
       
       :set sName [/interface get $i name]
       :set sTotalBytes [/queue simple get $sName total-bytes] ; \
       :set sUptime [/ppp active get $i uptime]

       :set mLimit [/queue simple get $sName max-limit]
       :set slashpos [:pic [:find $mLimit "/"]]
       :set mdSize [:pic $mLimit [:tonum(([:tonum($slashpos)] +1))] 30] 
       :set mPart ([:pic $mLimit [:tonum(([:tonum($slashpos)] +1))] 30] / 4)
       :set muSize [:pic $mLimit 0 $slashpos]

      :if ($sUptime < 30m && $sTotalBytes >10240000) \

          do={ \
                 :set NewSpeed ($muSize . "/" . ($mdSize - $mPart))                         
                 :log info ("SPEED " . $sName . " exceeds 10 Mega Bytes and has been online for " . $sUptime . " reducing speed to " . $NewSpeed )
                 /queue simple set $sName  limit-at=$NewSpeed max-limit=$NewSpeed
                  :log info ("SPEED " . $sName . " Total Download:" . [:tostr($sTotalBytes)] . "  and has been online for " . $sUptime )
                }


       :if ( $sUptime >30m && $sUptime < 1h && $sTotalBytes >15360000) \

          do={ \
                 :set NewSpeed ($muSize . "/" . ($mdSize - $mPart))                         
                 :log info ("SPEED " . $sName . " exceeds 15 Mega Bytes and has been online for " . $sUptime . " reducing speed to " . $NewSpeed )
                 /queue simple set $sName  limit-at=$NewSpeed max-limit=$NewSpeed
                :log info ("SPEED " . $sName . " Total Download:" . [:tostr($sTotalBytes)] . "  and has been online for " . $sUptime )
                }
                


       :if ( $sUptime >1h && $sUptime < 5h && $sTotalBytes > 51200000) \

          do={ \
                 :set NewSpeed ($muSize . "/" . ($mdSize - $mPart))                         
                 :log info ("SPEED " . $sName . " exceeds 50 Mega Bytes and has been online for " . $sUptime . " reducing speed to " . $NewSpeed )
                 /queue simple set $sName  limit-at=$NewSpeed max-limit=$NewSpeed
                  :log info ("SPEED " . $sName . " Total Download:" . [:tostr($sTotalBytes)] . "  and has been online for " . $sUptime )
                }

         }

any comments are welcome.
 
User avatar
ahmedramze
Member Candidate
Member Candidate
Posts: 111
Joined: Mon Feb 21, 2005 9:29 am
Location: IRAQ
Contact:

Thu Oct 19, 2006 12:01 pm

Can you Help Me If you have a Script that divide the bandwidth betwen users

for Example

I have 128/256 total band
when 1 user log in (( PPPOE or HotSpote )) His Limited will be 128/256
and 2 user log in them band will be Divide in to 64/128 for each one

I want the users to use the band when a few number online

Regard
 
User avatar
danz9370
just joined
Topic Author
Posts: 22
Joined: Sun Mar 27, 2005 1:21 pm
Location: Philippines
Contact:

Thu Oct 19, 2006 2:51 pm

Can you Help Me If you have a Script that divide the bandwidth betwen users

for Example

I have 128/256 total band
when 1 user log in (( PPPOE or HotSpote )) His Limited will be 128/256
and 2 user log in them band will be Divide in to 64/128 for each one

I want the users to use the band when a few number online

Regard
you can use the queue tree instead
 
Ozelo
Member
Member
Posts: 338
Joined: Fri Jun 02, 2006 3:56 am

Wed Oct 25, 2006 1:40 am

Interesting script, I would like to know if it works with dynamic simple queues that are added when receiving rate limit from radius. I mean, could it get changed to grab some info from radius and store it somewhere or perhaps, will the script change the rate limit on a dynamic simple queue or it only applys on static ones?

i.e.: Lets consider that a user that connect and receive rate limit from radius is a normal user and should have a dynamic simple queue. So, I decide to have some "special" users on my pppoe ac that may receive or not, some other parameter from radius (possibly a different rate limit than the normal users received). I would like to run a script every day at 10pm that indentify these special users and double its rate limit. Another script reverse these to their normal usage at 6am.

Sounds perfectly possible to use your script for that, dont you think? I would like to test the idea soon, if you didnt have done it already. ;) Thank you.
 
User avatar
ahmedramze
Member Candidate
Member Candidate
Posts: 111
Joined: Mon Feb 21, 2005 9:29 am
Location: IRAQ
Contact:

Wed Oct 25, 2006 10:07 am

you can use the queue tree instead
More Explain Please
 
User avatar
danz9370
just joined
Topic Author
Posts: 22
Joined: Sun Mar 27, 2005 1:21 pm
Location: Philippines
Contact:

Wed Oct 25, 2006 12:49 pm

Interesting script, I would like to know if it works with dynamic simple queues that are added when receiving rate limit from radius. I mean, could it get changed to grab some info from radius and store it somewhere or perhaps, will the script change the rate limit on a dynamic simple queue or it only applys on static ones?

i.e.: Lets consider that a user that connect and receive rate limit from radius is a normal user and should have a dynamic simple queue. So, I decide to have some "special" users on my pppoe ac that may receive or not, some other parameter from radius (possibly a different rate limit than the normal users received). I would like to run a script every day at 10pm that indentify these special users and double its rate limit. Another script reverse these to their normal usage at 6am.

Sounds perfectly possible to use your script for that, dont you think? I would like to test the idea soon, if you didnt have done it already. ;) Thank you.
i am using a windows radius server (vircom), and yes, the script can change users speed assigned by the radius server. it is 100% working with dynamic simple queue.

you can enhance the script if you want to, the script is your base script.
 
Ozelo
Member
Member
Posts: 338
Joined: Fri Jun 02, 2006 3:56 am

Wed Oct 25, 2006 4:17 pm

It is working so great! nice! :) But there is something that called my attention and I didnt figure how to acomplish better: When should I run the script.

How do you run yours? I mean, I could run my script every day at 11pm to check if there are special users and then change their speed. But, if the user connects after 11pm, they get the default special speed. So, I should run the script every minute after 11pm until 6am. Is there a way possible to run the script when the users do the connection instead run the script scheduled?

Thank you!
 
User avatar
danz9370
just joined
Topic Author
Posts: 22
Joined: Sun Mar 27, 2005 1:21 pm
Location: Philippines
Contact:

Fri Oct 27, 2006 1:18 am

It is working so great! nice! :) But there is something that called my attention and I didnt figure how to acomplish better: When should I run the script.

How do you run yours? I mean, I could run my script every day at 11pm to check if there are special users and then change their speed. But, if the user connects after 11pm, they get the default special speed. So, I should run the script every minute after 11pm until 6am. Is there a way possible to run the script when the users do the connection instead run the script scheduled?

Thank you!
well, i ran mine every 10 minutes, but in your case, you could probably copy the script to a new one and run it every 5 or 10 minutes after 11pm. in other words, you have two identical script but run at different time and interval.
 
Ozelo
Member
Member
Posts: 338
Joined: Fri Jun 02, 2006 3:56 am

Mon Oct 30, 2006 10:27 pm

Heres what I did, maybe it could be better designed. Ive setup a scheduled script called "special_mode_control" to run every minute and here is the code:
:set sTime [:pic [/system clock get time] 0 2]
:if (($sTime >= "22" && $sTime <= "23") || ($sTime >= "00" && $sTime < "06")) do={ \
:if ([/system scheduler get continous_special disabled]) do={
:log info "STARTING SPECIAL MODE"
/system scheduler set continous_special disabled=no
}
}
:if ($sTime >= "06" && $sTime <= "06") do={ \
:if ([/system scheduler get continous_special disabled] = false) do={
:log info "STARTING NORMAL MODE"
/system scheduler set continous_special disabled=yes
/system script run do_normal
}
}
Then, at 10pm and before 06am it enable another scheduled script every minute. Heres the code:
:set mCnt 0
:foreach i in=[/queue simple find] do= { \
:if ([/queue simple get $i max-limit] = "67000/67000") do={ \
/queue simple set $i max-limit="127000/127000" limit-at="127000/127000" burst-limit=512000/512000 burst-threshold=256000/256000 burst-time=8s/8s
:set mCnt ($mCnt + 1)
}
:if ([/queue simple get $i max-limit] = "129000/129000") do={ \
/queue simple set $i max-limit="255000/255000" limit-at="255000/255000" burst-limit=1024000/1024000 burst-threshold=512000/512000 burst-time=8s/8s
:set mCnt ($mCnt + 1)
}
}
:if ($mCnt > 0) do={ :log info ("do_special: " . $mCnt . " clients added to the special mode") }
Finally, the "special_mode_control" script disable the "continous_special" scheduled script at 6am and run once the "do_normal" script, geting all special mode clients back to normal until 10pm. Heres the code to do the "do_normal" script:
:set mCnt 0
:foreach i in=[/queue simple find] do= { \
:if ([/queue simple get $i max-limit] = "127000/127000") do={ \
/queue simple set $i max-limit="67000/67000" limit-at="67000/67000" burst-limit=250000/250000 burst-threshold=128000/128000 burst-time=8s/8s
:set mCnt ($mCnt + 1)
}
:if ([/queue simple get $i max-limit] = "255000/255000") do={ \
/queue simple set $i max-limit="129000/129000" limit-at="129000/129000" burst-limit=512000/512000 burst-threshold=256000/256000 burst-time=8s/8s
:set mCnt ($mCnt + 1)
}
}
:if ($mCnt > 0) do={ :log info ("do_normal: " . $mCnt . " clients back to normal mode") }
So far, it do the job. :) Thank you.
 
ener
Frequent Visitor
Frequent Visitor
Posts: 62
Joined: Fri May 10, 2013 4:47 pm

Re: PPPoE user script (ala F.A.P) Fair Access Policy

Tue May 21, 2013 11:53 am

where can i input the scripts? is it in MT or in my Daloradius? by the way im using dalo radius..

Who is online

Users browsing this forum: No registered users and 13 guests