Hello,
I am interested in a script that detects and keeps track of (in real time) RTP traffic is passing through the WAN interface. If so, issue the command to enable a queue, when RTP traffic ceases to pass (I.E, voice of video call has ended) then disable the QoS script.
Is this doable? Any guidelines?
Thanks!
----------SOLUTION---------------------------------------------------
My internet connection is not the greatest and it’s only guaranteed 50% of it’s advertised throughput. That means that at worst, if the network is congested I would get around 50% of the bandwidth.
Since I live abroad, VoIP traffic is very important for me. However, I don’t make calls too often. Therefore, I was looking for a way to automatically have a QoS script be enabled whenever I have a VoIP call in place but I don’t want to throttle my bandwidth if I am not in a VoIP call.
So, how did I resolve this issue?
Well, I did the following:
- Usually VoIP media traffic uses UDP RTP ports (in asterisk it defaults to 10000 to 20000 UDP ports).
- I created a mangle rule on the forward chain that has source ip 0.0.0.0/0 and destination list (I created a destination list of my VoIP servers where I send and receive traffic from) in my case the mangle rule number is #2 (you’ll see it in the script).
- Mangle rules count how many bytes have gone through it. So therefore, I count the difference of bytes in order to know if actual RTP traffic is flowing through.
- After traffic has been detected the script will check for changes in traffic every 2 seconds
I wrote this script which seems to work fine. It loops forever after you start it, so detection level (from what I tested) can go down to 50ms!
:local count1 [ /ip firewall mangle get 2 bytes ];
:delay 100ms;
:local count2 [ /ip firewall mangle get 2 bytes ];
:local status [ /queue simple get VoIP-Queue disabled ];
:while ( $count2 = $count1 ) do={
:set count1 [ /ip firewall mangle get 2 bytes ];
:delay 100ms;
:set count2 [ /ip firewall mangle get 2 bytes ];
:while ( $count2 != $count1 ) do={
:if ($status = true) do={
/queue simple enable VoIP-Queue;
:set status false;
:log info "Queue Activated";
}
:set count1 [ /ip firewall mangle get 2 bytes ];
:delay 2s;
:set count2 [ /ip firewall mangle get 2 bytes ];
};
:delay 2s;
:if ($status = false ) do={
/queue simple disable VoIP-Queue;
:set status true;
:log info "Queue Deactivated";
}
};
** A little cleaning up is needed but you get the idea ![]()
I hope that this works for you as it did for me.
If you happen to have a good QoS script, please consider sharing it with me. Thanks!