From 7e54f7ea5f9d7473b5c15d1c7d0b0095d1b75c32 Mon Sep 17 00:00:00 2001 From: Stephan Arndt Date: Sun, 24 Mar 2013 20:03:18 +0100 Subject: [PATCH] improved handling of etx-messages --- sys/net/sixlowpan/rpl/etx_beaconing.c | 101 +++++++++++++------------- sys/net/sixlowpan/rpl/etx_beaconing.h | 3 +- sys/net/sixlowpan/rpl/rpl_structs.h | 1 + 3 files changed, 55 insertions(+), 50 deletions(-) diff --git a/sys/net/sixlowpan/rpl/etx_beaconing.c b/sys/net/sixlowpan/rpl/etx_beaconing.c index c05bdc5f64..398218c2d9 100644 --- a/sys/net/sixlowpan/rpl/etx_beaconing.c +++ b/sys/net/sixlowpan/rpl/etx_beaconing.c @@ -20,17 +20,24 @@ #include "rpl_structs.h" #include "rpl_dodag.h" +//For debugging purposes +#include +//#define ENABLE_DEBUG + +char etx_radio_buf[ETX_RADIO_STACKSIZE] = { 0 }; +char etx_update_buf[ETX_UPDT_STACKSIZE] = { 0 }; + int etx_beacon_pid = 0; int etx_radio_pid = 0; int etx_update_pid = 0; //Buffer -char etx_beacon_buf[ETX_BEACON_STACKSIZE] = { 0 }; -char etx_radio_buf[ETX_RADIO_STACKSIZE] = { 0 }; -char etx_update_buf[ETX_UPDT_STACKSIZE] = { 0 }; - uint8_t etx_send_buf[ETX_BUF_SIZE] = { 0 }; uint8_t etx_rec_buf[ETX_BUF_SIZE] = { 0 }; +char etx_beacon_buf[ETX_BEACON_STACKSIZE] = { 0 }; + +//Message queue for radio +msg_t msg_que[ETX_RCV_QUEUE_SIZE] = { 0 }; /* * The counter for the current 'round'. An ETX beacon is sent every ETX_INTERVAL @@ -39,9 +46,6 @@ uint8_t etx_rec_buf[ETX_BUF_SIZE] = { 0 }; */ static uint8_t rounds = 0; -//Message queue for radio -msg_t msg_que[ETX_RCV_QUEUE_SIZE] = { 0 }; - /* * This could (and should) be done differently, once the RPL implementation * deals with candidate neighbors in another way than just defining that every @@ -78,7 +82,7 @@ void show_candidates(void) { for (candidate = &candidates[0], end = candidates + RPL_MAX_CANDIDATE_NEIGHBORS; candidate < end; candidate++) { - printf("Candidates Addr:%d\n" + DEBUG("Candidates Addr:%d\n" "\t cur_etx:%f\n" "\t packets_rx:%d\n" "\t used:%d\n", candidate->addr.uint8[ETX_IPV6_LAST_BYTE], @@ -156,7 +160,7 @@ void etx_beacon(void) { etx_p->data[i * ETX_TUPLE_SIZE] = candidates[i].addr.uint8[ETX_IPV6_LAST_BYTE]; etx_p->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET] = - candidates[i].packets_rx; + candidates[i].packets_tx; p_length = p_length + ETX_PKT_HDR_LEN; } } @@ -168,7 +172,8 @@ void etx_beacon(void) { //vtimer_usleep(((ETX_INTERVAL - ETX_MAX_JITTER)*MS) + jittercorrection*MS + jitter*MS); /// TODO once vtimer works as intended, replace the hwtimer here with /// the vtimer. Right now vtimer bugs, so we have hwtimer here. - hwtimer_wait(HWTIMER_TICKS(((ETX_INTERVAL - ETX_MAX_JITTER)*MS) + jittercorrection*MS + jitter*MS)); + hwtimer_wait( + HWTIMER_TICKS(((ETX_INTERVAL - ETX_MAX_JITTER)*MS) + jittercorrection*MS + jitter*MS)); jittercorrection = (ETX_MAX_JITTER) - jitter; @@ -199,9 +204,10 @@ double etx_get_metric(ipv6_addr_t * address) { return 0; } -uint8_t etx_add_candidate(ipv6_addr_t * address, uint8_t * pkt_rcvd) { +rpl_candidate_neighbor_t * etx_add_candidate(ipv6_addr_t * address) { + puts("add candidate"); /* - * Pre-Condition: Add etx_add_candidate should only be called when the + * Pre-Condition: etx_add_candidate should only be called when the * candidate is not yet in the list. * Otherwise the candidate will be added a second time, * leading to unknown behavior. @@ -218,11 +224,11 @@ uint8_t etx_add_candidate(ipv6_addr_t * address, uint8_t * pkt_rcvd) { * This shouldn't really happen though, since we have enough * place in the array. * - * Returns if the candidate was added (1) or not (0). + * Returns the pointer to the candidate if it was added, or a NULL-pointer + * otherwise. */ rpl_candidate_neighbor_t * candidate; rpl_candidate_neighbor_t * end; - uint8_t added = 0; for (candidate = &candidates[0], end = candidates + RPL_MAX_CANDIDATE_NEIGHBORS; candidate < end; @@ -232,16 +238,15 @@ uint8_t etx_add_candidate(ipv6_addr_t * address, uint8_t * pkt_rcvd) { continue; } else { //We still have a free place add the new candidate - candidate->addr = * address; + candidate->addr = *address; candidate->cur_etx = 0; - candidate->packets_rx = *pkt_rcvd; + candidate->packets_tx = 0; + candidate->packets_rx = 0; candidate->used = 1; - - added = 1; - break; + return candidate; } } - return added; + return NULL ; } void etx_handle_beacon(ipv6_addr_t * candidate_address) { @@ -252,42 +257,40 @@ void etx_handle_beacon(ipv6_addr_t * candidate_address) { etx_probe_t * probe = get_etx_rec_buf(); - //Todo delete once everything works well - printf("ETX beacon package received with following values:\n" + DEBUG("ETX beacon package received with following values:\n" "\tPackage Option:%x\n" "\t Data Length:%u\n" "\tSource Address:%d\n\n", probe->code, probe->length, candidate_address->uint8[ETX_IPV6_LAST_BYTE]); - rpl_candidate_neighbor_t* candidate = NULL; - - for (uint8_t i = 0; i < probe->length / ETX_TUPLE_SIZE; i++) { - //todo delete once everything works well - printf("\tIPv6 short Addr:%u\n" - "\tPackets f. Addr:%u\n\n", probe->data[i * ETX_TUPLE_SIZE], - probe->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET]); - - // If i find my address in this probe, update the packet_rx value for - // this candidate, if he is in my candidate list. - if (probe->data[i * ETX_TUPLE_SIZE] - == own_address->uint8[ETX_IPV6_LAST_BYTE]) { - candidate = etx_find_candidate(candidate_address); - if (candidate != NULL ) { - candidate->packets_rx = probe->data[i * ETX_TUPLE_SIZE - + ETX_PKT_REC_OFFSET]; - } else { - //Candidate was not found in my list, maybe I should add it - uint8_t addresult = 0; - addresult = etx_add_candidate(candidate_address, - &(probe->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET])); - - if(addresult == 1){ - puts("[WARNING] Candidate could not get added"); - } - } + rpl_candidate_neighbor_t* candidate = etx_find_candidate(candidate_address); + if (candidate == NULL ) { + //Candidate was not found in my list, I should add it + candidate = etx_add_candidate(candidate_address); + if (candidate == NULL ) { + puts("[ERROR] Candidate could not get added"); + puts("Increase the constant RPL_MAX_CANDIDATE_NEIGHBORS"); + return; } } + //I have received 1 more packet from this candidate + candidate->packets_tx = candidate->packets_tx + 1; + + // If i find my address in this probe, update the packet_rx value for + // this candidate. + for (uint8_t i = 0; i < probe->length / ETX_TUPLE_SIZE; i++) { + DEBUG("\tIPv6 short Addr:%u\n" + "\tPackets f. Addr:%u\n\n", probe->data[i * ETX_TUPLE_SIZE], + probe->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET]); + + if (probe->data[i * ETX_TUPLE_SIZE] + == own_address->uint8[ETX_IPV6_LAST_BYTE]) { + + candidate->packets_rx = probe->data[i * ETX_TUPLE_SIZE + + ETX_PKT_REC_OFFSET]; + } + } } void etx_radio(void) { @@ -364,7 +367,7 @@ void etx_update(void) { candidate->cur_etx = candidate->packets_rx / (double) ETX_ROUNDS; candidate->packets_rx = 0; - printf( + DEBUG( "Updated ETX Metric to %f for candidate used was on %d", candidate->cur_etx, candidate->used); } diff --git a/sys/net/sixlowpan/rpl/etx_beaconing.h b/sys/net/sixlowpan/rpl/etx_beaconing.h index ed5fc1974d..8dcf3b30b4 100644 --- a/sys/net/sixlowpan/rpl/etx_beaconing.h +++ b/sys/net/sixlowpan/rpl/etx_beaconing.h @@ -11,9 +11,10 @@ #include "sys/net/sixlowpan/sixlowip.h" +//4908 is available stack size #define ETX_BEACON_STACKSIZE 2000 //TODO debug stacksize, set for production #define ETX_RADIO_STACKSIZE 2000 //TODO debug stacksize, set for production -#define ETX_UPDT_STACKSIZE 800 //TODO debug stacksize, set for production +#define ETX_UPDT_STACKSIZE 908 //TODO debug stacksize, set for production //[option|length|ipaddr.|packetcount] with up to 15 ipaddr|packetcount pairs diff --git a/sys/net/sixlowpan/rpl/rpl_structs.h b/sys/net/sixlowpan/rpl/rpl_structs.h index af1e4703f7..a71d600514 100644 --- a/sys/net/sixlowpan/rpl/rpl_structs.h +++ b/sys/net/sixlowpan/rpl/rpl_structs.h @@ -206,6 +206,7 @@ struct rpl_dodag_t; typedef struct rpl_candidate_neighbor_t { ipv6_addr_t addr; //The address of this node + uint8_t packets_tx; //The packets this node has transmitted TO ME uint8_t packets_rx; //The packets this node has received FROM ME double cur_etx; //The currently calculated ETX-value uint8_t used; //The indicator if this node is active or not