Add per neighbor packet throttle
This commit is contained in:
parent
91d84a3086
commit
7cbd59df03
1 changed files with 51 additions and 40 deletions
|
@ -108,6 +108,13 @@ struct neighbor_queue {
|
||||||
#define CSMA_MAX_NEIGHBOR_QUEUES 2
|
#define CSMA_MAX_NEIGHBOR_QUEUES 2
|
||||||
#endif /* CSMA_CONF_MAX_NEIGHBOR_QUEUES */
|
#endif /* CSMA_CONF_MAX_NEIGHBOR_QUEUES */
|
||||||
|
|
||||||
|
/* The maximum number of pending packet per neighbor */
|
||||||
|
#ifdef CSMA_CONF_MAX_PACKET_PER_NEIGHBOR
|
||||||
|
#define CSMA_MAX_PACKET_PER_NEIGHBOR CSMA_CONF_MAX_PACKET_PER_NEIGHBOR
|
||||||
|
#else
|
||||||
|
#define CSMA_MAX_PACKET_PER_NEIGHBOR MAX_QUEUED_PACKETS
|
||||||
|
#endif /* CSMA_CONF_MAX_PACKET_PER_NEIGHBOR */
|
||||||
|
|
||||||
#define MAX_QUEUED_PACKETS QUEUEBUF_NUM
|
#define MAX_QUEUED_PACKETS QUEUEBUF_NUM
|
||||||
MEMB(neighbor_memb, struct neighbor_queue, CSMA_MAX_NEIGHBOR_QUEUES);
|
MEMB(neighbor_memb, struct neighbor_queue, CSMA_MAX_NEIGHBOR_QUEUES);
|
||||||
MEMB(packet_memb, struct rdc_buf_list, MAX_QUEUED_PACKETS);
|
MEMB(packet_memb, struct rdc_buf_list, MAX_QUEUED_PACKETS);
|
||||||
|
@ -348,49 +355,53 @@ send_packet(mac_callback_t sent, void *ptr)
|
||||||
|
|
||||||
if(n != NULL) {
|
if(n != NULL) {
|
||||||
/* Add packet to the neighbor's queue */
|
/* Add packet to the neighbor's queue */
|
||||||
q = memb_alloc(&packet_memb);
|
if(list_length(n->queued_packet_list) < CSMA_MAX_PACKET_PER_NEIGHBOR) {
|
||||||
if(q != NULL) {
|
q = memb_alloc(&packet_memb);
|
||||||
q->ptr = memb_alloc(&metadata_memb);
|
if(q != NULL) {
|
||||||
if(q->ptr != NULL) {
|
q->ptr = memb_alloc(&metadata_memb);
|
||||||
q->buf = queuebuf_new_from_packetbuf();
|
if(q->ptr != NULL) {
|
||||||
if(q->buf != NULL) {
|
q->buf = queuebuf_new_from_packetbuf();
|
||||||
struct qbuf_metadata *metadata = (struct qbuf_metadata *)q->ptr;
|
if(q->buf != NULL) {
|
||||||
/* Neighbor and packet successfully allocated */
|
struct qbuf_metadata *metadata = (struct qbuf_metadata *)q->ptr;
|
||||||
if(packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS) == 0) {
|
/* Neighbor and packet successfully allocated */
|
||||||
/* Use default configuration for max transmissions */
|
if(packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS) == 0) {
|
||||||
metadata->max_transmissions = CSMA_MAX_MAC_TRANSMISSIONS;
|
/* Use default configuration for max transmissions */
|
||||||
} else {
|
metadata->max_transmissions = CSMA_MAX_MAC_TRANSMISSIONS;
|
||||||
metadata->max_transmissions =
|
} else {
|
||||||
packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS);
|
metadata->max_transmissions =
|
||||||
}
|
packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS);
|
||||||
metadata->sent = sent;
|
}
|
||||||
metadata->cptr = ptr;
|
metadata->sent = sent;
|
||||||
|
metadata->cptr = ptr;
|
||||||
|
|
||||||
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
|
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
|
||||||
PACKETBUF_ATTR_PACKET_TYPE_ACK) {
|
PACKETBUF_ATTR_PACKET_TYPE_ACK) {
|
||||||
list_push(n->queued_packet_list, q);
|
list_push(n->queued_packet_list, q);
|
||||||
} else {
|
} else {
|
||||||
list_add(n->queued_packet_list, q);
|
list_add(n->queued_packet_list, q);
|
||||||
}
|
}
|
||||||
|
|
||||||
PRINTF("csma: send_packet, queue length %d, free packets %d\n",
|
PRINTF("csma: send_packet, queue length %d, free packets %d\n",
|
||||||
list_length(n->queued_packet_list), memb_numfree(&packet_memb));
|
list_length(n->queued_packet_list), memb_numfree(&packet_memb));
|
||||||
/* If q is the first packet in the neighbor's queue, send asap */
|
/* If q is the first packet in the neighbor's queue, send asap */
|
||||||
if(list_head(n->queued_packet_list) == q) {
|
if(list_head(n->queued_packet_list) == q) {
|
||||||
ctimer_set(&n->transmit_timer, 0, transmit_packet_list, n);
|
ctimer_set(&n->transmit_timer, 0, transmit_packet_list, n);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memb_free(&metadata_memb, q->ptr);
|
memb_free(&metadata_memb, q->ptr);
|
||||||
PRINTF("csma: could not allocate queuebuf, dropping packet\n");
|
PRINTF("csma: could not allocate queuebuf, dropping packet\n");
|
||||||
|
}
|
||||||
|
memb_free(&packet_memb, q);
|
||||||
|
PRINTF("csma: could not allocate queuebuf, dropping packet\n");
|
||||||
}
|
}
|
||||||
memb_free(&packet_memb, q);
|
/* The packet allocation failed. Remove and free neighbor entry if empty. */
|
||||||
PRINTF("csma: could not allocate queuebuf, dropping packet\n");
|
if(list_length(n->queued_packet_list) == 0) {
|
||||||
}
|
list_remove(neighbor_list, n);
|
||||||
/* The packet allocation failed. Remove and free neighbor entry if empty. */
|
memb_free(&neighbor_memb, n);
|
||||||
if(list_length(n->queued_packet_list) == 0) {
|
}
|
||||||
list_remove(neighbor_list, n);
|
} else {
|
||||||
memb_free(&neighbor_memb, n);
|
PRINTF("csma: Neighbor queue full\n");
|
||||||
}
|
}
|
||||||
PRINTF("csma: could not allocate packet, dropping packet\n");
|
PRINTF("csma: could not allocate packet, dropping packet\n");
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue