How to Set the DSCP Flag in Your System
DSCP (Differentiated Services Code Point) is a series of bits in the IP header for classification purposes. These bits specify the precedence value of the packet, the drop probability, and the network service used.
Before setting the DSCP flag with a desired value, you need to take some things into consideration: You cannot force the DSCP flag from the DDS middleware, but you can suggest the system use a specific value.
The reason is that all network elements such as switches and routers must have the capability and be enabled to actually use the TOS bits to treat higher-priority packets differently (TOS is an older mechanism to prioritize packets).
In addition, many network transports are not capable of managing packet priority. All this makes it impossible for DDS to control the prioritization of data at the network level.
Notice that the DSCP can have different values:
DSCP Value | Decimal Value | Meaning | Drop Probability | Equivalent IP Precedence Value |
101 110 | 46 | High Priority Expedited Forwarding (EF) | N/A | 101 - Critical |
000 000 | 0 | Best Effort | N/A | 000 - Routine |
001 010 | 10 | AF11 | Low | 001 - Priority |
001 100 | 12 | AF12 | Medium | 001 - Priority |
001 110 | 14 | AF13 | High | 001 - Priority |
010 010 | 18 | AF21 | Low | 010 - Immediate |
010 100 | 20 | AF22 | Medium | 010 - Immediate |
010 110 | 22 | AF23 | High | 010 - Immediate |
011 010 | 26 | AF31 | Low | 011 - Flash |
011 100 | 28 | AF32 | Medium | 011 - Flash |
011 110 | 30 | AF33 | High | 011 - Flash |
100 010 | 34 | AF41 | Low | 100 - Flash Override |
100 100 | 36 | AF42 | Medium | 100 - Flash Override |
100 110 | 38 | AF43 | High | 100 - Flash Override |
001 000 | 8 | CS1 | 1 | |
010 000 | 16 | CS2 | 2 | |
011 000 | 24 | CS3 | 3 | |
100 000 | 32 | CS4 | 4 | |
101 000 | 40 | CS5 | 5 | |
110 000 | 48 | CS6 | 6 | |
111 000 | 56 | CS7 | 7 | |
000 000 | 0 | Default | ||
101 110 | 46 | EF |
QoS Changes
In order to configure the DSCP flags, you need to consider the nature of your traffic and the transport that your DomainParticipants are using.
Traffic type
For User Data, you would need to use the transport_priority QoS Policy. This QoS Policy may be applied to the QoS of DataWriters, DataReaders and Topics.
<datawriter_qos> <transport_priority> <value>46</value> </transport_priority> </datawriter_qos>
For Metatraffic Data, you would need to modify the metatraffic_transport_priority QoS within the Discovery QoS Policy of a DomainParticipant QoS.
<participant_qos> <discovery> <metatraffic_transport_priority>46</metatraffic_transport_priority> </discovery> </participant_qos>
Transport Kind
Given that DSCP is native to IP, we need to also configure transports such as UDPv4.
In particular, there are three QoS that configure how a Transport will use the values provided above:
- transport_priority_mask
- transport_priority_mapping_high
- transport_priority_mapping_low
These are used to modify the final Transport Priority value to be used, using the following formula:
out_value = (in_value & transport_priority_mask) out_value = min(out_value, transport_priority_mapping_high) out_value = max(out_value, transport_priority_mapping_low)
For example, in order to configure the UDPv4 Transport, one could use the following QoS configuration:
<participant_qos> <property> <value> <element> <name>dds.transport.UDPv4.builtin.transport_priority_mask</name> <value>0x3F</value> </element> <element> <name>dds.transport.UDPv4.builtin.transport_priority_mapping_high</name> <value>0xFF</value> </element> <element> <name>dds.transport.UDPv4.builtin.transport_priority_mapping_low</name> <value>0x00</value> </element> </value> </property> </participant_qos>
Operating System Changes (applicable to Windows)
If you need to change this value on a Windows machine, it won’t be enough to make the change in the QoS profile. Instead, it is necessary to do it at the application level and it must be set by modifying a system registry:
Open the regedit application (for example typing regedit in the “Start” button).
Using the left side tree, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters path.
There, right click, select “New” and then “DWORD”.
Use “DisableUserTOSSetting” for the field name and for "0" for the Value data.
Then go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Qos (if you don’t have any QoS in the tree, you can create one with right click>New>Key and enter the QoS name).
Create a string value (Right click>New>String value) and use “Do not use NLA” for the name and “1” for the value.
Reboot you computer.
After your system restarts, open gpedit.msc.
Go to Computer configuration > Windows Settings > Policy-based QoS and right click on “Create new policy”.
Check “Specify DSCP Value” and use the desired value (for example, 8). Click “Next”.
Check “Only application with this executable name:” and fill with Process Name (executable). Click “Next” twice.
After these steps, run your application and the DSCP value should have changed.