Merge pull request #4770 from Yonezawa-T2/rbuf_usec

rbuf: change arrival time unit from seconds to microseconds
This commit is contained in:
Oleg Hahm 2016-02-16 11:38:06 +01:00
commit 0a65d8c558
2 changed files with 11 additions and 11 deletions

View File

@ -240,7 +240,7 @@ static bool _rbuf_update_ints(rbuf_t *entry, uint16_t offset, size_t frag_size)
static void _rbuf_gc(void)
{
rbuf_t *oldest = NULL;
uint32_t now_sec = xtimer_now() / SEC_IN_USEC;
uint32_t now_usec = xtimer_now();
unsigned int i;
for (i = 0; i < RBUF_SIZE; i++) {
@ -248,7 +248,7 @@ static void _rbuf_gc(void)
return;
}
else if ((rbuf[i].pkt != NULL) &&
((now_sec - rbuf[i].arrival) > RBUF_TIMEOUT)) {
((now_usec - rbuf[i].arrival) > RBUF_TIMEOUT)) {
DEBUG("6lo rfrag: entry (%s, ", gnrc_netif_addr_to_str(l2addr_str,
sizeof(l2addr_str), rbuf[i].src, rbuf[i].src_len));
DEBUG("%s, %u, %u) timed out\n",
@ -259,7 +259,7 @@ static void _rbuf_gc(void)
gnrc_pktbuf_release(rbuf[i].pkt);
_rbuf_rem(&(rbuf[i]));
}
else if ((oldest == NULL) || (rbuf[i].arrival < oldest->arrival)) {
else if ((oldest == NULL) || ((oldest->arrival - rbuf[i].arrival) < (UINT32_MAX / 2))) {
oldest = &(rbuf[i]);
}
}
@ -276,7 +276,7 @@ static rbuf_t *_rbuf_get(const void *src, size_t src_len,
size_t size, uint16_t tag)
{
rbuf_t *res = NULL;
uint32_t now_sec = xtimer_now() / SEC_IN_USEC;
uint32_t now_usec = xtimer_now();
for (unsigned int i = 0; i < RBUF_SIZE; i++) {
/* check first if entry already available */
@ -292,7 +292,7 @@ static rbuf_t *_rbuf_get(const void *src, size_t src_len,
gnrc_netif_addr_to_str(l2addr_str, sizeof(l2addr_str),
rbuf[i].dst, rbuf[i].dst_len),
(unsigned)rbuf[i].pkt->size, rbuf[i].tag);
rbuf[i].arrival = now_sec;
rbuf[i].arrival = now_usec;
return &(rbuf[i]);
}
@ -311,7 +311,7 @@ static rbuf_t *_rbuf_get(const void *src, size_t src_len,
*((uint64_t *)res->pkt->data) = 0; /* clean first few bytes for later
* look-ups */
res->arrival = now_sec;
res->arrival = now_usec;
memcpy(res->src, src, src_len);
memcpy(res->dst, dst, dst_len);
res->src_len = src_len;

View File

@ -30,9 +30,9 @@
extern "C" {
#endif
#define RBUF_L2ADDR_MAX_LEN (8U) /**< maximum length for link-layer addresses */
#define RBUF_SIZE (4U) /**< size of the reassembly buffer */
#define RBUF_TIMEOUT (3U) /**< timeout for reassembly in seconds */
#define RBUF_L2ADDR_MAX_LEN (8U) /**< maximum length for link-layer addresses */
#define RBUF_SIZE (4U) /**< size of the reassembly buffer */
#define RBUF_TIMEOUT (3U * SEC_IN_USEC) /**< timeout for reassembly in microseconds */
/**
* @brief Fragment intervals to identify limits of fragments.
@ -73,8 +73,8 @@ typedef struct rbuf_int {
typedef struct {
rbuf_int_t *ints; /**< intervals of the fragment */
gnrc_pktsnip_t *pkt; /**< the reassembled packet in packet buffer */
uint32_t arrival; /**< time in seconds of arrival of last
* received fragment */
uint32_t arrival; /**< time in microseconds of arrival of
* last received fragment */
uint8_t src[RBUF_L2ADDR_MAX_LEN]; /**< source address */
uint8_t dst[RBUF_L2ADDR_MAX_LEN]; /**< destination address */
uint8_t src_len; /**< length of source address */