I have a script I wrote almost identical to that except that it worked with usermanager. I also have one that I wrote and posted here somewhere to set several groups of users and have trees for each group that controlled the the amount of bytes they could download per con before it dropped them to a subqueue with lower data rate or priority, but maintained the overall bandwith per user to what is established in there plan. it worked fine for tcp but had a bug or two when it came to udp.
what i would like to do is
be able to set my pipe size
have 4 groups of speeds say , 256k 512k 1m and 1.5m
have it check each ip in each group for say 10 sec and if they download >x in 10 seconds set a timer for 30 sec, else reset timer to check agian in 10sec.
when timer is up they have download >x total since first count change them to a lower subqueue (speed and priority)set new timer for 30 sec and if at the end of those 30 sec the total is >x continue the process until they are at 30% plan rate. else reset counters and start all over.
be able to use nat if nessasary , but mostly just routing.
be able to set someone to a dedicated priority for dedicated bandwith. (not in any plan, they bought dedicated not shared service)
keep a running total on upload and download per user.
if p2p can be cut out completely per group and given lower priority per group.
if voip can be set to a higher priority per group also
you could add other stuff like dns and other protocols that need higher priority.