Skip to content

Commit

Permalink
net: context: Add PRIORITY option support
Browse files Browse the repository at this point in the history
Add context option support and implement PRIORITY option that
can be used to classify the network traffic to different trafic
classes according to said priority value.

Signed-off-by: Jukka Rissanen <[email protected]>
  • Loading branch information
jukkar authored and Anas Nashif committed Mar 27, 2018
1 parent ca8b00a commit 81d8d52
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .known-issues/doc/networking.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@
^(?P=filename):(?P=lineno): WARNING: Invalid definition: Expected end of definition. \[error at [0-9]+]
^.*ieee802154_req_params.__unnamed__
^[- \t]*\^
#
# include/net/net_context.h
#
^(?P<filename>[-._/\w]+/doc/api/networking.rst):(?P<lineno>[0-9]+): WARNING: Invalid definition: Expected end of definition. \[error at [0-9]+]
^.*net_context.options
^[- \t]*\^
40 changes: 40 additions & 0 deletions include/net/net_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ struct net_context {
*/
struct sockaddr remote;

/** Option values */
struct {
#if defined(CONFIG_NET_CONTEXT_PRIORITY)
/** Priority of the network data sent via this net_context */
u8_t priority;
#endif
} options;

/** Connection handle */
struct net_conn_handle *conn_handler;

Expand Down Expand Up @@ -769,6 +777,38 @@ int net_context_recv(struct net_context *context,
int net_context_update_recv_wnd(struct net_context *context,
s32_t delta);

enum net_context_option {
NET_OPT_PRIORITY = 1,
};

/**
* @brief Set an connection option for this context.
*
* @param context The network context to use.
* @param option Option to set
* @param value Option value
* @param len Option length
*
* @return 0 if ok, <0 if error
*/
int net_context_set_option(struct net_context *context,
enum net_context_option option,
const void *value, size_t len);

/**
* @brief Get connection option value for this context.
*
* @param context The network context to use.
* @param option Option to set
* @param value Option value
* @param len Option length (returned to caller)
*
* @return 0 if ok, <0 if error
*/
int net_context_get_option(struct net_context *context,
enum net_context_option option,
void *value, size_t *len);

/**
* @typedef net_context_cb_t
* @brief Callback used while iterating over network contexts
Expand Down
7 changes: 7 additions & 0 deletions subsys/net/ip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ config NET_CONTEXT_CHECK
If you know that the options passed to net_context...() functions
are ok, then you can disable the checks to save some memory.

config NET_CONTEXT_PRIORITY
bool "Add priority support to net_context"
default n
help
It is possible to prioritize network traffic. This requires
also traffic class support to work as expected.

config NET_TEST
bool "Network Testing"
default n
Expand Down
75 changes: 75 additions & 0 deletions subsys/net/ip/net_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -2462,6 +2462,81 @@ int net_context_update_recv_wnd(struct net_context *context,
return -EPROTOTYPE;
#endif
}

static int set_context_priority(struct net_context *context,
const void *value, size_t len)
{
#if defined(CONFIG_NET_CONTEXT_PRIORITY)
if (len > sizeof(u8_t)) {
return -EINVAL;
}

context->options.priority = *((u8_t *)value);

return 0;
#else
return -ENOTSUP;
#endif
}

static int get_context_priority(struct net_context *context,
void *value, size_t *len)
{
#if defined(CONFIG_NET_CONTEXT_PRIORITY)
*((u8_t *)value) = context->options.priority;

if (len) {
*len = sizeof(u8_t);
}

return 0;
#else
return -ENOTSUP;
#endif
}

int net_context_set_option(struct net_context *context,
enum net_context_option option,
const void *value, size_t len)
{
int ret = 0;

NET_ASSERT(context);

if (!PART_OF_ARRAY(contexts, context)) {
return -EINVAL;
}

switch (option) {
case NET_OPT_PRIORITY:
ret = set_context_priority(context, value, len);
break;
}

return ret;
}

int net_context_get_option(struct net_context *context,
enum net_context_option option,
void *value, size_t *len)
{
int ret = 0;

NET_ASSERT(context);

if (!PART_OF_ARRAY(contexts, context)) {
return -EINVAL;
}

switch (option) {
case NET_OPT_PRIORITY:
ret = get_context_priority(context, value, len);
break;
}

return ret;
}

void net_context_foreach(net_context_cb_t cb, void *user_data)
{
int i;
Expand Down

0 comments on commit 81d8d52

Please sign in to comment.