Merge pull request #1052 from simonduq/packetbuf-cleanup

Packetbuf cleanup
This commit is contained in:
George Oikonomou 2015-05-09 22:30:21 +01:00
commit bd5e35c968
18 changed files with 44 additions and 35 deletions

View file

@ -262,8 +262,8 @@ uip_over_mesh_send(void)
if(BUF->proto == UIP_PROTO_TCP) { if(BUF->proto == UIP_PROTO_TCP) {
#if NETSTACK_CONF_WITH_RIME #if NETSTACK_CONF_WITH_RIME
packetbuf_set_attr(PACKETBUF_ATTR_ERELIABLE, 1); packetbuf_set_attr(PACKETBUF_ATTR_ERELIABLE, 1);
#endif /* NETSTACK_CONF_WITH_RIME */
packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, 1); packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, 1);
#endif /* NETSTACK_CONF_WITH_RIME */
/* packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_PACKET_TYPE_STREAM);*/ /* packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_PACKET_TYPE_STREAM);*/
} }

View file

@ -1336,11 +1336,6 @@ send_packet(linkaddr_t *dest)
packetbuf_set_addr(PACKETBUF_ADDR_SENDER,(void*)&uip_lladdr); packetbuf_set_addr(PACKETBUF_ADDR_SENDER,(void*)&uip_lladdr);
#endif #endif
/* Force acknowledge from sender (test hardware autoacks) */
#if SICSLOWPAN_CONF_ACK_ALL
packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, 1);
#endif
/* Provide a callback function to receive the result of /* Provide a callback function to receive the result of
a packet transmission. */ a packet transmission. */
NETSTACK_LLSEC.send(&packet_sent, NULL); NETSTACK_LLSEC.send(&packet_sent, NULL);
@ -1388,6 +1383,7 @@ output(const uip_lladdr_t *localdest)
set_packet_attrs(); set_packet_attrs();
} }
#if PACKETBUF_WITH_PACKET_TYPE
#define TCP_FIN 0x01 #define TCP_FIN 0x01
#define TCP_ACK 0x10 #define TCP_ACK 0x10
#define TCP_CTL 0x3f #define TCP_CTL 0x3f
@ -1402,6 +1398,7 @@ output(const uip_lladdr_t *localdest)
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE, packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE,
PACKETBUF_ATTR_PACKET_TYPE_STREAM_END); PACKETBUF_ATTR_PACKET_TYPE_STREAM_END);
} }
#endif
/* /*
* The destination address will be tagged to each outbound * The destination address will be tagged to each outbound

View file

@ -499,7 +499,6 @@ send_packet(mac_callback_t mac_callback, void *mac_callback_ptr,
uint8_t got_strobe_ack = 0; uint8_t got_strobe_ack = 0;
int len; int len;
uint8_t is_broadcast = 0; uint8_t is_broadcast = 0;
uint8_t is_reliable = 0;
uint8_t is_known_receiver = 0; uint8_t is_known_receiver = 0;
uint8_t collisions; uint8_t collisions;
int transmit_len; int transmit_len;
@ -546,11 +545,6 @@ send_packet(mac_callback_t mac_callback, void *mac_callback_ptr,
packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[1]); packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[1]);
#endif /* NETSTACK_CONF_WITH_IPV6 */ #endif /* NETSTACK_CONF_WITH_IPV6 */
} }
is_reliable = packetbuf_attr(PACKETBUF_ATTR_RELIABLE)
#if NETSTACK_CONF_WITH_RIME
|| packetbuf_attr(PACKETBUF_ATTR_ERELIABLE)
#endif /* NETSTACK_CONF_WITH_RIME */
;
if(!packetbuf_attr(PACKETBUF_ATTR_IS_CREATED_AND_SECURED)) { if(!packetbuf_attr(PACKETBUF_ATTR_IS_CREATED_AND_SECURED)) {
packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1); packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1);

View file

@ -373,11 +373,13 @@ send_packet(mac_callback_t sent, void *ptr)
} }
metadata->sent = sent; metadata->sent = sent;
metadata->cptr = ptr; metadata->cptr = ptr;
#if PACKETBUF_WITH_PACKET_TYPE
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
#endif
{
list_add(n->queued_packet_list, q); list_add(n->queued_packet_list, q);
} }

View file

@ -453,8 +453,6 @@ send_packet(void)
packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[1]); packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[1]);
#endif /* NETSTACK_CONF_WITH_IPV6 */ #endif /* NETSTACK_CONF_WITH_IPV6 */
} }
/* is_reliable = packetbuf_attr(PACKETBUF_ATTR_RELIABLE) ||
packetbuf_attr(PACKETBUF_ATTR_ERELIABLE);*/
len = NETSTACK_FRAMER.create(); len = NETSTACK_FRAMER.create();
strobe_len = len + sizeof(struct cxmac_hdr); strobe_len = len + sizeof(struct cxmac_hdr);
if(len < 0 || strobe_len > (int)sizeof(strobe)) { if(len < 0 || strobe_len > (int)sizeof(strobe)) {
@ -475,7 +473,7 @@ send_packet(void)
return MAC_TX_ERR; return MAC_TX_ERR;
} }
#if WITH_STREAMING #if WITH_STREAMING && PACKETBUF_WITH_PACKET_TYPE
if(is_streaming == 1 && if(is_streaming == 1 &&
(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), (linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
&is_streaming_to) || &is_streaming_to) ||
@ -519,7 +517,7 @@ send_packet(void)
wait = ((rtimer_clock_t)(e->time - now)) % (DEFAULT_PERIOD); wait = ((rtimer_clock_t)(e->time - now)) % (DEFAULT_PERIOD);
expected = now + wait - 2 * DEFAULT_ON_TIME; expected = now + wait - 2 * DEFAULT_ON_TIME;
#if WITH_ACK_OPTIMIZATION #if WITH_ACK_OPTIMIZATION && PACKETBUF_WITH_PACKET_TYPE
/* Wait until the receiver is expected to be awake */ /* Wait until the receiver is expected to be awake */
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) != if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) !=
PACKETBUF_ATTR_PACKET_TYPE_ACK && PACKETBUF_ATTR_PACKET_TYPE_ACK &&
@ -624,12 +622,16 @@ send_packet(void)
/* If we have received the strobe ACK, and we are sending a packet /* If we have received the strobe ACK, and we are sending a packet
that will need an upper layer ACK (as signified by the that will need an upper layer ACK (as signified by the
PACKETBUF_ATTR_RELIABLE packet attribute), we keep the radio on. */ PACKETBUF_ATTR_RELIABLE packet attribute), we keep the radio on. */
if(got_strobe_ack && (packetbuf_attr(PACKETBUF_ATTR_RELIABLE) || if(got_strobe_ack && (
#if NETSTACK_CONF_WITH_RIME #if NETSTACK_CONF_WITH_RIME
packetbuf_attr(PACKETBUF_ATTR_RELIABLE) ||
packetbuf_attr(PACKETBUF_ATTR_ERELIABLE) || packetbuf_attr(PACKETBUF_ATTR_ERELIABLE) ||
#endif /* NETSTACK_CONF_WITH_RIME */ #endif /* NETSTACK_CONF_WITH_RIME */
#if PACKETBUF_WITH_PACKET_TYPE
packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) == packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
PACKETBUF_ATTR_PACKET_TYPE_STREAM)) { PACKETBUF_ATTR_PACKET_TYPE_STREAM ||
#endif
0)) {
on(); /* Wait for ACK packet */ on(); /* Wait for ACK packet */
waiting_for_packet = 1; waiting_for_packet = 1;
} else { } else {

View file

@ -242,8 +242,10 @@ parse(void)
} }
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr); packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
packetbuf_set_attr(PACKETBUF_ATTR_PENDING, frame.fcf.frame_pending); packetbuf_set_attr(PACKETBUF_ATTR_PENDING, frame.fcf.frame_pending);
/* packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, frame.fcf.ack_required);*/ packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, frame.seq);
#if NETSTACK_CONF_WITH_RIME
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, frame.seq); packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, frame.seq);
#endif
#if LLSEC802154_SECURITY_LEVEL #if LLSEC802154_SECURITY_LEVEL
if(frame.fcf.security_enabled) { if(frame.fcf.security_enabled) {

View file

@ -74,7 +74,7 @@ mac_sequence_is_duplicate(void)
for(i = 0; i < MAX_SEQNOS; ++i) { for(i = 0; i < MAX_SEQNOS; ++i) {
if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER), if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER),
&received_seqnos[i].sender)) { &received_seqnos[i].sender)) {
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_ID) == received_seqnos[i].seqno) { if(packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO) == received_seqnos[i].seqno) {
/* Duplicate packet. */ /* Duplicate packet. */
return 1; return 1;
} }
@ -102,7 +102,7 @@ mac_sequence_register_seqno(void)
for(j = i - 1; j > 0; --j) { for(j = i - 1; j > 0; --j) {
memcpy(&received_seqnos[j], &received_seqnos[j - 1], sizeof(struct seqno)); memcpy(&received_seqnos[j], &received_seqnos[j - 1], sizeof(struct seqno));
} }
received_seqnos[0].seqno = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID); received_seqnos[0].seqno = packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO);
linkaddr_copy(&received_seqnos[0].sender, linkaddr_copy(&received_seqnos[0].sender,
packetbuf_addr(PACKETBUF_ADDR_SENDER)); packetbuf_addr(PACKETBUF_ADDR_SENDER));
} }

View file

@ -294,7 +294,7 @@ packet_input(void)
if(duplicate) { if(duplicate) {
/* Drop the packet. */ /* Drop the packet. */
PRINTF("nullrdc: drop duplicate link layer packet %u\n", PRINTF("nullrdc: drop duplicate link layer packet %u\n",
packetbuf_attr(PACKETBUF_ATTR_PACKET_ID)); packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO));
} else { } else {
mac_sequence_register_seqno(); mac_sequence_register_seqno();
} }

View file

@ -106,7 +106,9 @@ send_packet(mac_callback_t sent, void *ptr)
params.fcf.frame_type = FRAME802154_DATAFRAME; params.fcf.frame_type = FRAME802154_DATAFRAME;
params.fcf.security_enabled = 0; params.fcf.security_enabled = 0;
params.fcf.frame_pending = 0; params.fcf.frame_pending = 0;
#if NETSTACK_CONF_WITH_RIME
params.fcf.ack_required = packetbuf_attr(PACKETBUF_ATTR_RELIABLE); params.fcf.ack_required = packetbuf_attr(PACKETBUF_ATTR_RELIABLE);
#endif
params.fcf.panid_compression = 0; params.fcf.panid_compression = 0;
/* Insert IEEE 802.15.4 (2003) version bit. */ /* Insert IEEE 802.15.4 (2003) version bit. */

View file

@ -74,6 +74,12 @@
#define PACKETBUF_HDR_SIZE 48 #define PACKETBUF_HDR_SIZE 48
#endif #endif
#ifdef PACKETBUF_CONF_WITH_PACKET_TYPE
#define PACKETBUF_WITH_PACKET_TYPE PACKETBUF_CONF_WITH_PACKET_TYPE
#else
#define PACKETBUF_WITH_PACKET_TYPE NETSTACK_CONF_WITH_RIME
#endif
/** /**
* \brief Clear and reset the packetbuf * \brief Clear and reset the packetbuf
* *
@ -309,10 +315,12 @@ enum {
PACKETBUF_ATTR_IS_CREATED_AND_SECURED, PACKETBUF_ATTR_IS_CREATED_AND_SECURED,
/* Scope 1 attributes: used between two neighbors only. */ /* Scope 1 attributes: used between two neighbors only. */
PACKETBUF_ATTR_RELIABLE, #if PACKETBUF_WITH_PACKET_TYPE
PACKETBUF_ATTR_PACKET_ID,
PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_PACKET_TYPE,
#endif
#if NETSTACK_CONF_WITH_RIME #if NETSTACK_CONF_WITH_RIME
PACKETBUF_ATTR_PACKET_ID,
PACKETBUF_ATTR_RELIABLE,
PACKETBUF_ATTR_REXMIT, PACKETBUF_ATTR_REXMIT,
PACKETBUF_ATTR_MAX_REXMIT, PACKETBUF_ATTR_MAX_REXMIT,
PACKETBUF_ATTR_NUM_REXMIT, PACKETBUF_ATTR_NUM_REXMIT,

View file

@ -402,14 +402,18 @@ sicslowmac_dataRequest(void)
frame_create_params_t params; frame_create_params_t params;
frame_result_t result; frame_result_t result;
#if NETSTACK_CONF_WITH_RIME
/* Save the msduHandle in a global variable. */ /* Save the msduHandle in a global variable. */
msduHandle = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID); msduHandle = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID);
#endif
/* Build the FCF. */ /* Build the FCF. */
params.fcf.frameType = DATAFRAME; params.fcf.frameType = DATAFRAME;
params.fcf.securityEnabled = false; params.fcf.securityEnabled = false;
params.fcf.framePending = false; params.fcf.framePending = false;
#if NETSTACK_CONF_WITH_RIME
params.fcf.ackRequired = packetbuf_attr(PACKETBUF_ATTR_RELIABLE); params.fcf.ackRequired = packetbuf_attr(PACKETBUF_ATTR_RELIABLE);
#endif
params.fcf.panIdCompression = false; params.fcf.panIdCompression = false;
/* Insert IEEE 802.15.4 (2003) version bit. */ /* Insert IEEE 802.15.4 (2003) version bit. */

View file

@ -1073,8 +1073,10 @@ rf230_transmit(unsigned short payload_len)
if (tx_result==RADIO_TX_OK) { if (tx_result==RADIO_TX_OK) {
RIMESTATS_ADD(lltx); RIMESTATS_ADD(lltx);
#if NETSTACK_CONF_WITH_RIME
if(packetbuf_attr(PACKETBUF_ATTR_RELIABLE)) if(packetbuf_attr(PACKETBUF_ATTR_RELIABLE))
RIMESTATS_ADD(ackrx); //ack was requested and received RIMESTATS_ADD(ackrx); //ack was requested and received
#endif
#if RF230_INSERTACK #if RF230_INSERTACK
/* Not PAN broadcast to FFFF, and ACK was requested and received */ /* Not PAN broadcast to FFFF, and ACK was requested and received */
if (!((buffer[5]==0xff) && (buffer[6]==0xff)) && (buffer[0]&(1<<6))) if (!((buffer[5]==0xff) && (buffer[6]==0xff)) && (buffer[0]&(1<<6)))

View file

@ -658,11 +658,13 @@ cc2420_transmit(unsigned short payload_len)
{ {
rtimer_clock_t sfd_timestamp; rtimer_clock_t sfd_timestamp;
sfd_timestamp = cc2420_sfd_start_time; sfd_timestamp = cc2420_sfd_start_time;
#if PACKETBUF_WITH_PACKET_TYPE
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) == if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP) { PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP) {
/* Write timestamp to last two bytes of packet in TXFIFO. */ /* Write timestamp to last two bytes of packet in TXFIFO. */
write_ram((uint8_t *) &sfd_timestamp, CC2420RAM_TXFIFO + payload_len - 1, 2, WRITE_RAM_IN_ORDER); write_ram((uint8_t *) &sfd_timestamp, CC2420RAM_TXFIFO + payload_len - 1, 2, WRITE_RAM_IN_ORDER);
} }
#endif
} }
if(!(get_status() & BV(CC2420_TX_ACTIVE))) { if(!(get_status() & BV(CC2420_TX_ACTIVE))) {

View file

@ -438,11 +438,13 @@ cc2520_transmit(unsigned short payload_len)
{ {
rtimer_clock_t sfd_timestamp; rtimer_clock_t sfd_timestamp;
sfd_timestamp = cc2520_sfd_start_time; sfd_timestamp = cc2520_sfd_start_time;
#if PACKETBUF_WITH_PACKET_TYPE
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) == if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP) { PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP) {
/* Write timestamp to last two bytes of packet in TXFIFO. */ /* Write timestamp to last two bytes of packet in TXFIFO. */
CC2520_WRITE_RAM(&sfd_timestamp, CC2520RAM_TXFIFO + payload_len - 1, 2); CC2520_WRITE_RAM(&sfd_timestamp, CC2520RAM_TXFIFO + payload_len - 1, 2);
} }
#endif
} }
if(!(status() & BV(CC2520_TX_ACTIVE))) { if(!(status() & BV(CC2520_TX_ACTIVE))) {

View file

@ -109,8 +109,7 @@ parse(void)
} }
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr); packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
packetbuf_set_attr(PACKETBUF_ATTR_PENDING, frame.fcf.frame_pending); packetbuf_set_attr(PACKETBUF_ATTR_PENDING, frame.fcf.frame_pending);
/* packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, frame.fcf.ack_required);*/ packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, frame.seq);
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, frame.seq);
PRINTF("15.4-IN: %2X", frame.fcf.frame_type); PRINTF("15.4-IN: %2X", frame.fcf.frame_type);
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));

View file

@ -191,8 +191,6 @@ typedef unsigned short uip_stats_t;
#define CHANNEL_802_15_4 26 #define CHANNEL_802_15_4 26
/* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */ /* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */
#define RF230_CONF_AUTOACK 1 #define RF230_CONF_AUTOACK 1
/* Request 802.15.4 ACK on all packets sent (else autoretry). This is primarily for testing. */
#define SICSLOWPAN_CONF_ACK_ALL 0
/* 1 + Number of auto retry attempts 0-15 (0 implies don't use extended TX_ARET_ON mode) */ /* 1 + Number of auto retry attempts 0-15 (0 implies don't use extended TX_ARET_ON mode) */
#define RF230_CONF_FRAME_RETRIES 2 #define RF230_CONF_FRAME_RETRIES 2
/* Number of csma retry attempts 0-5 in extended tx mode (7 does immediate tx with no csma) */ /* Number of csma retry attempts 0-5 in extended tx mode (7 does immediate tx with no csma) */

View file

@ -206,8 +206,6 @@ typedef unsigned short uip_stats_t;
#define RADIO_CONF_CALIBRATE_INTERVAL 256 #define RADIO_CONF_CALIBRATE_INTERVAL 256
/* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */ /* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */
#define RF230_CONF_AUTOACK 1 #define RF230_CONF_AUTOACK 1
/* Request 802.15.4 ACK on all packets sent (else autoretry). This is primarily for testing. */
#define SICSLOWPAN_CONF_ACK_ALL 0
/* Number of auto retry attempts+1, 1-16. Set zero to disable extended TX_ARET_ON mode with CCA) */ /* Number of auto retry attempts+1, 1-16. Set zero to disable extended TX_ARET_ON mode with CCA) */
#define RF230_CONF_FRAME_RETRIES 3 #define RF230_CONF_FRAME_RETRIES 3
/* Number of CSMA attempts 0-7. 802.15.4 2003 standard max is 5. */ /* Number of CSMA attempts 0-7. 802.15.4 2003 standard max is 5. */

View file

@ -284,9 +284,6 @@ typedef unsigned short uip_stats_t;
#define RADIO_CONF_CALIBRATE_INTERVAL 256 #define RADIO_CONF_CALIBRATE_INTERVAL 256
/* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */ /* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */
#define RF230_CONF_AUTOACK 1 #define RF230_CONF_AUTOACK 1
/* Request 802.15.4 ACK on all packets sent by sicslowpan.c (else autoretry) */
/* Broadcasts will be duplicated by the retry count, since no one will ACK them! */
#define SICSLOWPAN_CONF_ACK_ALL 0
/* 1 + Number of auto retry attempts 0-15 (0 implies don't use extended TX_ARET_ON mode with CCA) */ /* 1 + Number of auto retry attempts 0-15 (0 implies don't use extended TX_ARET_ON mode with CCA) */
#define RF230_CONF_FRAME_RETRIES 2 #define RF230_CONF_FRAME_RETRIES 2
/* CCA theshold energy -91 to -61 dBm (default -77). Set this smaller than the expected minimum rssi to avoid packet collisions */ /* CCA theshold energy -91 to -61 dBm (default -77). Set this smaller than the expected minimum rssi to avoid packet collisions */