@@ -138,10 +138,41 @@ extern "C" {
138
138
* After the successful state change, data can be sent using socket_send().
139
139
* The connection can be shut down in either direction with socket_shutdown() function - shutting down write signals end-of-data to the peer.
140
140
*
141
+ *
141
142
* \section socket-udpicmp How to use UDP and RAW socket:
142
143
*
143
144
* A UDP socket is ready to receive and send data immediately after a successful call of socket_open() and a NET_READY event is received.
144
145
* Data can be transmitted with the socket_sendto() function. An ICMP socket works with same function call.
146
+ *
147
+ * \section socket-trafficpriority How to set socket message priority to improve Quality of Service (QoS):
148
+ *
149
+ * IPv6 header has a field traffic class that contains a 6-bit Differentiated Services Code Point (DSCP) field that is used for packet
150
+ * classification. By default the packet class level is set to 0 NS_DSCP_DEFAULT.
151
+ *
152
+ * Recommend QoS levels:
153
+ *
154
+ * | Level |Description |
155
+ * | :--------------: | :-------------------------------------------------------------------------------------------------: |
156
+ * | NS_DSCP_DEFAULT | Default level for normal data usage |
157
+ * | NS_DSCP_AF11 | Higher Application data service for prioritize packet forwarding. |
158
+ * | NS_DSCP_EF | Expedited Forwarding (EF) for short messages. Allows low loss, low delay, and low jitter services. |
159
+ * | | This is meant for very important messages like alerts. EF packet length should be kept in |
160
+ * | | minimum. This should not be used for any other purpose as it will block other network traffic |
161
+ * | NS_DSCP_CS6 | Network protocol message Priority. Application should not use this. |
162
+ *
163
+ * High priority messages can be set to use higher than default class by using socket_setsockopt() and
164
+ * socket_option_traffic_class_dsc_set() helper.
165
+ *
166
+ * Example to send a message using Expedited Forwarding class:
167
+ *
168
+ * //Set EF class to high priority messages
169
+ * int16_t traffic_class = socket_option_traffic_class_dsc_set(NS_DSCP_EF);
170
+ * socket_setsockopt(socket_id, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_TCLASS, &traffic_class, sizeof traffic_class);
171
+ *
172
+ * //Set traffic class back to default
173
+ * traffic_class = socket_option_traffic_class_dsc_set(NS_DSCP_DEFAULT);
174
+ * socket_setsockopt(socket_id, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_TCLASS, &traffic_class, sizeof traffic_class);
175
+ *
145
176
*/
146
177
147
178
#include "ns_address.h"
@@ -250,6 +281,24 @@ typedef struct ns_in6_pktinfo {
250
281
int8_t ipi6_ifindex ; /**< send/recv interface index */
251
282
} ns_in6_pktinfo_t ;
252
283
284
+ /** \name Socket DSCP (Differentiated Services Code Point) QoS level examples.
285
+ * \anchor MSG_QOS_LEVELS
286
+ */
287
+ ///@{
288
+ /** Standard priority and it is socket default */
289
+ #define NS_DSCP_DEFAULT 0
290
+ /** Application high priority service: Stack priorities these messages over the default priority messages */
291
+ #define NS_DSCP_AF11 10
292
+ /** Expedited Forwarding (EF) QoS level enable high priority state: low loss, low delay, and low jitter services */
293
+ #define NS_DSCP_EF 46
294
+ /** Network protocol traffic allocated QoS level stack may internally use that */
295
+ #define NS_DSCP_CS6 48
296
+ ///@}
297
+
298
+ /** Helper Traffic class Differentiated Services Code for QoS 0-63. 0 is default which define Lowest Priority
299
+ *
300
+ * */
301
+ #define socket_option_traffic_class_dsc_set (x ) (uint8_t)((x & 63) << 2)
253
302
254
303
/** \name Alignment macros for control message headers
255
304
* \anchor CMSG_ALIGN_FLAGS
0 commit comments