Community discussions

 
User avatar
promind
Member Candidate
Member Candidate
Topic Author
Posts: 153
Joined: Thu Feb 23, 2006 11:26 am
Location: Rousse, Bulgaria
Contact:

how to change dynamic queues

Thu Mar 13, 2008 10:21 am

Here is how I do it:
1. Create table clients where nas info is stored:
DROP TABLE IF EXISTS `clients`;
CREATE TABLE `clients` (
`cid` int(2) NOT NULL auto_increment,
`client` varchar(15) NOT NULL default '0.0.0.0',
`secret` varchar(32) NOT NULL default '*',
`shortname` varchar(32) NOT NULL default '',
`nastype` varchar(32) NOT NULL default '',
PRIMARY KEY (`cid`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
1.1. I'm using customized database of freeradius with different module, but you can suit it to your needs.
In groups table create field Mikrotik-Rate-Limit and Night-Mikroti-Rate-Limit,
Differ your shapes as you want 1:2 or 1:1.5 etc...
Add a script that will execute this at a certain time containing:
#!/bin/sh
/usr/bin/mysql -uradius -ppwd radius -e "alter table "yourgrouptable" change MikroTik-Rate-Limit back_rate_limit varchar(64) NOT NULL DEFAULT '0';"
/usr/bin/mysql -uradius -ppwd radius -e "alter table "yourgrouptable" change Night-Mikroti-Rate-Limit Mikroti-Rate-Limit varchar(64) NOT NULL DEFAULT '0';"
/usr/bin/mysql -uradius -ppwd radius -e "alter table "yourgrouptable" change back_rate_limit Night-Mikroti-Rate-Limit varchar(64) NOT NULL DEFAULT '0';"

2. Create php script that gathers MikroTik named NASes/it can be done with 1 script but I prefer 2/ which will be executed right after the table fields change
#!/usr/bin/php -q
<?php
mysql_connect("localhost", "radius", "radpwd") or
die("Could not connect: " . mysql_error());
mysql_select_db("radius");

$query = "SELECT client from clients where nastype='MikroTik'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$client = $row[0];
system("/usr/bin/php -q /etc/ppp/temp/shape-mt.php $client");
}
mysql_free_result($result);
?>
3. Create shape-mt.php script that handles the shapings:
mysql_connect("localhost", "radius", "radpwd") or
die("Could not connect: " . mysql_error());
mysql_select_db("radius");

$ras = $argv[1];

$query = "SELECT Framed-User, MikroTik-Rate-Limit from "your online table" INNER JOIN "yourgrouptable" ON "your online table".groupid="yourgroutable".groupid where "Online-Info"='Online' and "NAS"='$ras'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$user = $row[0];
$rate = $row[1];
system("/usr/bin/perl -w /usr/bin/send-speed.pl $ras $user $rate");
}
mysql_free_result($result);
?>
4. Executing your perl script for overwriting the dynamic queues:
#!/usr/bin/perl

my $host = $ARGV[0];
my $username = $ARGV[1];
my $rate = $ARGV[2];
my $found=0;

use Data::Dumper;
use Net::Telnet ();

$t = new Net::Telnet (
Host => "$host",
Timeout => 10,
Dump_log => "./xyz",
Prompt => '/\[.+\] > $/');

$t->login("mikrotik-RW-user", "mikroti-password");

$t->cmd("/queue simple set \"<pppoe-$username>\" limit-at=$rate max-limit=$rate");
Do not forget to enable telnet on the MikroTik and you can use pptp-$username if you provide PPTP.
If you have any further questions please feel free to ask here!
 
savage
Forum Guru
Forum Guru
Posts: 1168
Joined: Mon Oct 18, 2004 12:07 am
Location: Cape Town, South Africa
Contact:

Re: how to change dynamic queues

Thu Mar 13, 2008 12:15 pm

Interesting...

What about just using a radius client, and sending a radius attribute to the MT? One line, one command, no need for all these scripts calling more scripts, calling more scripts ;)
Regards,
Chris
 
User avatar
promind
Member Candidate
Member Candidate
Topic Author
Posts: 153
Joined: Thu Feb 23, 2006 11:26 am
Location: Rousse, Bulgaria
Contact:

Re: how to change dynamic queues

Thu Mar 13, 2008 12:39 pm

Interesting...

What about just using a radius client, and sending a radius attribute to the MT? One line, one command, no need for all these scripts calling more scripts, calling more scripts ;)
Sending attribute is just when user connects.
When user is online/realtime/ you cannot touch his/her queue so I have to make these scripts to gather online users on my MikroTik RASes and apply the new speeds.
 
savage
Forum Guru
Forum Guru
Posts: 1168
Joined: Mon Oct 18, 2004 12:07 am
Location: Cape Town, South Africa
Contact:

Re: how to change dynamic queues

Thu Mar 13, 2008 1:24 pm

Change of Authorization
RADIUS disconnect and Change of Authorization (according to RFC3576) are supported as well. These attributes may be changed by a CoA request from the RADIUS server:
* Mikrotik-Group
* Mikrotik-Recv-Limit
* Mikrotik-Xmit-Limit
* Mikrotik-Rate-Limit
* Ascend-Data-Rate (only if Mikrotik-Rate-Limit is not present)
* Ascend-XMit-Rate (only if Mikrotik-Rate-Limit is not present)
* Mikrotik-Mark-Id
* Filter-Id
* Mikrotik-Advertise-Url
* Mikrotik-Advertise-Interval
* Session-Timeout
* Idle-Timeout
* Port-Limit
Note that it is not possible to change IP address, pool or routes that way - for such changes a user must be disconnected first.
It has been discussed on these forums before, MT supports CoA (Change of Authorization I believe). You can alter the dynamic queue speed via a radius update message.
Regards,
Chris
 
User avatar
promind
Member Candidate
Member Candidate
Topic Author
Posts: 153
Joined: Thu Feb 23, 2006 11:26 am
Location: Rousse, Bulgaria
Contact:

Re: how to change dynamic queues

Thu Mar 13, 2008 3:37 pm

Change of Authorization
RADIUS disconnect and Change of Authorization (according to RFC3576) are supported as well. These attributes may be changed by a CoA request from the RADIUS server:
* Mikrotik-Group
* Mikrotik-Recv-Limit
* Mikrotik-Xmit-Limit
* Mikrotik-Rate-Limit
* Ascend-Data-Rate (only if Mikrotik-Rate-Limit is not present)
* Ascend-XMit-Rate (only if Mikrotik-Rate-Limit is not present)
* Mikrotik-Mark-Id
* Filter-Id
* Mikrotik-Advertise-Url
* Mikrotik-Advertise-Interval
* Session-Timeout
* Idle-Timeout
* Port-Limit
Note that it is not possible to change IP address, pool or routes that way - for such changes a user must be disconnected first.
It has been discussed on these forums before, MT supports CoA (Change of Authorization I believe). You can alter the dynamic queue speed via a radius update message.
It has been discussed but PPPoE does not support CoA just PoD.
 
rachadatallah
just joined
Posts: 11
Joined: Sat Aug 09, 2008 12:35 pm

Re: how to change dynamic queues

Wed Dec 30, 2009 10:53 am

could you help me more about those scripts where to apply them and how it works

look what i want to do
first i'm using pppoe and i have arround 40 users
i have arround 3 profiles speed 150k/40k 220k/50k 280k/64k

what i want is that mikrotik changes automatically those rates and double the speed
from midnight till 11:00 am

but the problem i don't know how and need some help
ps:details imp because i'm not a programer

Who is online

Users browsing this forum: No registered users and 42 guests