-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12559 from miri64/gnrc_sixlowpan_frag/enh/factor-…
…out-frag-buf gnrc_sixlowpan_frag: factor-out and rename fragmentation buffer
- Loading branch information
Showing
11 changed files
with
273 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MODULE := gnrc_sixlowpan_frag_fb | ||
|
||
include $(RIOTBASE)/Makefile.base |
64 changes: 64 additions & 0 deletions
64
sys/net/gnrc/network_layer/sixlowpan/frag/fb/gnrc_sixlowpan_frag_fb.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
/** @} */ |
Oops, something went wrong.