Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

gnrc_sixlowpan_frag: factor-out and rename fragmentation buffer #12559

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,21 @@ endif

ifneq (,$(filter gnrc_sixlowpan_frag,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan
USEMODULE += gnrc_sixlowpan_frag_fb
USEMODULE += gnrc_sixlowpan_frag_rb
endif

ifneq (,$(filter gnrc_sixlowpan_frag_fb,$(USEMODULE)))
USEMODULE += core_msg
endif

ifneq (,$(filter gnrc_sixlowpan_frag_rb,$(USEMODULE)))
USEMODULE += xtimer
endif

ifneq (,$(filter gnrc_sixlowpan_frag_vrb,$(USEMODULE)))
USEMODULE += xtimer
USEMODULE += gnrc_sixlowpan_frag_fb
endif

ifneq (,$(filter gnrc_sixlowpan_iphc,$(USEMODULE)))
Expand Down
8 changes: 4 additions & 4 deletions sys/include/net/gnrc/sixlowpan/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ extern "C" {
/**
* @brief Number of datagrams that can be fragmented simultaneously
*
* This determines the number of @ref gnrc_sixlowpan_msg_frag_t instances
* This determines the number of @ref gnrc_sixlowpan_frag_fb_t instances
* available.
*
* @note Only applicable with
* [gnrc_sixlowpan_frag](@ref net_gnrc_sixlowpan_frag) module
* [gnrc_sixlowpan_frag_fb](@ref net_gnrc_sixlowpan_frag_fb) module
*/
#ifndef GNRC_SIXLOWPAN_MSG_FRAG_SIZE
#define GNRC_SIXLOWPAN_MSG_FRAG_SIZE (1U)
#ifndef GNRC_SIXLOWPAN_FRAG_FB_SIZE
#define GNRC_SIXLOWPAN_FRAG_FB_SIZE (1U)
#endif

/**
Expand Down
80 changes: 6 additions & 74 deletions sys/include/net/gnrc/sixlowpan/frag.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
#define NET_GNRC_SIXLOWPAN_FRAG_H

#include <inttypes.h>
#include <stdbool.h>

#include "byteorder.h"
#include "msg.h"
#include "net/gnrc/pkt.h"
#include "net/gnrc/netif/hdr.h"
#ifdef MODULE_GNRC_SIXLOWPAN_FRAG_HINT
#include "net/gnrc/sixlowpan/frag/hint.h"
#endif /* MODULE_GNRC_SIXLOWPAN_FRAG_HINT */
#include "net/gnrc/sixlowpan/frag/fb.h"
#include "net/gnrc/sixlowpan/internal.h"
#include "net/ieee802154.h"
#include "net/sixlowpan.h"
Expand All @@ -43,34 +42,6 @@
extern "C" {
#endif

/**
* @name Message types
* @{
*/
/**
* @brief Message type for passing one 6LoWPAN fragment down the network stack
*/
#define GNRC_SIXLOWPAN_MSG_FRAG_SND (0x0225)
/** @} */

/**
* @brief Definition of 6LoWPAN fragmentation type.
*/
typedef struct {
gnrc_pktsnip_t *pkt; /**< Pointer to the IPv6 packet to be fragmented */
uint16_t datagram_size; /**< Length of just the (uncompressed) IPv6 packet to be fragmented */
uint16_t tag; /**< Tag used for the fragment */
uint16_t offset; /**< Offset of the Nth fragment from the beginning of the
* payload datagram */
#ifdef MODULE_GNRC_SIXLOWPAN_FRAG_HINT
/**
* @brief Hint for the size (smaller than link-layer PDU) for the next
* fragment to sent
*/
gnrc_sixlowpan_frag_hint_t hint;
#endif /* MODULE_GNRC_SIXLOWPAN_FRAG_HINT */
} gnrc_sixlowpan_msg_frag_t;

#if defined(MODULE_GNRC_SIXLOWPAN_FRAG_STATS) || DOXYGEN
/**
* @brief Statistics on fragmentation and reassembly
Expand All @@ -81,7 +52,7 @@ typedef struct {
unsigned rbuf_full; /**< counts the number of events where the
* reassembly buffer is full */
unsigned frag_full; /**< counts the number of events that there where
* no @ref gnrc_sixlowpan_msg_frag_t available */
* no @ref gnrc_sixlowpan_frag_fb_t available */
#if defined(MODULE_GNRC_SIXLOWPAN_FRAG_VRB) || DOXYGEN
unsigned vrb_full; /**< counts the number of events where the virtual
* reassembly buffer is full */
Expand All @@ -96,26 +67,17 @@ typedef struct {
gnrc_sixlowpan_frag_stats_t *gnrc_sixlowpan_frag_stats_get(void);
#endif

/**
* @brief Allocates a @ref gnrc_sixlowpan_msg_frag_t object
*
* @return A @ref gnrc_sixlowpan_msg_frag_t if available
* @return NULL, otherwise
*/
gnrc_sixlowpan_msg_frag_t *gnrc_sixlowpan_msg_frag_get(void);

/**
* @brief Sends a packet fragmented
*
* @pre `ctx != NULL`
* @pre gnrc_sixlowpan_msg_frag_t::pkt of @p ctx is equal to @p pkt or
* @pre gnrc_sixlowpan_frag_fb_t::pkt of @p ctx is equal to @p pkt or
* `pkt == NULL`.
*
* @param[in] pkt A packet. May be NULL.
* @param[in] ctx Message containing status of the 6LoWPAN fragmentation
* progress. Expected to be of type
* @ref gnrc_sixlowpan_msg_frag_t, with
* gnrc_sixlowpan_msg_frag_t set to @p pkt. Must not be
* @param[in] ctx A fragmentation buffer entry. Expected to be of type
* @ref gnrc_sixlowpan_frag_fb_t, with
* gnrc_sixlowpan_frag_fb_t set to @p pkt. Must not be
* NULL.
* @param[in] page Current 6Lo dispatch parsing page.
*/
Expand All @@ -130,36 +92,6 @@ void gnrc_sixlowpan_frag_send(gnrc_pktsnip_t *pkt, void *ctx, unsigned page);
*/
void gnrc_sixlowpan_frag_recv(gnrc_pktsnip_t *pkt, void *ctx, unsigned page);

/**
* @brief Generate a new datagram tag for sending
*
* @return A new datagram tag.
*/
uint16_t gnrc_sixlowpan_frag_next_tag(void);

/**
* @brief Sends a message to pass a further fragment down the network stack
*
* @see GNRC_SIXLOWPAN_MSG_FRAG_SND
*
* @param[in] fragment_msg A @ref gnrc_sixlowpan_msg_frag_t object
*
* @return true, when the message was sent
* @return false when sending the message failed.
*/
static inline bool gnrc_sixlowpan_frag_send_msg(gnrc_sixlowpan_msg_frag_t *fragment_msg)
{
msg_t msg;

msg.content.ptr = fragment_msg;
msg.type = GNRC_SIXLOWPAN_MSG_FRAG_SND;
#ifdef TEST_SUITES
return (msg_try_send(&msg, gnrc_sixlowpan_get_pid()) > 0);
#else
return (msg_send_to_self(&msg) != 0);
#endif
}

#ifdef __cplusplus
}
#endif
Expand Down
125 changes: 125 additions & 0 deletions sys/include/net/gnrc/sixlowpan/frag/fb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright (C) 2019 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @defgroup net_gnrc_sixlowpan_frag_fb 6LoWPAN fragmentation buffer
* @ingroup net_gnrc_sixlowpan_frag
* @brief Buffer for asynchronous 6LoWPAN fragmentation
* @{
*
* @file
* @brief Fragmentation buffer definitions
*
* @author Martine Lenders <m.lenders@fu-berlin.de>
*/
#ifndef NET_GNRC_SIXLOWPAN_FRAG_FB_H
#define NET_GNRC_SIXLOWPAN_FRAG_FB_H

#include <stdbool.h>
#include <stdint.h>

#include "msg.h"
#include "net/gnrc/pkt.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Message type for passing one 6LoWPAN fragment down the network stack
*/
#define GNRC_SIXLOWPAN_FRAG_FB_SND_MSG (0x0225)

/**
* @brief 6LoWPAN fragmentation buffer entry.
*/
typedef struct {
gnrc_pktsnip_t *pkt; /**< Pointer to the IPv6 packet to be fragmented */
uint16_t datagram_size; /**< Length of just the (uncompressed) IPv6 packet to be fragmented */
uint16_t tag; /**< Tag used for the fragment */
uint16_t offset; /**< Offset of the Nth fragment from the beginning of the
* payload datagram */
#ifdef MODULE_GNRC_SIXLOWPAN_FRAG_HINT
/**
* @brief Hint for the size (smaller than link-layer PDU) for the next
* fragment to sent
*/
gnrc_sixlowpan_frag_hint_t hint;
#endif /* MODULE_GNRC_SIXLOWPAN_FRAG_HINT */
} gnrc_sixlowpan_frag_fb_t;

#ifdef TEST_SUITES
/**
* @brief Reset fragmentation buffer
*
* @note Only available with test
*/
void gnrc_sixlowpan_frag_fb_reset(void);
#endif

/**
* @brief Allocates a fragmentation buffer entry
*
* @return A fragmentation buffer entry if available
* @return NULL, otherwise
*/
gnrc_sixlowpan_frag_fb_t *gnrc_sixlowpan_frag_fb_get(void);

/**
* @brief Get an existing fragmentation buffer entry by a given tag
*
* @param[in] tag Tag to search for.
*
* @return a fragmentation buffer entry if one with @p tag exists.
* @return NULL, if no fragmentation buffer entry can be found.
*/
gnrc_sixlowpan_frag_fb_t *gnrc_sixlowpan_frag_fb_get_by_tag(uint16_t tag);

/**
* @brief Generate a new datagram tag for sending
*
* @return A new datagram tag.
*/
uint16_t gnrc_sixlowpan_frag_fb_next_tag(void);

#if defined(TEST_SUITES) && !defined(DOXYGEN)
#include "kernel_types.h"

/* can't include `net/sixlowpan.h` as this would create a cyclical include */
extern kernel_pid_t gnrc_sixlowpan_get_pid(void);
#endif

/**
* @brief Sends a message to pass a further fragment down the network stack
*
* @see GNRC_SIXLOWPAN_MSG_FRAG_SND
*
* @param[in] fbuf A fragmentation buffer entry
*]
* @return true, when the message was sent
* @return false when sending the message failed.
*/
static inline bool gnrc_sixlowpan_frag_fb_send(gnrc_sixlowpan_frag_fb_t *fbuf)
{
msg_t msg;

msg.content.ptr = fbuf;
msg.type = GNRC_SIXLOWPAN_FRAG_FB_SND_MSG;
#ifdef TEST_SUITES
return (msg_try_send(&msg, gnrc_sixlowpan_get_pid()) > 0);
#else
return (msg_send_to_self(&msg) != 0);
#endif
}

#ifdef __cplusplus
}
#endif

#endif /* NET_GNRC_SIXLOWPAN_FRAG_FB_H */
/** @} */
3 changes: 3 additions & 0 deletions sys/net/gnrc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ endif
ifneq (,$(filter gnrc_sixlowpan_frag,$(USEMODULE)))
DIRS += network_layer/sixlowpan/frag
endif
ifneq (,$(filter gnrc_sixlowpan_frag_fb,$(USEMODULE)))
DIRS += network_layer/sixlowpan/frag/fb
endif
ifneq (,$(filter gnrc_sixlowpan_frag_rb,$(USEMODULE)))
DIRS += network_layer/sixlowpan/frag/rb
endif
Expand Down
3 changes: 3 additions & 0 deletions sys/net/gnrc/network_layer/sixlowpan/frag/fb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE := gnrc_sixlowpan_frag_fb

include $(RIOTBASE)/Makefile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2019 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @{
*
* @file
* @author Martine Lenders <m.lenders@fu-berlin.de>
*/

#include <stdint.h>
#include <string.h>

#include "net/gnrc/sixlowpan/config.h"
#include "net/gnrc/sixlowpan/frag/fb.h"
#ifdef MODULE_GNRC_SIXLOWPAN_FRAG_STATS
#include "net/gnrc/sixlowpan/frag/stats.h"
#endif

static gnrc_sixlowpan_frag_fb_t _fbs[GNRC_SIXLOWPAN_FRAG_FB_SIZE];
static uint16_t _current_tag;

#ifdef TEST_SUITES
void gnrc_sixlowpan_frag_fb_reset(void)
{
memset(_fbs, 0, sizeof(_fbs));
_current_tag = 0;
}
#endif

gnrc_sixlowpan_frag_fb_t *gnrc_sixlowpan_frag_fb_get(void)
{
for (unsigned i = 0; i < GNRC_SIXLOWPAN_FRAG_FB_SIZE; i++) {
if (_fbs[i].pkt == NULL) {
return &_fbs[i];
}
}
#ifdef MODULE_GNRC_SIXLOWPAN_FRAG_STATS
gnrc_sixlowpan_frag_stats_get()->frag_full++;
#endif
return NULL;
}

gnrc_sixlowpan_frag_fb_t *gnrc_sixlowpan_frag_fb_get_by_tag(uint16_t tag)
{
for (unsigned i = 0; i < GNRC_SIXLOWPAN_FRAG_FB_SIZE; i++) {
if ((_fbs[i].pkt != NULL) && (_fbs[i].tag == tag)) {
return &_fbs[i];
}
}
return NULL;
}

uint16_t gnrc_sixlowpan_frag_fb_next_tag(void)
{
return (++_current_tag);
}

/** @} */
Loading