Limit different bandwidth in day and night for different users
Maybe you have many users, institutions, and alike, that use the internet during the day. And maybe you have "power users" that have two jobs, come home at 19.00 and they want to make it all at once, read mail, chat, download with p2p programs, etc.
Let's say you have corporate users / institutions / government. People that arrive at 07.00 and leave the office 18.00 at most. You reserve them 1 mbit/s all the time. Most of your home users are using maximum bandwidth after 15.00 and just after midnight. You decide to allow them to use all the bandwidth you can afford, after the "big" clients get offline ( institutions, and alike, wich pay big money for quality services)
So, you decide you may "lend" some of the bandwidth of the users that are not working, while they are not...
You can of course add 2 ( two ) queues for each limit you want to put, but you can also put a single queue, and modify it's limits from a script.
That's the way we will do it. Might just be simpler. Why ? You keep the limits for different type of users in a single place ( the script). Also you can graph a single queue, that may be more acceptable for you and for some users if you allow them to view their traffic graphs.
You are using simple queues to limit the traffic.
( This can be easily adapted to queue tree, by modifying limits in the queue tree.... but that's another story. Work it out yourself.)
You have 3 types of users:
- 256k/256k at day, 1M/1M at night
- 512k/512k at day, 2M/2M at night
- 1M/1M at day, 4M/4M at night
You limit them by individual simple queues, and distinction among categories is by comment. ( i put this also on queue name to make it easier to see. It seems to me that winbox does not display comments on v3.6 at least on the RB I am working with right now :(, but the console uses them right and the scripts work fine )
How do we do it?
- Put simple queues with established limits, and distinctive queue _comment_ for each category of users. ( eg. ""Vasile_CAT1"", ""Vasile2_CAT2"", etc as queue names, and [CAT1, CAT2 will be the category identifiers, put in comment]
- Establish limits for each category: CAT1, CAT2, etc., we will modify this from the 2 scripts that handle everything.
- Put the script to run from the scheduler every 24 hours, and modify limits for day/night, reg. each category of users. The script for the "day" starts 06.00 hours, and ends 18.00 hours, when the script for the "night" starts, enabling the night modifications.
Setup NTP Client
Ok. Now, for this to work, first of all sync your clock. Or you might get strange results and complains, if your clock is out of sync :)
/system ntp client set enabled=yes mode=unicast primary-ntp=18.104.22.168 secondary-ntp=22.214.171.124
( You can put primary-ntp and secondary-npt to be resolved to whatever 0.europe.pool.ntp.org and 1.europe.pool.ntp.org is pointing to. Please replace "europe" with your continent, for further improvement on response times and proximity. See ntp.org for further information )
Setup the queues
( I put 4 for this example only. you can setup as many as you like, it does not matter )
/queue simple add comment="CAT1" direction=both disabled=no dst-address=192.168.4.15/32 \ max-limit=256000/256000 name="George_CAT1" parent=none priority=8 \ queue=default-small/default-small add comment="CAT1" direction=both disabled=no dst-address=192.168.4.16/32 \ max-limit=256000/256000 name="Robinson_CAT1" parent=none priority=8 \ queue=default-small/default-small add comment="CAT2" direction=both disabled=no dst-address=192.168.4.17/32 \ max-limit=512000/512000 name="Crusoe_CAT2" parent=none priority=8 \ queue=default-small/default-small add comment="CAT3" direction=both disabled=no dst-address=192.168.4.18/32 \ max-limit=1024000/1024000 name="Momma_CAT3" parent=none priority=8 \ queue=default-small/default-small
Now, these were the queues. Let's see:
Setup the scripts
For the "day" limits:
/system scheduler add comment="" disabled=no interval=1d name="Day" on-event="/queue simple\r\nset [find \ comment=CAT1] max-limit=256000/256000\r\nset [find comment=CAT2] \ max-limit=512000/512000\r\nset [find comment=CAT3] max-limit=1024000/1024000\r\n" \ start-date=jan/01/1970 start-time=06:00:00
For the "night" limits:
/system scheduler add comment="" disabled=no interval=1d name="Night" on-event="/queue simple\r\nset [find \ comment=CAT1] max-limit=1024000/1024000\r\nset [find comment=CAT2] \ max-limit=2048000/2048000\r\nset [find comment=CAT3] max-limit=4096000/4096000\r\n" \ start-date=jan/01/1970 start-time=18:00:00
Well, in clear text, they look (better)like this:
/queue simple set [find comment=CAT1] max-limit=256000/256000 set [find comment=CAT2] max-limit=512000/512000 set [find comment=CAT3] max-limit=1024000/1024000
/queue simple set [find comment=CAT1] max-limit=1024000/1024000 set [find comment=CAT2] max-limit=2048000/2048000 set [find comment=CAT3] max-limit=4096000/4096000
Each script is put to run at 1 day interval, "Day" script starts at 06.00, "Night" script starts at 18.00.
Implement in your systems.
Put your own limits on categories. You can put how many categories you like, with whatever identifiers you like, remember to update scripts. :)
You can edit the limits of queue tree, if you want to enable it with different limits at night. ( you can for example allow p2p with different limit at night, whether you decided how to limit it by mangle and routing marks, or by simple queues, whatever.
Have a nice scripting.