Skip to content

Commit 1bd5ce6

Browse files
authored
Merge pull request #13671 from balajicyp/topic/setsockopt_ip_tos
Add an socket option to set type of service to set specific precedence for QoS
2 parents ac45aac + ada44a6 commit 1bd5ce6

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

connectivity/lwipstack/source/LWIPStack.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,12 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
665665
return err_remap(igmp_err);
666666
}
667667

668+
case NSAPI_IPTOS:
669+
if (optlen != sizeof(u8_t)) {
670+
return NSAPI_ERROR_UNSUPPORTED;
671+
}
672+
s->conn->pcb.ip->tos = (u8_t)(*(const int *)optval);
673+
return 0;
668674
default:
669675
return NSAPI_ERROR_UNSUPPORTED;
670676
}

connectivity/netsocket/include/netsocket/nsapi_types.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,50 @@ extern "C" {
2828
#endif
2929

3030

31+
/*
32+
* The Type of Service provides an indication of the abstract
33+
* parameters of the quality of service desired. These parameters are
34+
* to be used to guide the selection of the actual service parameters
35+
* when transmitting a datagram through a particular network. Several
36+
* networks offer service precedence, which somehow treats high
37+
* precedence traffic as more important than other traffic (generally
38+
* by accepting only traffic above a certain precedence at time of high
39+
* load). The major choice is a three way tradeoff between low-delay,
40+
* high-reliability, and high-throughput.
41+
* The use of the Delay, Throughput, and Reliability indications may
42+
* increase the cost (in some sense) of the service. In many networks
43+
* better performance for one of these parameters is coupled with worse
44+
* performance on another. Except for very unusual cases at most two
45+
* of these three indications should be set.
46+
*/
47+
#define NSAPI_IPTOS_TOS_MASK 0x1E
48+
#define NSAPI_IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
49+
#define NSAPI_IPTOS_LOWDELAY 0x10
50+
#define NSAPI_IPTOS_THROUGHPUT 0x08
51+
#define NSAPI_IPTOS_RELIABILITY 0x04
52+
#define NSAPI_IPTOS_LOWCOST 0x02
53+
#define NSAPI_IPTOS_MINCOST IPTOS_LOWCOST
54+
55+
/*
56+
* The Network Control precedence designation is intended to be used
57+
* within a network only. The actual use and control of that
58+
* designation is up to each network. The Internetwork Control
59+
* designation is intended for use by gateway control originators only.
60+
* If the actual use of these precedence designations is of concern to
61+
* a particular network, it is the responsibility of that network to
62+
* control the access to, and use of, those precedence designations.
63+
*/
64+
#define NSAPI_IPTOS_PREC_MASK 0xe0
65+
#define NSAPI_IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
66+
#define NSAPI_IPTOS_PREC_NETCONTROL 0xe0
67+
#define NSAPI_IPTOS_PREC_INTERNETCONTROL 0xc0
68+
#define NSAPI_IPTOS_PREC_CRITIC_ECP 0xa0
69+
#define NSAPI_IPTOS_PREC_FLASHOVERRIDE 0x80
70+
#define NSAPI_IPTOS_PREC_FLASH 0x60
71+
#define NSAPI_IPTOS_PREC_IMMEDIATE 0x40
72+
#define NSAPI_IPTOS_PREC_PRIORITY 0x20
73+
#define NSAPI_IPTOS_PREC_ROUTINE 0x00
74+
3175
/** Enum of standardized error codes
3276
*
3377
* Valid error codes have negative values and may
@@ -273,6 +317,7 @@ typedef enum nsapi_socket_option {
273317
NSAPI_BIND_TO_DEVICE, /*!< Bind socket network interface name*/
274318
NSAPI_LATENCY, /*!< Read estimated latency to destination */
275319
NSAPI_STAGGER, /*!< Read estimated stagger value to destination */
320+
NSAPI_IPTOS, /*!< Set IP type of service to set specific precedence */
276321
} nsapi_socket_option_t;
277322

278323
typedef enum nsapi_tlssocket_level {

0 commit comments

Comments
 (0)