MUM 2010
It is currently Tue Feb 09, 2010 5:11 am

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: how to change dynamic queues
PostPosted: Thu Mar 13, 2008 11:21 am 
Offline
Member Candidate
Member Candidate

Joined: Thu Feb 23, 2006 12:26 pm
Posts: 131
Location: Rousse, Bulgaria
Here is how I do it:
1. Create table clients where nas info is stored:
Quote:
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:
Quote:
#!/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
Quote:
#!/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:
Quote:
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:

Quote:
#!/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!


Top
 Profile  
 
 Post subject: Re: how to change dynamic queues
PostPosted: Thu Mar 13, 2008 1:15 pm 
Offline
Forum Veteran
Forum Veteran
User avatar

Joined: Mon Oct 18, 2004 12:07 am
Posts: 766
Location: Cape Town, South Africa
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


Top
 Profile  
 
 Post subject: Re: how to change dynamic queues
PostPosted: Thu Mar 13, 2008 1:39 pm 
Offline
Member Candidate
Member Candidate

Joined: Thu Feb 23, 2006 12:26 pm
Posts: 131
Location: Rousse, Bulgaria
savage wrote:
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.


Top
 Profile  
 
 Post subject: Re: how to change dynamic queues
PostPosted: Thu Mar 13, 2008 2:24 pm 
Offline
Forum Veteran
Forum Veteran
User avatar

Joined: Mon Oct 18, 2004 12:07 am
Posts: 766
Location: Cape Town, South Africa
Quote:
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


Top
 Profile  
 
 Post subject: Re: how to change dynamic queues
PostPosted: Thu Mar 13, 2008 4:37 pm 
Offline
Member Candidate
Member Candidate

Joined: Thu Feb 23, 2006 12:26 pm
Posts: 131
Location: Rousse, Bulgaria
savage wrote:
Quote:
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.


Top
 Profile  
 
 Post subject: Re: how to change dynamic queues
PostPosted: Wed Dec 30, 2009 11:53 am 
Offline
just joined

Joined: Sat Aug 09, 2008 12:35 pm
Posts: 3
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: 0ldman, MSNbot Media, wa4zlw and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
MUM Poland and MUM China free REGISTRATION OPEN