From d9c9f38c61c7075fd2d93a6c256e55d430e1511c Mon Sep 17 00:00:00 2001 From: Stephan Arndt Date: Fri, 29 Mar 2013 13:41:48 +0100 Subject: [PATCH] integrated ETX calculation with RPL, rpl messages seem to not get handled very often --- sys/net/sixlowpan/rpl/etx_beaconing.c | 54 +++++++++++---------------- sys/net/sixlowpan/rpl/etx_beaconing.h | 5 ++- sys/net/sixlowpan/rpl/of_mrhof.c | 6 ++- sys/net/sixlowpan/rpl/of_mrhof.h | 5 +++ sys/net/sixlowpan/rpl/rpl.c | 20 +++++++--- sys/net/sixlowpan/rpl/trickle.c | 8 ++-- sys/net/sixlowpan/sixlowmac.c | 2 +- 7 files changed, 52 insertions(+), 48 deletions(-) diff --git a/sys/net/sixlowpan/rpl/etx_beaconing.c b/sys/net/sixlowpan/rpl/etx_beaconing.c index 9773156546..f6af4653b9 100644 --- a/sys/net/sixlowpan/rpl/etx_beaconing.c +++ b/sys/net/sixlowpan/rpl/etx_beaconing.c @@ -81,7 +81,7 @@ static etx_neighbor_t candidates[ETX_MAX_CANDIDATE_NEIGHBORS] = { 0 }; * In this time, no packet may be handled, otherwise it could assume values * from the last round to count for this round. */ -//mutex_t etx_mutex; +mutex_t etx_mutex; //Transceiver command for sending ETX probes transceiver_command_t tcmd; @@ -120,7 +120,7 @@ void show_candidates(void) { } void etx_init_beaconing(ipv6_addr_t * address) { - //mutex_init(&etx_mutex); + mutex_init(&etx_mutex); own_address = address; //set code puts("ETX BEACON INIT"); @@ -160,21 +160,21 @@ void etx_beacon(void) { */ ieee_802154_long_t empty_addr = { 0 }; - //Build first etx packet - for (uint8_t i = 0; i < ETX_MAX_CANDIDATE_NEIGHBORS; i++) { - if (candidates[i].used != 0) { - packet->data[i * ETX_TUPLE_SIZE] = - candidates[i].addr.uint8[ETX_IPV6_LAST_BYTE]; - packet->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET] = - etx_count_packet_tx(&candidates[i]); - p_length = p_length + ETX_TUPLE_SIZE; - } - } - packet->length = p_length; - while (true) { thread_sleep(); - //mutex_lock(&etx_mutex); + mutex_lock(&etx_mutex); + //Build etx packet + p_length = 0; + for (uint8_t i = 0; i < ETX_BEST_CANDIDATES; i++) { + if (candidates[i].used != 0) { + packet->data[i * ETX_TUPLE_SIZE] = + candidates[i].addr.uint8[ETX_IPV6_LAST_BYTE]; + packet->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET] = + etx_count_packet_tx(&candidates[i]); + p_length = p_length + ETX_PKT_HDR_LEN; + } + } + packet->length = p_length; send_ieee802154_frame(&empty_addr, &etx_send_buf[0], ETX_DATA_MAXLEN+ETX_PKT_HDR_LEN, 1); DEBUG("sent beacon!\n"); @@ -187,19 +187,7 @@ void etx_beacon(void) { } cur_round = 0; } - //mutex_unlock(&etx_mutex,0); - //Build etx packet - p_length = 0; - for (uint8_t i = 0; i < ETX_MAX_CANDIDATE_NEIGHBORS; i++) { - if (candidates[i].used != 0) { - packet->data[i * ETX_TUPLE_SIZE] = - candidates[i].addr.uint8[ETX_IPV6_LAST_BYTE]; - packet->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET] = - etx_count_packet_tx(&candidates[i]); - p_length = p_length + ETX_PKT_HDR_LEN; - } - } - packet->length = p_length; + mutex_unlock(&etx_mutex,0); } } @@ -388,9 +376,9 @@ void etx_radio(void) { //up to 8 bits candidate_addr.uint8[ETX_IPV6_LAST_BYTE] = (uint8_t) p->src; //handle the beacon - //mutex_lock(&etx_mutex); + mutex_lock(&etx_mutex); etx_handle_beacon(&candidate_addr); - //mutex_unlock(&etx_mutex,0); + mutex_unlock(&etx_mutex,1); } p->processing--; @@ -459,7 +447,7 @@ static uint8_t etx_count_packet_tx(etx_neighbor_t * candidate) { for (uint8_t i = 0; i < ETX_WINDOW; i++) { if (i != cur_round) { pkt_count = pkt_count + candidate->packets_tx[i]; -#ifdef ENABLE_DEBUG //so ugly delete TODO +#ifdef ENABLE_DEBUG DEBUG("%d",candidate->packets_tx[i]); if (i < ETX_WINDOW - 1) { DEBUG(","); @@ -471,7 +459,7 @@ static uint8_t etx_count_packet_tx(etx_neighbor_t * candidate) { //Didn't receive a packet, zero the field and don't add candidate->packets_tx[i] = 0; #ifdef ENABLE_DEBUG - DEBUG("%d",candidate->packets_tx[i]); + DEBUG("%d!",candidate->packets_tx[i]); if (i < ETX_WINDOW - 1) { DEBUG(","); } @@ -481,7 +469,7 @@ static uint8_t etx_count_packet_tx(etx_neighbor_t * candidate) { pkt_count = pkt_count + 1; candidate->packets_tx[i] = 1; #ifdef ENABLE_DEBUG - DEBUG("%d",candidate->packets_tx[i]); + DEBUG("%d!",candidate->packets_tx[i]); if (i < ETX_WINDOW - 1) { DEBUG(","); } diff --git a/sys/net/sixlowpan/rpl/etx_beaconing.h b/sys/net/sixlowpan/rpl/etx_beaconing.h index 4baccb6aa5..611b45de66 100644 --- a/sys/net/sixlowpan/rpl/etx_beaconing.h +++ b/sys/net/sixlowpan/rpl/etx_beaconing.h @@ -12,7 +12,7 @@ #include "sys/net/sixlowpan/sixlowip.h" //For debugging purposes -//#define ENABLE_DEBUG +#define ENABLE_DEBUG #include #ifdef ENABLE_DEBUG @@ -52,6 +52,7 @@ */ #define ETX_INTERVAL (1000) #define ETX_WINDOW (10) //10 is the default value +#define ETX_BEST_CANDIDATES (15) //Sent only 15 candidates in a beaconing packet #define ETX_TUPLE_SIZE (2) //1 Byte for Addr, 1 Byte for packets rec. #define ETX_PKT_REC_OFFSET (ETX_TUPLE_SIZE - 1) //Offset in a tuple of (addr,pkt_rec), will always be the last byte #define ETX_IPV6_LAST_BYTE (15) //The last byte for an ipv6 address @@ -94,7 +95,7 @@ typedef struct __attribute__((packed)) etx_probe_t{ typedef struct etx_neighbor_t { ipv6_addr_t addr; //The address of this node uint8_t tx_cur_round; //The indicator for receiving a packet from this candidate this round - uint8_t packets_tx[10]; //The packets this node has transmitted TO ME + uint8_t packets_tx[ETX_WINDOW]; //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 diff --git a/sys/net/sixlowpan/rpl/of_mrhof.c b/sys/net/sixlowpan/rpl/of_mrhof.c index 1eeac0d8dc..66f04f7c6a 100644 --- a/sys/net/sixlowpan/rpl/of_mrhof.c +++ b/sys/net/sixlowpan/rpl/of_mrhof.c @@ -31,17 +31,19 @@ void reset(rpl_dodag_t *dodag) { } static uint16_t calc_path_cost(rpl_parent_t * parent) { + puts("calc_pathcost"); /* * Calculates the path cost through the parent, for now, only for ETX */ if (parent == NULL ) { // Shouldn't ever happen since this function is supposed to be always // run with a parent. If it does happen, we can assume a root called it. - printf("[WARNING] calc_path_cost called without parent!"); + puts("[WARNING] calc_path_cost called without parent!"); return DEFAULT_MIN_HOP_RANK_INCREASE; } double etx_value = etx_get_metric(&(parent->addr)); + printf("Metric for parent returned: %f", etx_value); if (etx_value != 0) { /* * (ETX_for_link_to_neighbor * 128) + Rank_of_that_neighbor @@ -74,6 +76,7 @@ static uint16_t calc_path_cost(rpl_parent_t * parent) { } static uint16_t calc_rank(rpl_parent_t * parent, uint16_t base_rank) { + puts("calc_rank"); /* * Return the rank for this node. * @@ -117,6 +120,7 @@ static uint16_t calc_rank(rpl_parent_t * parent, uint16_t base_rank) { } static rpl_parent_t * which_parent(rpl_parent_t * p1, rpl_parent_t * p2) { + puts("which_parent"); /* * Return the parent with the lowest path cost. * Before returning any of the two given parents, make sure that a switch is diff --git a/sys/net/sixlowpan/rpl/of_mrhof.h b/sys/net/sixlowpan/rpl/of_mrhof.h index b15f31e855..214353bc7b 100644 --- a/sys/net/sixlowpan/rpl/of_mrhof.h +++ b/sys/net/sixlowpan/rpl/of_mrhof.h @@ -1,3 +1,8 @@ +//For debugging purposes +#define ENABLE_DEBUG +#include + + #include "rpl_structs.h" /* diff --git a/sys/net/sixlowpan/rpl/rpl.c b/sys/net/sixlowpan/rpl/rpl.c index 9671a37ee6..566768fc86 100644 --- a/sys/net/sixlowpan/rpl/rpl.c +++ b/sys/net/sixlowpan/rpl/rpl.c @@ -158,7 +158,10 @@ uint8_t rpl_init(transceiver_type_t trans, uint16_t rpl_address){ //INSERT NEW OBJECTIVE FUNCTIONS HERE objective_functions[0] = rpl_get_of0(); + puts("OF0 added.");//todo del objective_functions[1] = rpl_get_of_mrhof(); + puts("OF_MRHOF added.");//todo del + sixlowpan_init(trans,rpl_address,0); //Wir benötigen einen Link Local prefix, um unsere entsprechende Addresse im Netz abzufragen @@ -206,7 +209,7 @@ void rpl_init_root(){ dodag->version = RPL_COUNTER_INIT; dodag->grounded = RPL_GROUNDED; dodag->node_status = (uint8_t) ROOT_NODE; - dodag->my_rank = ROOT_RANK; //TODO change this, according to spec. + dodag->my_rank = ROOT_RANK; dodag->joined = 1; dodag->my_preferred_parent = NULL; } @@ -222,7 +225,7 @@ void rpl_init_root(){ void send_DIO(ipv6_addr_t* destination){ - //puts("\nSEND DIO"); + puts("=================SEND DIO=================");//TODO comment out mutex_lock(&rpl_send_mutex); rpl_dodag_t * mydodag; icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); @@ -277,7 +280,7 @@ void send_DIO(ipv6_addr_t* destination){ } void send_DIS(ipv6_addr_t *destination){ - //puts("Send DIS"); + puts("=================Send DIS================="); mutex_lock(&rpl_send_mutex); icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); @@ -298,6 +301,7 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, if(i_am_root){ return; } + puts("=================Send DAO=================");//todo del mutex_lock(&rpl_send_mutex); rpl_dodag_t * my_dodag; my_dodag = rpl_get_my_dodag(); @@ -382,7 +386,7 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, } void send_DAO_ACK(ipv6_addr_t *destination){ - //puts("Send DAO_ACK to"); + puts("=================Send DAO_ACK to================="); ipv6_print_addr(destination); rpl_dodag_t * my_dodag; my_dodag = rpl_get_my_dodag(); @@ -410,7 +414,7 @@ void send_DAO_ACK(ipv6_addr_t *destination){ } void rpl_process(void){ - + puts("rpl process here!");//todo del msg_t m_recv; msg_init_queue(msg_queue, RPL_PKT_RECV_BUF_SIZE); @@ -425,24 +429,28 @@ void rpl_process(void){ memcpy(&rpl_buffer,ipv6_buf,ipv6_buf->length+IPV6_HDR_LEN); switch(*code) { case(ICMP_CODE_DIS):{ + puts("=================processing DIS!=================");//todo del recv_rpl_dis(); mutex_unlock(&rpl_recv_mutex, 0); //mutex_unlock(&rpl_send_mutex, 0); break; } case(ICMP_CODE_DIO):{ + puts("=================processing DIO!=================");//todo del recv_rpl_dio(); mutex_unlock(&rpl_recv_mutex, 0); //mutex_unlock(&rpl_send_mutex, 0); break; } case(ICMP_CODE_DAO):{ + puts("=================processing DAO!=================");//todo del recv_rpl_dao(); mutex_unlock(&rpl_recv_mutex, 0); //mutex_unlock(&rpl_send_mutex, 0); break; } case(ICMP_CODE_DAO_ACK):{ + puts("=================processing DAOACK!=================");//todo del recv_rpl_dao_ack(); mutex_unlock(&rpl_recv_mutex, 0); //mutex_unlock(&rpl_send_mutex, 0); @@ -451,7 +459,7 @@ void rpl_process(void){ default: mutex_unlock(&rpl_recv_mutex, 0); //mutex_unlock(&rpl_send_mutex, 0); - puts("default unlock"); + puts("=================default unlock================="); break; } } diff --git a/sys/net/sixlowpan/rpl/trickle.c b/sys/net/sixlowpan/rpl/trickle.c index 8a7d3d6b3c..5a70e0107e 100644 --- a/sys/net/sixlowpan/rpl/trickle.c +++ b/sys/net/sixlowpan/rpl/trickle.c @@ -51,19 +51,17 @@ void reset_trickletimer(void){ } void init_trickle(void){ - puts("trickle init!"); - //malloc thread stacks - timer_over_buf = malloc(TRICKLE_TIMER_STACKSIZE*sizeof(char)); + timer_over_buf = calloc(TRICKLE_TIMER_STACKSIZE,sizeof(char)); if(timer_over_buf == NULL){ puts("[ERROR] Could not allocate enough memory for timer_over_buf!"); return; } - interval_over_buf = malloc(TRICKLE_INTERVAL_STACKSIZE*sizeof(char)); + interval_over_buf = calloc(TRICKLE_INTERVAL_STACKSIZE,sizeof(char)); if(interval_over_buf == NULL){ puts("[ERROR] Could not allocate enough memory for interval_over_buf!"); return; } - dao_delay_over_buf = malloc(DAO_DELAY_STACKSIZE*sizeof(char)); + dao_delay_over_buf = calloc(DAO_DELAY_STACKSIZE,sizeof(char)); if(dao_delay_over_buf == NULL){ puts("[ERROR] Could not allocate enough memory for interval_over_buf!"); return; diff --git a/sys/net/sixlowpan/sixlowmac.c b/sys/net/sixlowpan/sixlowmac.c index e000f08695..d0ed5030d1 100644 --- a/sys/net/sixlowpan/sixlowmac.c +++ b/sys/net/sixlowpan/sixlowmac.c @@ -191,7 +191,7 @@ void send_ieee802154_frame(ieee_802154_long_t *addr, uint8_t *payload, p.data = buf; msg_send_receive(&mesg, &transceiver_rsp, transceiver_pid); - printf("%s, %u: %lu\n", __FILE__, __LINE__, transceiver_rsp.content.value); + //printf("%s, %u: %lu\n", __FILE__, __LINE__, transceiver_rsp.content.value); hwtimer_wait(5000); }