Merge pull request #743 from kkrentz/csma-improvements-pr

General improvements to CSMA
This commit is contained in:
Simon Duquennoy 2018-11-11 14:43:10 +01:00 committed by GitHub
commit d4022a5628
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 45 deletions

View File

@ -50,6 +50,7 @@
#include "net/netstack.h"
#include "lib/list.h"
#include "lib/memb.h"
#include "lib/assert.h"
/* Log configuration */
#include "sys/log.h"
@ -131,7 +132,10 @@ MEMB(packet_memb, struct packet_queue, MAX_QUEUED_PACKETS);
MEMB(metadata_memb, struct qbuf_metadata, MAX_QUEUED_PACKETS);
LIST(neighbor_list);
static void packet_sent(void *ptr, int status, int num_transmissions);
static void packet_sent(struct neighbor_queue *n,
struct packet_queue *q,
int status,
int num_transmissions);
static void transmit_from_queue(void *ptr);
/*---------------------------------------------------------------------------*/
static struct neighbor_queue *
@ -162,7 +166,7 @@ backoff_period(void)
}
/*---------------------------------------------------------------------------*/
static int
send_one_packet(void *ptr)
send_one_packet(struct neighbor_queue *n, struct packet_queue *q)
{
int ret;
int last_sent_ok = 0;
@ -245,7 +249,7 @@ send_one_packet(void *ptr)
last_sent_ok = 1;
}
packet_sent(ptr, ret, 1);
packet_sent(n, q, ret, 1);
return last_sent_ok;
}
/*---------------------------------------------------------------------------*/
@ -263,7 +267,7 @@ transmit_from_queue(void *ptr)
n->transmissions, list_length(n->packet_queue));
/* Send first packet in the neighbor queue */
queuebuf_to_packetbuf(q->buf);
send_one_packet(n);
send_one_packet(n, q);
}
}
}
@ -396,30 +400,15 @@ tx_ok(struct packet_queue *q, struct neighbor_queue *n, int num_transmissions)
}
/*---------------------------------------------------------------------------*/
static void
packet_sent(void *ptr, int status, int num_transmissions)
packet_sent(struct neighbor_queue *n,
struct packet_queue *q,
int status,
int num_transmissions)
{
struct neighbor_queue *n;
struct packet_queue *q;
assert(n != NULL);
assert(q != NULL);
n = ptr;
if(n == NULL) {
return;
}
/* Find out what packet this callback refers to */
for(q = list_head(n->packet_queue);
q != NULL; q = list_item_next(q)) {
if(queuebuf_attr(q->buf, PACKETBUF_ATTR_MAC_SEQNO) ==
packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO)) {
break;
}
}
if(q == NULL) {
LOG_WARN("packet sent: seqno %u not found\n",
packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO));
return;
} else if(q->ptr == NULL) {
if(q->ptr == NULL) {
LOG_WARN("packet sent: no metadata\n");
return;
}

View File

@ -75,11 +75,7 @@ static void
input_packet(void)
{
#if CSMA_SEND_SOFT_ACK
int original_datalen;
uint8_t *original_dataptr;
original_datalen = packetbuf_datalen();
original_dataptr = packetbuf_dataptr();
uint8_t ackdata[CSMA_ACK_LEN];
#endif
if(packetbuf_datalen() == CSMA_ACK_LEN) {
@ -91,6 +87,8 @@ input_packet(void)
&linkaddr_node_addr) &&
!packetbuf_holds_broadcast()) {
LOG_WARN("not for us\n");
} else if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER), &linkaddr_node_addr)) {
LOG_WARN("frame from ourselves\n");
} else {
int duplicate = 0;
@ -106,20 +104,11 @@ input_packet(void)
}
#if CSMA_SEND_SOFT_ACK
{
frame802154_t info154;
frame802154_parse(original_dataptr, original_datalen, &info154);
if(info154.fcf.frame_type == FRAME802154_DATAFRAME &&
info154.fcf.ack_required != 0 &&
linkaddr_cmp((linkaddr_t *)&info154.dest_addr,
&linkaddr_node_addr)) {
uint8_t ackdata[CSMA_ACK_LEN] = {0, 0, 0};
ackdata[0] = FRAME802154_ACKFRAME;
ackdata[1] = 0;
ackdata[2] = info154.seq;
NETSTACK_RADIO.send(ackdata, CSMA_ACK_LEN);
}
if(packetbuf_attr(PACKETBUF_ATTR_MAC_ACK)) {
ackdata[0] = FRAME802154_ACKFRAME;
ackdata[1] = 0;
ackdata[2] = ((uint8_t *)packetbuf_hdrptr())[2];
NETSTACK_RADIO.send(ackdata, CSMA_ACK_LEN);
}
#endif /* CSMA_SEND_SOFT_ACK */
if(!duplicate) {

View File

@ -240,6 +240,7 @@ parse(void)
if(hdr_len && packetbuf_hdrreduce(hdr_len)) {
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, frame.fcf.frame_type);
packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, frame.fcf.ack_required);
if(frame.fcf.dest_addr_mode) {
if(frame.dest_pid != frame802154_get_pan_id() &&

View File

@ -87,6 +87,7 @@ parse(void)
}
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, frame.seq);
packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, frame.fcf.ack_required);
return 0;
}
#endif