Debian Codegraph @

Xpjproject/pjlib/include/pj/sock_qos.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #ifndef __PJ_SOCK_QOS_H__
20 #define __PJ_SOCK_QOS_H__
21
22 /**
23 * @file sock_qos.h
24 * @brief Socket QoS API
25 */
26
27 #include <pj/sock.h>
28
29 PJ_BEGIN_DECL
30
31
32 /**
33 * @defgroup socket_qos Socket Quality of Service (QoS) API: TOS, DSCP, WMM, IEEE 802.1p
34 * @ingroup PJ_SOCK
35 * @{
36
37
38 \section intro QoS Technologies
39
40 QoS settings are available for both Layer 2 and 3 of TCP/IP protocols:
41
42 \subsection intro_ieee8021p Layer 2: IEEE 802.1p for Ethernet
43
44 IEEE 802.1p tagging will mark frames sent by a host for prioritized
45 delivery using a 3-bit Priority field in the virtual local area network
46 (VLAN) header of the Ethernet frame. The VLAN header is placed inside
47 the Ethernet header, between the Source Address field and either the
48 Length field (for an IEEE 802.3 frame) or the EtherType field (for an
49 Ethernet II frame).
50
51 \subsection intro_wmm Layer 2: WMM
52
53 At the Network Interface layer for IEEE 802.11 wireless, the Wi-Fi
54 Alliance certification for Wi-Fi Multimedia (WMM) defines four access
55 categories for prioritizing network traffic. These access categories
56 are (in order of highest to lowest priority) voice, video, best-effort,
57 and background. Host support for WMM prioritization requires that both
58 wireless network adapters and their drivers support WMM. Wireless
59 access points (APs) must have WMM enabled.
60
61 \subsection intro_dscp Layer 3: DSCP
62
63 At the Internet layer, you can use Differentiated Services/Diffserv and
64 set the value of the Differentiated Services Code Point (DSCP) in the
65 IP header. As defined in RFC 2474, the DSCP value is the high-order 6 bits
66 of the IP version 4 (IPv4) TOS field and the IP version 6 (IPv6) Traffic
67 Class field.
68
69 \subsection intro_other Layer 3: Other
70
71 Other mechanisms exist (such as RSVP, IntServ) but this will not be
72 implemented.
73
74
75 \section availability QoS Availability
76
77 \subsection linux Linux
78
79 DSCP is available via IP TOS option.
80
81 Ethernet 802.1p tagging is done by setting setsockopt(SO_PRIORITY) option
82 of the socket, then with the set_egress_map option of the vconfig utility
83 to convert this to set vlan-qos field of the packet.
84
85 WMM is not known to be available.
86
87 \subsection windows Windows and Windows Mobile
88
89 (It's a mess!)
90
91 DSCP is settable with setsockopt() on Windows 2000 or older, but Windows
92 would silently ignore this call on WinXP or later, unless administrator
93 modifies the registry. On Windows 2000, Windows XP, and Windows Server
94 2003, GQoS (Generic QoS) API is the standard API, but this API may not be
95 supported in the future. On Vista and Windows 7, the is a new QoS2 API,
96 also known as Quality Windows Audio-Video Experience (qWAVE).
97
98 IEEE 802.1p tagging is available via Traffic Control (TC) API, available
99 on Windows XP SP2, but this needs administrator access. For Vista and
100 later, it's in qWAVE.
101
102 WMM is available for mobile platforms on Windows Mobile 6 platform and
103 Windows Embedded CE 6, via setsockopt(IP_DSCP_TRAFFIC_TYPE). qWAVE
104 supports this as well.
105
106 \subsection symbian Symbian S60 3rd Ed
107
108 Both DSCP and WMM is supported via RSocket::SetOpt() with will set both
109 Layer 2 and Layer 3 QoS settings accordingly. Internally, PJLIB sets the
110 DSCP field of the socket, and based on certain DSCP values mapping,
111 Symbian will set the WMM tag accordingly.
112
113 \section api PJLIB's QoS API Abstraction
114
115 Based on the above, the following API is implemented.
116
117 Declare the following "standard" traffic types.
118
119 \code
120 typedef enum pj_qos_type
121 {
122 PJ_QOS_TYPE_BEST_EFFORT,
123 PJ_QOS_TYPE_BACKGROUND,
124 PJ_QOS_TYPE_VIDEO,
125 PJ_QOS_TYPE_VOICE,
126 PJ_QOS_TYPE_CONTROL,
127 PJ_QOS_TYPE_SIGNALLING
128 } pj_qos_type;
129 \endcode
130
131 The traffic classes above will determine how the Layer 2 and 3 QoS
132 settings will be used. The standard mapping between the classes above
133 to the corresponding Layer 2 and 3 settings are as follows:
134
135 \code
136 =================================================================
137 PJLIB Traffic Type IP DSCP WMM 802.1p
138 -----------------------------------------------------------------
139 BEST_EFFORT 0x00 BE (Bulk Effort) 0
140 BACKGROUND 0x08 BK (Bulk) 2
141 VIDEO 0x28 VI (Video) 5
142 VOICE 0x30 VO (Voice) 6
143 CONTROL 0x38 VO (Voice) 7
144 SIGNALLING 0x28 VI (Video) 5
145 =================================================================
146 \endcode
147
148 There are two sets of API provided to manipulate the QoS parameters.
149
150 \subsection portable_api Portable API
151
152 The first set of API is:
153
154 \code
155 // Set QoS parameters
156 PJ_DECL(pj_status_t) pj_sock_set_qos_type(pj_sock_t sock,
157 pj_qos_type val);
158
159 // Get QoS parameters
160 PJ_DECL(pj_status_t) pj_sock_get_qos_type(pj_sock_t sock,
161 pj_qos_type *p_val);
162 \endcode
163
164 The API will set the traffic type according to the DSCP class, for both
165 Layer 2 and Layer 3 QoS settings, where it's available. If any of the
166 layer QoS setting is not settable, the API will silently ignore it.
167 If both layers are not setable, the API will return error.
168
169 The API above is the recommended use of QoS, since it is the most
170 portable across all platforms.
171
172 \subsection detail_api Fine Grained Control API
173
174 The second set of API is intended for application that wants to fine
175 tune the QoS parameters.
176
177 The Layer 2 and 3 QoS parameters are stored in pj_qos_params structure:
178
179 \code
180 typedef enum pj_qos_flag
181 {
182 PJ_QOS_PARAM_HAS_DSCP = 1,
183 PJ_QOS_PARAM_HAS_SO_PRIO = 2,
184 PJ_QOS_PARAM_HAS_WMM = 4
185 } pj_qos_flag;
186
187 typedef enum pj_qos_wmm_prio
188 {
189 PJ_QOS_WMM_PRIO_BULK_EFFORT,
190 PJ_QOS_WMM_PRIO_BULK,
191 PJ_QOS_WMM_PRIO_VIDEO,
192 PJ_QOS_WMM_PRIO_VOICE
193 } pj_qos_wmm_prio;
194
195 typedef struct pj_qos_params
196 {
197 pj_uint8_t flags; // Determines which values to
198 // set, bitmask of pj_qos_flag
199 pj_uint8_t dscp_val; // The 6 bits DSCP value to set
200 pj_uint8_t so_prio; // SO_PRIORITY value
201 pj_qos_wmm_prio wmm_prio; // WMM priority value
202 } pj_qos_params;
203 \endcode
204
205 The second set of API with more fine-grained control over the parameters
206 are:
207
208 \code
209 // Retrieve QoS params for the specified traffic type
210 PJ_DECL(pj_status_t) pj_qos_get_params(pj_qos_type type,
211 pj_qos_params *p);
212
213 // Set QoS parameters to the socket
214 PJ_DECL(pj_status_t) pj_sock_set_qos_params(pj_sock_t sock,
215 const pj_qos_params *p);
216
217 // Get QoS parameters from the socket
218 PJ_DECL(pj_status_t) pj_sock_get_qos_params(pj_sock_t sock,
219 pj_qos_params *p);
220 \endcode
221
222
223 Important:
224
225 The pj_sock_set/get_qos_params() APIs are not portable, and it's probably
226 only going to be implemented on Linux. Application should always try to
227 use pj_sock_set_qos_type() instead.
228 */
229
230
231 /**
232 * High level traffic classification.
233 */
234 typedef enum pj_qos_type
235 {
236 PJ_QOS_TYPE_BEST_EFFORT, /**< Best effort traffic (default value).
237 Any QoS function calls with specifying
238 this value are effectively no-op */
239 PJ_QOS_TYPE_BACKGROUND, /**< Background traffic. */
240 PJ_QOS_TYPE_VIDEO, /**< Video traffic. */
241 PJ_QOS_TYPE_VOICE, /**< Voice traffic. */
242 PJ_QOS_TYPE_CONTROL, /**< Control traffic. */
243 PJ_QOS_TYPE_SIGNALLING /**< Signalling traffic. */
244 } pj_qos_type;
245
246 /**
247 * Bitmask flag to indicate which QoS layer setting is set in the
248 * \a flags field of the #pj_qos_params structure.
249 */
250 typedef enum pj_qos_flag
251 {
252 PJ_QOS_PARAM_HAS_DSCP = 1, /**< DSCP field is set. */
253 PJ_QOS_PARAM_HAS_SO_PRIO = 2, /**< Socket SO_PRIORITY */
254 PJ_QOS_PARAM_HAS_WMM = 4 /**< WMM field is set. */
255 } pj_qos_flag;
256
257
258 /**
259 * Standard WMM priorities.
260 */
261 typedef enum pj_qos_wmm_prio
262 {
263 PJ_QOS_WMM_PRIO_BULK_EFFORT, /**< Bulk effort priority */
264 PJ_QOS_WMM_PRIO_BULK, /**< Bulk priority. */
265 PJ_QOS_WMM_PRIO_VIDEO, /**< Video priority */
266 PJ_QOS_WMM_PRIO_VOICE /**< Voice priority */
267 } pj_qos_wmm_prio;
268
269
270 /**
271 * QoS parameters to be set or retrieved to/from the socket.
272 */
273 typedef struct pj_qos_params
274 {
275 pj_uint8_t flags; /**< Determines which values to
276 set, bitmask of pj_qos_flag */
277 pj_uint8_t dscp_val; /**< The 6 bits DSCP value to set */
278 pj_uint8_t so_prio; /**< SO_PRIORITY value */
279 pj_qos_wmm_prio wmm_prio; /**< WMM priority value */
280 } pj_qos_params;
281
282
283
284 /**
285 * This is the high level and portable API to enable QoS on the specified
286 * socket, by setting the traffic type to the specified parameter.
287 *
288 * @param sock The socket.
289 * @param type Traffic type to be set.
290 *
291 * @return PJ_SUCCESS if at least Layer 2 or Layer 3 setting is
292 * successfully set. If both Layer 2 and Layer 3 settings
293 * can't be set, this function will return error.
294 */
295 PJ_DECL(pj_status_t) pj_sock_set_qos_type(pj_sock_t sock,
296 pj_qos_type type);
297
298 /**
299 * This is the high level and portable API to get the traffic type that has
300 * been set on the socket. On occasions where the Layer 2 or Layer 3 settings
301 * were modified by using low level API, this function may return approximation
302 * of the closest QoS type that matches the settings.
303 *
304 * @param sock The socket.
305 * @param p_type Pointer to receive the traffic type of the socket.
306 *
307 * @return PJ_SUCCESS if traffic type for the socket can be obtained
308 * or approximated..
309 */
310 PJ_DECL(pj_status_t) pj_sock_get_qos_type(pj_sock_t sock,
311 pj_qos_type *p_type);
312
313
314 /**
315 * This is a convenience function to apply QoS to the socket, and print error
316 * logging if the operations failed. Both QoS traffic type and the low level
317 * QoS parameters can be applied with this function.
318 *
319 * @param sock The socket handle.
320 * @param qos_type QoS traffic type. The QoS traffic type will be applied
321 * only if the value is not PJ_QOS_TYPE_BEST_EFFORT,
322 * @param qos_params Optional low-level QoS parameters. This will be
323 * applied only if this argument is not NULL and the
324 * flags inside the structure is non-zero. Upon return,
325 * the flags will indicate which parameters have been
326 * applied successfully.
327 * @param log_level This function will print to log at this level upon
328 * encountering errors.
329 * @param log_sender Optional sender name in the log.
330 * @param sock_name Optional name to help identify the socket in the log.
331 *
332 * @return PJ_SUCCESS if at least Layer 2 or Layer 3 setting is
333 * successfully set. If both Layer 2 and Layer 3 settings
334 * can't be set, this function will return error.
335 *
336 * @see pj_sock_apply_qos2()
337 */
338 PJ_DECL(pj_status_t) pj_sock_apply_qos(pj_sock_t sock,
339 pj_qos_type qos_type,
340 pj_qos_params *qos_params,
341 unsigned log_level,
342 const char *log_sender,
343 const char *sock_name);
344
345 /**
346 * Variant of #pj_sock_apply_qos() where the \a qos_params parameter is
347 * const.
348 *
349 * @see pj_sock_apply_qos()
350 */
351 PJ_DECL(pj_status_t) pj_sock_apply_qos2(pj_sock_t sock,
352 pj_qos_type qos_type,
353 const pj_qos_params *qos_params,
354 unsigned log_level,
355 const char *log_sender,
356 const char *sock_name);
357
358 /**
359 * Retrieve the standard mapping of QoS params for the specified traffic
360 * type.
361 *
362 * @param type The traffic type from which the QoS parameters
363 * are to be retrieved.
364 * @param p_param Pointer to receive the QoS parameters.
365 *
366 * @return PJ_SUCCESS on success or the appropriate error code.
367 */
368 PJ_DECL(pj_status_t) pj_qos_get_params(pj_qos_type type,
369 pj_qos_params *p_param);
370
371
372 /**
373 * Retrieve the traffic type that matches the specified QoS parameters.
374 * If no exact matching is found, this function will return an
375 * approximation of the closest matching traffic type for the specified
376 * QoS parameters.
377 *
378 * @param param Structure containing QoS parameters to map into
379 * "standard" traffic types.
380 * @param p_type Pointer to receive the traffic type.
381 *
382 * @return PJ_SUCCESS on success or the appropriate error code.
383 */
384 PJ_DECL(pj_status_t) pj_qos_get_type(const pj_qos_params *param,
385 pj_qos_type *p_type);
386
387
388 /**
389 * This is a low level API to set QoS parameters to the socket.
390 *
391 * @param sock The socket.
392 * @param param Structure containing QoS parameters to be applied
393 * to the socket. Upon return, the \a flags field
394 * of this structure will be set with bitmask value
395 * indicating which QoS settings have successfully
396 * been applied to the socket.
397 *
398 * @return PJ_SUCCESS if at least one field setting has been
399 * successfully set. If no setting can't be set,
400 * this function will return error.
401 */
402 PJ_DECL(pj_status_t) pj_sock_set_qos_params(pj_sock_t sock,
403 pj_qos_params *param);
404
405 /**
406 * This is a low level API to get QoS parameters from the socket.
407 *
408 * @param sock The socket.
409 * @param p_param Pointer to receive the parameters. Upon returning
410 * successfully, the \a flags field of this structure
411 * will be initialized with the appropriate bitmask
412 * to indicate which fields have been successfully
413 * retrieved.
414 *
415 * @return PJ_SUCCESS on success or the appropriate error code.
416 */
417 PJ_DECL(pj_status_t) pj_sock_get_qos_params(pj_sock_t sock,
418 pj_qos_params *p_param);
419
420
421 /**
422 * @}
423 */
424
425
426 PJ_END_DECL
427
428 #endif /* __PJ_SOCK_QOS_H__ */
429