quota limit with freeradius

I have setup freeradius 2.x with mysql as Billing system and Mikrotik as NAS (pppoe server).

I have managed to configure few modules like time limit, expiration etc. but unable to configure volume QUOTA limit , e.g 100MB for user.

I tried to take various examples from the google/forum but none of it worked. can some one please post some working examples of the counters and tips please?

Try following: [I have used it in Ubuntu Freeradius 2.x with Mikrotik 5.x]
QUOTA LIMIT FOR USER with CUSTOM MEANINGFUL REJECT REPLY MESSAGE

To limit user data volume limit (either daily, weekly or monthly, set this in reset section) use below code.

edit the file /etc/freeradius/sites-enabled/default

and add following under “authorize {“ section

totalbytecounter{
reject = 1
}
if(reject){
update reply {
Reply-Message := "ZAIB-RADIUS-REPLY - You have reached your bandwidth limit"
}
reject
}

now edit file /etc/freeradius/modules/sqlcounter_expire_on_login
Add Following

sqlcounter totalbytecounter {
counter-name = Mikrotik-Total-Limit
check-name = Mikrotik-Total-Limit
reply-name = Mikrotik-Total-Limit
sqlmod-inst = sql
key = User-Name
reset = never
query = “SELECT ((SUM(AcctInputOctets)+SUM(AcctOutputOctets))) FROM radacct WHERE UserName=‘%{%k}’”
}

Save and Exit.

Now add user attribute in radchceck table (Following is 1 MB total data limit example, which can be used in parts as well )

Note: Value is in bytes, so use it accordingly

INSERT INTO radcheck ( id , UserName , Attribute , op , Value ) VALUES (NULL , 'zaib', 'Mikrotik-Total-Limit', '=', '1000000');

Once the user quota over, and user retry login he will get access deny message, and in radius log, you can see following
radreply.PNG