QoS for VOIP in Mikrotik
Prerequisities: Your VOIP SW/HW client can set the DSCP/TOS field in the IP packet in such a way that:
- SIP signaling messages will be marked by DSCP=0x68 (=104)
- RTP voice audio data will be marked by DSCP=0xB8 (=184)
These are the default values for SPA-XXXX VOIP gateways, but also SW clients should be able to make these settings. E.g., in XLite, just divide these values by 4 (DSCP for SIP=26, for RTP=46)
If your central internet gateway router handles/restores the DSCP-marked packets correctly (see the HTB script that we use on our gateway), then implementing QoS for VOIP packets at your Mikrotik routers is easy - see the following script:
/ip firewall mangle add chain=prerouting tos=104 action=mark-packet new-packet-mark=voip-sip passthrough=yes add chain=prerouting tos=184 action=mark-packet new-packet-mark=voip-rtp passthrough=yes
If your central router does NOT restore the DSCP marks for packet incoming from the VOIP providers (and the providers do not mark packets with DSCP), you must implement the same things as in the HTB script - mark connection, then mark unmarked packets with the connection mark and use the packet marks in the queues (note that Mikrotik 2.9.x can't use connection mark in queue rules)
Finally, the queues:
/queue simple add name="VOIP-SIP" interface=all packet-marks=voip-sip priority=1 add name="VOIP-RTP" interface=all packet-marks=voip-rtp priority=1
Note that:
- only one queue is necessary if you have DSCP marks on packets in both directions (DSCP marks for incoming packets can be restored on the central internet gateway - see the HTB script). The reason for one queue is that
- the default pfifo queueing discipline prioritize the DSCP marks automatically, so theoretically, if the central internet gateway restores the DSCP marks on incoming packets from VOIP providers, everything could work OK even without any QoS settings on the router. The pfifo is defaultly used on HTB leafs and also on ethernet interfaces in Linux and Mikrotik which do not have any qdisc assigned.
But if you already do some QoS (e.g. using HTB in Linux or "queues" on Mikrotik)on your routers, you should add also these 2 queues dedicated to VOIP.