mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #12318 from miri64/gnrc_sixlowpan_frag/enh/rbuf-rework201
gnrc_sixlowpan_frag: move public rbuf functions to their own module
This commit is contained in:
commit
5aae638bfd
@ -212,6 +212,7 @@ endif
|
||||
|
||||
ifneq (,$(filter gnrc_sixlowpan_frag,$(USEMODULE)))
|
||||
USEMODULE += gnrc_sixlowpan
|
||||
USEMODULE += gnrc_sixlowpan_frag_rb
|
||||
USEMODULE += xtimer
|
||||
endif
|
||||
|
||||
|
@ -5,6 +5,9 @@ endif
|
||||
ifneq (,$(filter gnrc_netif,$(USEMODULE)))
|
||||
USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/gnrc/netif/include
|
||||
endif
|
||||
ifneq (,$(filter gnrc_sixlowpan_frag_rb,$(USEMODULE)))
|
||||
USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/gnrc/network_layer/sixlowpan/frag
|
||||
endif
|
||||
ifneq (,$(filter gnrc_sock,$(USEMODULE)))
|
||||
USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/gnrc/sock/include
|
||||
ifneq (,$(filter gnrc_ipv6,$(USEMODULE)))
|
||||
|
@ -58,68 +58,6 @@ extern "C" {
|
||||
#define GNRC_SIXLOWPAN_MSG_FRAG_GC_RBUF (0x0226)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief Fragment intervals to identify limits of fragments and duplicates.
|
||||
*
|
||||
* @note Fragments MUST NOT overlap and overlapping fragments are to be
|
||||
* discarded
|
||||
*
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4944#section-5.3">
|
||||
* RFC 4944, section 5.3
|
||||
* </a>
|
||||
*/
|
||||
typedef struct gnrc_sixlowpan_rbuf_int {
|
||||
/**
|
||||
* @brief next element in fragment interval list
|
||||
*/
|
||||
struct gnrc_sixlowpan_rbuf_int *next;
|
||||
uint16_t start; /**< start byte of the fragment interval */
|
||||
uint16_t end; /**< end byte of the fragment interval */
|
||||
} gnrc_sixlowpan_rbuf_int_t;
|
||||
|
||||
/**
|
||||
* @brief Base class for both reassembly buffer and virtual reassembly buffer
|
||||
*
|
||||
* 1. the source address,
|
||||
* 2. the destination address,
|
||||
* 3. the datagram size, and
|
||||
* 4. the datagram tag
|
||||
*
|
||||
* to identify all fragments that belong to the given datagram.
|
||||
*
|
||||
* @see [RFC 4944, section 5.3](https://tools.ietf.org/html/rfc4944#section-5.3)
|
||||
* @see https://tools.ietf.org/html/draft-ietf-lwig-6lowpan-virtual-reassembly-01
|
||||
*/
|
||||
typedef struct {
|
||||
gnrc_sixlowpan_rbuf_int_t *ints; /**< intervals of already received fragments */
|
||||
uint8_t src[IEEE802154_LONG_ADDRESS_LEN]; /**< source address */
|
||||
uint8_t dst[IEEE802154_LONG_ADDRESS_LEN]; /**< destination address */
|
||||
uint8_t src_len; /**< length of gnrc_sixlowpan_rbuf_t::src */
|
||||
uint8_t dst_len; /**< length of gnrc_sixlowpan_rbuf_t::dst */
|
||||
uint16_t tag; /**< the datagram's tag */
|
||||
uint16_t datagram_size; /**< the datagram's size */
|
||||
/**
|
||||
* @brief The number of bytes currently received of the complete datagram
|
||||
*/
|
||||
uint16_t current_size;
|
||||
uint32_t arrival; /**< time in microseconds of arrival of
|
||||
* last received fragment */
|
||||
} gnrc_sixlowpan_rbuf_base_t;
|
||||
|
||||
/**
|
||||
* @brief An entry in the 6LoWPAN reassembly buffer.
|
||||
*
|
||||
* A recipient of a fragment SHALL use
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
gnrc_sixlowpan_rbuf_base_t super; /**< base class */
|
||||
/**
|
||||
* @brief The reassembled packet in the packet buffer
|
||||
*/
|
||||
gnrc_pktsnip_t *pkt;
|
||||
} gnrc_sixlowpan_rbuf_t;
|
||||
|
||||
/**
|
||||
* @brief Definition of 6LoWPAN fragmentation type.
|
||||
*/
|
||||
@ -204,18 +142,6 @@ void gnrc_sixlowpan_frag_recv(gnrc_pktsnip_t *pkt, void *ctx, unsigned page);
|
||||
*/
|
||||
uint16_t gnrc_sixlowpan_frag_next_tag(void);
|
||||
|
||||
/**
|
||||
* @brief Remove base entry
|
||||
*
|
||||
* @param[in,out] entry Entry to remove
|
||||
*/
|
||||
void gnrc_sixlowpan_frag_rbuf_base_rm(gnrc_sixlowpan_rbuf_base_t *entry);
|
||||
|
||||
/**
|
||||
* @brief Garbage collect reassembly buffer.
|
||||
*/
|
||||
void gnrc_sixlowpan_frag_rbuf_gc(void);
|
||||
|
||||
/**
|
||||
* @brief Sends a message to pass a further fragment down the network stack
|
||||
*
|
||||
@ -239,38 +165,6 @@ static inline bool gnrc_sixlowpan_frag_send_msg(gnrc_sixlowpan_msg_frag_t *fragm
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(MODULE_GNRC_SIXLOWPAN_FRAG) || defined(DOXYGEN)
|
||||
/**
|
||||
* @brief Removes an entry from the reassembly buffer
|
||||
*
|
||||
* @pre `rbuf != NULL`
|
||||
*
|
||||
* @param[in] rbuf A reassembly buffer entry. Must not be NULL.
|
||||
*/
|
||||
void gnrc_sixlowpan_frag_rbuf_remove(gnrc_sixlowpan_rbuf_t *rbuf);
|
||||
|
||||
/**
|
||||
* @brief Checks if a reassembly buffer entry is complete and dispatches it
|
||||
* to the next layer if that is the case
|
||||
*
|
||||
* @pre `rbuf != NULL`
|
||||
* @pre `netif != NULL`
|
||||
*
|
||||
* @param[in] rbuf A reassembly buffer entry. Must not be NULL.
|
||||
* @param[in] netif Original @ref gnrc_netif_hdr_t of the last received frame.
|
||||
* Used to construct the @ref gnrc_netif_hdr_t of the completed
|
||||
* datagram. Must not be NULL.
|
||||
*/
|
||||
void gnrc_sixlowpan_frag_rbuf_dispatch_when_complete(gnrc_sixlowpan_rbuf_t *rbuf,
|
||||
gnrc_netif_hdr_t *netif);
|
||||
#else
|
||||
/* NOPs to be used with gnrc_sixlowpan_iphc if gnrc_sixlowpan_frag is not
|
||||
* compiled in */
|
||||
#define gnrc_sixlowpan_frag_rbuf_remove(rbuf) (void)(rbuf)
|
||||
#define gnrc_sixlowpan_frag_rbuf_dispatch_when_complete(rbuf, netif) \
|
||||
(void)(rbuf); (void)(netif)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
140
sys/include/net/gnrc/sixlowpan/frag/rb.h
Normal file
140
sys/include/net/gnrc/sixlowpan/frag/rb.h
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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_rb 6LoWPAN reassembly buffer
|
||||
* @ingroup net_gnrc_sixlowpan_frag
|
||||
* @brief 6LoWPAN reassembly buffer
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Reassembly buffer definitions
|
||||
*
|
||||
* @author Martine Lenders <m.lenders@fu-berlin.de>
|
||||
*/
|
||||
#ifndef NET_GNRC_SIXLOWPAN_FRAG_RB_H
|
||||
#define NET_GNRC_SIXLOWPAN_FRAG_RB_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Fragment intervals to identify limits of fragments and duplicates.
|
||||
*
|
||||
* @note Fragments MUST NOT overlap and overlapping fragments are to be
|
||||
* discarded
|
||||
*
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4944#section-5.3">
|
||||
* RFC 4944, section 5.3
|
||||
* </a>
|
||||
*/
|
||||
typedef struct gnrc_sixlowpan_rbuf_int {
|
||||
/**
|
||||
* @brief next element in fragment interval list
|
||||
*/
|
||||
struct gnrc_sixlowpan_rbuf_int *next;
|
||||
uint16_t start; /**< start byte of the fragment interval */
|
||||
uint16_t end; /**< end byte of the fragment interval */
|
||||
} gnrc_sixlowpan_rbuf_int_t;
|
||||
|
||||
/**
|
||||
* @brief Base class for both reassembly buffer and virtual reassembly buffer
|
||||
*
|
||||
* 1. the source address,
|
||||
* 2. the destination address,
|
||||
* 3. the datagram size, and
|
||||
* 4. the datagram tag
|
||||
*
|
||||
* to identify all fragments that belong to the given datagram.
|
||||
*
|
||||
* @see [RFC 4944, section 5.3](https://tools.ietf.org/html/rfc4944#section-5.3)
|
||||
* @see https://tools.ietf.org/html/draft-ietf-lwig-6lowpan-virtual-reassembly-01
|
||||
*/
|
||||
typedef struct {
|
||||
gnrc_sixlowpan_rbuf_int_t *ints; /**< intervals of already received fragments */
|
||||
uint8_t src[IEEE802154_LONG_ADDRESS_LEN]; /**< source address */
|
||||
uint8_t dst[IEEE802154_LONG_ADDRESS_LEN]; /**< destination address */
|
||||
uint8_t src_len; /**< length of gnrc_sixlowpan_rbuf_t::src */
|
||||
uint8_t dst_len; /**< length of gnrc_sixlowpan_rbuf_t::dst */
|
||||
uint16_t tag; /**< the datagram's tag */
|
||||
uint16_t datagram_size; /**< the datagram's size */
|
||||
/**
|
||||
* @brief The number of bytes currently received of the complete datagram
|
||||
*/
|
||||
uint16_t current_size;
|
||||
uint32_t arrival; /**< time in microseconds of arrival of
|
||||
* last received fragment */
|
||||
} gnrc_sixlowpan_rbuf_base_t;
|
||||
|
||||
/**
|
||||
* @brief An entry in the 6LoWPAN reassembly buffer.
|
||||
*
|
||||
* A recipient of a fragment SHALL use
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
gnrc_sixlowpan_rbuf_base_t super; /**< base class */
|
||||
/**
|
||||
* @brief The reassembled packet in the packet buffer
|
||||
*/
|
||||
gnrc_pktsnip_t *pkt;
|
||||
} gnrc_sixlowpan_rbuf_t;
|
||||
|
||||
/**
|
||||
* @brief Remove base entry
|
||||
*
|
||||
* @param[in,out] entry Entry to remove
|
||||
*/
|
||||
void gnrc_sixlowpan_frag_rbuf_base_rm(gnrc_sixlowpan_rbuf_base_t *entry);
|
||||
|
||||
/**
|
||||
* @brief Garbage collect reassembly buffer.
|
||||
*/
|
||||
void gnrc_sixlowpan_frag_rbuf_gc(void);
|
||||
|
||||
#if defined(MODULE_GNRC_SIXLOWPAN_FRAG) || defined(DOXYGEN)
|
||||
/**
|
||||
* @brief Removes an entry from the reassembly buffer
|
||||
*
|
||||
* @pre `rbuf != NULL`
|
||||
*
|
||||
* @param[in] rbuf A reassembly buffer entry. Must not be NULL.
|
||||
*/
|
||||
void gnrc_sixlowpan_frag_rbuf_remove(gnrc_sixlowpan_rbuf_t *rbuf);
|
||||
|
||||
/**
|
||||
* @brief Checks if a reassembly buffer entry is complete and dispatches it
|
||||
* to the next layer if that is the case
|
||||
*
|
||||
* @pre `rbuf != NULL`
|
||||
* @pre `netif != NULL`
|
||||
*
|
||||
* @param[in] rbuf A reassembly buffer entry. Must not be NULL.
|
||||
* @param[in] netif Original @ref gnrc_netif_hdr_t of the last received frame.
|
||||
* Used to construct the @ref gnrc_netif_hdr_t of the completed
|
||||
* datagram. Must not be NULL.
|
||||
*/
|
||||
void gnrc_sixlowpan_frag_rbuf_dispatch_when_complete(gnrc_sixlowpan_rbuf_t *rbuf,
|
||||
gnrc_netif_hdr_t *netif);
|
||||
#else
|
||||
/* NOPs to be used with gnrc_sixlowpan_iphc if gnrc_sixlowpan_frag is not
|
||||
* compiled in */
|
||||
#define gnrc_sixlowpan_frag_rbuf_remove(rbuf) (void)(rbuf)
|
||||
#define gnrc_sixlowpan_frag_rbuf_dispatch_when_complete(rbuf, netif) \
|
||||
(void)(rbuf); (void)(netif)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NET_GNRC_SIXLOWPAN_FRAG_RB_H */
|
||||
/** @} */
|
@ -27,7 +27,7 @@
|
||||
|
||||
#include "net/gnrc/netif.h"
|
||||
#include "net/gnrc/sixlowpan/config.h"
|
||||
#include "net/gnrc/sixlowpan/frag.h"
|
||||
#include "net/gnrc/sixlowpan/frag/rb.h"
|
||||
#include "timex.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -91,6 +91,9 @@ endif
|
||||
ifneq (,$(filter gnrc_sixlowpan_frag,$(USEMODULE)))
|
||||
DIRS += network_layer/sixlowpan/frag
|
||||
endif
|
||||
ifneq (,$(filter gnrc_sixlowpan_frag_rb,$(USEMODULE)))
|
||||
DIRS += network_layer/sixlowpan/frag/rb
|
||||
endif
|
||||
ifneq (,$(filter gnrc_sixlowpan_frag_vrb,$(USEMODULE)))
|
||||
DIRS += network_layer/sixlowpan/frag/vrb
|
||||
endif
|
||||
|
@ -368,61 +368,4 @@ uint16_t gnrc_sixlowpan_frag_next_tag(void)
|
||||
return (++_current_tag);
|
||||
}
|
||||
|
||||
void gnrc_sixlowpan_frag_rbuf_base_rm(gnrc_sixlowpan_rbuf_base_t *entry)
|
||||
{
|
||||
while (entry->ints != NULL) {
|
||||
gnrc_sixlowpan_rbuf_int_t *next = entry->ints->next;
|
||||
|
||||
entry->ints->start = 0;
|
||||
entry->ints->end = 0;
|
||||
entry->ints->next = NULL;
|
||||
entry->ints = next;
|
||||
}
|
||||
entry->datagram_size = 0;
|
||||
}
|
||||
|
||||
void gnrc_sixlowpan_frag_rbuf_gc(void)
|
||||
{
|
||||
rbuf_gc();
|
||||
}
|
||||
|
||||
void gnrc_sixlowpan_frag_rbuf_remove(gnrc_sixlowpan_rbuf_t *rbuf)
|
||||
{
|
||||
assert(rbuf != NULL);
|
||||
rbuf_rm(rbuf);
|
||||
}
|
||||
|
||||
void gnrc_sixlowpan_frag_rbuf_dispatch_when_complete(gnrc_sixlowpan_rbuf_t *rbuf,
|
||||
gnrc_netif_hdr_t *netif_hdr)
|
||||
{
|
||||
assert(rbuf);
|
||||
assert(netif_hdr);
|
||||
if (rbuf->super.current_size == rbuf->super.datagram_size) {
|
||||
gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(rbuf->super.src,
|
||||
rbuf->super.src_len,
|
||||
rbuf->super.dst,
|
||||
rbuf->super.dst_len);
|
||||
|
||||
if (netif == NULL) {
|
||||
DEBUG("6lo rbuf: error allocating netif header\n");
|
||||
gnrc_pktbuf_release(rbuf->pkt);
|
||||
gnrc_sixlowpan_frag_rbuf_remove(rbuf);
|
||||
return;
|
||||
}
|
||||
|
||||
/* copy the transmit information of the latest fragment into the newly
|
||||
* created header to have some link_layer information. The link_layer
|
||||
* info of the previous fragments is discarded.
|
||||
*/
|
||||
gnrc_netif_hdr_t *new_netif_hdr = netif->data;
|
||||
new_netif_hdr->if_pid = netif_hdr->if_pid;
|
||||
new_netif_hdr->flags = netif_hdr->flags;
|
||||
new_netif_hdr->lqi = netif_hdr->lqi;
|
||||
new_netif_hdr->rssi = netif_hdr->rssi;
|
||||
LL_APPEND(rbuf->pkt, netif);
|
||||
gnrc_sixlowpan_dispatch_recv(rbuf->pkt, NULL, 0);
|
||||
gnrc_sixlowpan_frag_rbuf_remove(rbuf);
|
||||
}
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
3
sys/net/gnrc/network_layer/sixlowpan/frag/rb/Makefile
Normal file
3
sys/net/gnrc/network_layer/sixlowpan/frag/rb/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
MODULE := gnrc_sixlowpan_frag_rb
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 "net/ieee802154.h"
|
||||
#include "net/gnrc/netif/hdr.h"
|
||||
#include "net/gnrc/pkt.h"
|
||||
#include "net/gnrc/sixlowpan.h"
|
||||
|
||||
#include "net/gnrc/sixlowpan/frag/rb.h"
|
||||
|
||||
#include "rbuf.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
void gnrc_sixlowpan_frag_rbuf_base_rm(gnrc_sixlowpan_rbuf_base_t *entry)
|
||||
{
|
||||
while (entry->ints != NULL) {
|
||||
gnrc_sixlowpan_rbuf_int_t *next = entry->ints->next;
|
||||
|
||||
entry->ints->start = 0;
|
||||
entry->ints->end = 0;
|
||||
entry->ints->next = NULL;
|
||||
entry->ints = next;
|
||||
}
|
||||
entry->datagram_size = 0;
|
||||
}
|
||||
|
||||
void gnrc_sixlowpan_frag_rbuf_gc(void)
|
||||
{
|
||||
rbuf_gc();
|
||||
}
|
||||
|
||||
void gnrc_sixlowpan_frag_rbuf_remove(gnrc_sixlowpan_rbuf_t *rbuf)
|
||||
{
|
||||
assert(rbuf != NULL);
|
||||
rbuf_rm(rbuf);
|
||||
}
|
||||
|
||||
void gnrc_sixlowpan_frag_rbuf_dispatch_when_complete(gnrc_sixlowpan_rbuf_t *rbuf,
|
||||
gnrc_netif_hdr_t *netif_hdr)
|
||||
{
|
||||
assert(rbuf);
|
||||
assert(netif_hdr);
|
||||
if (rbuf->super.current_size == rbuf->super.datagram_size) {
|
||||
gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(rbuf->super.src,
|
||||
rbuf->super.src_len,
|
||||
rbuf->super.dst,
|
||||
rbuf->super.dst_len);
|
||||
|
||||
if (netif == NULL) {
|
||||
DEBUG("6lo rbuf: error allocating netif header\n");
|
||||
gnrc_pktbuf_release(rbuf->pkt);
|
||||
gnrc_sixlowpan_frag_rbuf_remove(rbuf);
|
||||
return;
|
||||
}
|
||||
|
||||
/* copy the transmit information of the latest fragment into the newly
|
||||
* created header to have some link_layer information. The link_layer
|
||||
* info of the previous fragments is discarded.
|
||||
*/
|
||||
gnrc_netif_hdr_t *new_netif_hdr = netif->data;
|
||||
new_netif_hdr->if_pid = netif_hdr->if_pid;
|
||||
new_netif_hdr->flags = netif_hdr->flags;
|
||||
new_netif_hdr->lqi = netif_hdr->lqi;
|
||||
new_netif_hdr->rssi = netif_hdr->rssi;
|
||||
LL_APPEND(rbuf->pkt, netif);
|
||||
gnrc_sixlowpan_dispatch_recv(rbuf->pkt, NULL, 0);
|
||||
gnrc_sixlowpan_frag_rbuf_remove(rbuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** @} */
|
@ -26,7 +26,7 @@
|
||||
#include "net/gnrc/pkt.h"
|
||||
|
||||
#include "net/gnrc/sixlowpan/config.h"
|
||||
#include "net/gnrc/sixlowpan/frag.h"
|
||||
#include "net/gnrc/sixlowpan/frag/rb.h"
|
||||
#ifdef __cplusplus
|
||||
|
||||
extern "C" {
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "net/gnrc/ipv6/hdr.h"
|
||||
#include "net/gnrc/sixlowpan.h"
|
||||
#include "net/gnrc/sixlowpan/frag.h"
|
||||
#include "net/gnrc/sixlowpan/frag/rb.h"
|
||||
#include "net/gnrc/sixlowpan/iphc.h"
|
||||
#include "net/gnrc/netif.h"
|
||||
#include "net/sixlowpan.h"
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "net/gnrc/netif/internal.h"
|
||||
#include "net/gnrc/sixlowpan.h"
|
||||
#include "net/gnrc/sixlowpan/ctx.h"
|
||||
#include "net/gnrc/sixlowpan/frag.h"
|
||||
#include "net/gnrc/sixlowpan/frag/rb.h"
|
||||
#include "net/gnrc/sixlowpan/internal.h"
|
||||
#include "net/sixlowpan.h"
|
||||
#include "utlist.h"
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "embUnit.h"
|
||||
#include "net/gnrc/pktbuf.h"
|
||||
#include "net/gnrc/netreg.h"
|
||||
#include "net/gnrc/sixlowpan/frag.h"
|
||||
#include "rbuf.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user