Skip to content

Commit

Permalink
gnrc_sixlowpan_frag_sfr: add support for queue-based ECN
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Mar 9, 2021
1 parent d27ea02 commit 5de1c19
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 2 deletions.
3 changes: 3 additions & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ PSEUDOMODULES += gnrc_sixloenc
PSEUDOMODULES += gnrc_sixlowpan_border_router_default
PSEUDOMODULES += gnrc_sixlowpan_default
PSEUDOMODULES += gnrc_sixlowpan_frag_hint
PSEUDOMODULES += gnrc_sixlowpan_frag_sfr_ecn
PSEUDOMODULES += gnrc_sixlowpan_frag_sfr_ecn_netif
PSEUDOMODULES += gnrc_sixlowpan_frag_sfr_ecn_fqueue
PSEUDOMODULES += gnrc_sixlowpan_frag_sfr_stats
PSEUDOMODULES += gnrc_sixlowpan_iphc_nhc
PSEUDOMODULES += gnrc_sixlowpan_nd_border_router
Expand Down
8 changes: 8 additions & 0 deletions sys/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ ifneq (,$(filter gnrc_sixlowpan_frag_sfr,$(USEMODULE)))
endif
endif

ifneq (,$(filter gnrc_sixlowpan_frag_sfr_ecn_%,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan_frag_sfr_ecn
endif

ifneq (,$(filter gnrc_sixlowpan_frag_sfr_ecn,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan_frag_sfr
endif

ifneq (,$(filter gnrc_sixlowpan_frag_sfr_stats,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan_frag_sfr
endif
Expand Down
52 changes: 52 additions & 0 deletions sys/include/net/gnrc/sixlowpan/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,58 @@ extern "C" {
#ifndef CONFIG_GNRC_SIXLOWPAN_SFR_DG_RETRIES
#define CONFIG_GNRC_SIXLOWPAN_SFR_DG_RETRIES 0U
#endif

/**
* @brief The numerator for the factor for when to mark ECN on `netif` queue
* state
*
* When `gnrc_sixlowpan_frag_sfr_ecn_netif` is compiled in, nodes will set the
* ECN bit of an RFRAG header when the input queue of the outgoing `netif` is
* filled by
* @ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_NUM / @ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_DEN
*/
#ifndef CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_NUM
#define CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_NUM 1U
#endif

/**
* @brief The denominator for the factor for when to mark ECN on `netif` queue
* state
*
* When `gnrc_sixlowpan_frag_sfr_ecn_netif` is compiled in, nodes will set the
* ECN bit of an RFRAG header when the input queue of the outgoing `netif` is
* filled by
* @ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_NUM / @ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_DEN
*/
#ifndef CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_DEN
#define CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_DEN 2U
#endif

/**
* @brief The numerator for the factor for when to mark ECN on frame queue
* state
*
* When `gnrc_sixlowpan_frag_sfr_ecn_fqueue` is compiled in, nodes will set the
* ECN bit of an RFRAG header when the input queue of the outgoing `netif` is
* filled by
* @ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_NUM / @ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_DEN
*/
#ifndef CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_NUM
#define CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_NUM 1U
#endif

/**
* @brief The denominator for the factor for when to mark ECN on frame queue
* state
*
* When `gnrc_sixlowpan_frag_sfr_ecn_fqueue` is compiled in, nodes will set the
* ECN bit of an RFRAG header when the input queue of the outgoing `netif` is
* filled by
* @ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_NUM / @ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_DEN
*/
#ifndef CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_DEN
#define CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_DEN 2U
#endif
/** @} */

/**
Expand Down
50 changes: 50 additions & 0 deletions sys/net/gnrc/network_layer/sixlowpan/frag/sfr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,54 @@ config GNRC_SIXLOWPAN_SFR_DG_RETRIES
int "The maximum number of retries from scratch for a particular datagram (MaxDatagramRetries)"
default 0

menuconfig KCONFIG_USEMODULE_GNRC_SIXLOWPAN_FRAG_SFR_ECN_NETIF
bool "Configure SFR ECN based on netif queue"
depends on USEMODULE_GNRC_SIXLOWPAN_FRAG_SFR_ECN_NETIF

if KCONFIG_USEMODULE_GNRC_SIXLOWPAN_FRAG_SFR_ECN_NETIF
config GNRC_SIXLOWPAN_SFR_ECN_NETIF_NUM
int "The numerator for the factor for when to mark ECN on `netif` queue state"
default 1
help
When `gnrc_sixlowpan_frag_sfr_ecn_netif` is compiled in, nodes will set
the ECN bit of an RFRAG header when the input queue of the outgoing
`netif` is filled by
@ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_NUM / @ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_DEN


config GNRC_SIXLOWPAN_SFR_ECN_NETIF_DEN
int "The denominator for the factor for when to mark ECN on `netif` queue state"
default 2
help
When `gnrc_sixlowpan_frag_sfr_ecn_netif` is compiled in, nodes will set
the ECN bit of an RFRAG header when the input queue of the outgoing
`netif` is filled by
@ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_NUM / @ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_DEN
endif

menuconfig KCONFIG_USEMODULE_GNRC_SIXLOWPAN_FRAG_SFR_ECN_FQUEUE
bool "Configure SFR ECN based on SFR's frame queue"
depends on USEMODULE_GNRC_SIXLOWPAN_FRAG_SFR_ECN_FQUEUE

if KCONFIG_USEMODULE_GNRC_SIXLOWPAN_FRAG_SFR_ECN_FQUEUE
config GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_NUM
int "The numerator for the factor for when to mark ECN on frame queue state"
default 1
help
When `gnrc_sixlowpan_frag_sfr_ecn_fqueue` is compiled in, nodes will set
the ECN bit of an RFRAG header when the input queue of the outgoing
`netif` is filled by
@ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_NUM / @ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_DEN


config GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_DEN
int "The denominator for the factor for when to mark ECN on frame queue state"
default 2
help
When `gnrc_sixlowpan_frag_sfr_ecn_fqueue` is compiled in, nodes will set
the ECN bit of an RFRAG header when the input queue of the outgoing
`netif` is filled by
@ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_NUM / @ref CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_DEN
endif

endif
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,49 @@ void gnrc_sixlowpan_frag_sfr_arq_timeout(gnrc_sixlowpan_frag_fb_t *fbuf)
_clean_up_fbuf(fbuf, error_no);
}

static void _6lo_dispatch_send(gnrc_pktsnip_t *frame, void *ctx, unsigned page)
{
if (IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_ECN) &&
(sixlowpan_sfr_rfrag_is(frame->next->data))) {
int queue_state = 0;
int queue_size = 0;

if (IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_ECN_NETIF)) {
gnrc_netif_t *netif = gnrc_netif_hdr_get_netif(frame->data);

assert(frame->type == GNRC_NETTYPE_NETIF);
assert(frame->next->type == GNRC_NETTYPE_SIXLOWPAN);
queue_state = msg_avail_thread(netif->pid);
queue_size = msg_queue_len(netif->pid);
assert(queue_state > 0);

if ((queue_state * CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_DEN) >
(queue_size * CONFIG_GNRC_SIXLOWPAN_SFR_ECN_NETIF_NUM)) {
sixlowpan_sfr_set_ecn(frame->next->data);
}
}

if (IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR_ECN_FQUEUE)) {
queue_state = clist_count(&_frame_queue);
queue_size = FRAME_QUEUE_POOL_SIZE;

if ((queue_state * CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_DEN) >
(queue_size * CONFIG_GNRC_SIXLOWPAN_SFR_ECN_FQUEUE_NUM)) {
sixlowpan_sfr_set_ecn(frame->next->data);
}
}
}
gnrc_sixlowpan_dispatch_send(frame, ctx, page);
}

void gnrc_sixlowpan_frag_sfr_inter_frame_gap(void)
{
if (CONFIG_GNRC_SIXLOWPAN_SFR_INTER_FRAME_GAP_US > 0) {
_frame_queue_t *node = (_frame_queue_t *)clist_lpop(&_frame_queue);

if (node != NULL) {
_last_frame_sent = xtimer_now_usec();
gnrc_sixlowpan_dispatch_send(node->frame, NULL, node->page);
_6lo_dispatch_send(node->frame, NULL, node->page);
/* unset packet just to be safe */
node->frame = NULL;
clist_rpush(&_frame_queue_free, &node->super);
Expand Down Expand Up @@ -747,7 +782,7 @@ static bool _send_frame(gnrc_pktsnip_t *frame, void *ctx, unsigned page)
((now - _last_frame_sent) > CONFIG_GNRC_SIXLOWPAN_SFR_INTER_FRAME_GAP_US)) {
DEBUG("6lo sfr: dispatch frame to network interface\n");
_last_frame_sent = now;
gnrc_sixlowpan_dispatch_send(frame, ctx, page);
_6lo_dispatch_send(frame, ctx, page);
return true;
}
else {
Expand Down

0 comments on commit 5de1c19

Please sign in to comment.