integrated ETX calculation with RPL, rpl messages seem to not get handled very often

This commit is contained in:
Stephan Arndt 2013-03-29 13:41:48 +01:00
parent 1fd9325d8c
commit d9c9f38c61
7 changed files with 52 additions and 48 deletions

View File

@ -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 * In this time, no packet may be handled, otherwise it could assume values
* from the last round to count for this round. * 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 for sending ETX probes
transceiver_command_t tcmd; transceiver_command_t tcmd;
@ -120,7 +120,7 @@ void show_candidates(void) {
} }
void etx_init_beaconing(ipv6_addr_t * address) { void etx_init_beaconing(ipv6_addr_t * address) {
//mutex_init(&etx_mutex); mutex_init(&etx_mutex);
own_address = address; own_address = address;
//set code //set code
puts("ETX BEACON INIT"); puts("ETX BEACON INIT");
@ -160,21 +160,21 @@ void etx_beacon(void) {
*/ */
ieee_802154_long_t empty_addr = { 0 }; ieee_802154_long_t empty_addr = { 0 };
//Build first etx packet while (true) {
for (uint8_t i = 0; i < ETX_MAX_CANDIDATE_NEIGHBORS; i++) { thread_sleep();
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) { if (candidates[i].used != 0) {
packet->data[i * ETX_TUPLE_SIZE] = packet->data[i * ETX_TUPLE_SIZE] =
candidates[i].addr.uint8[ETX_IPV6_LAST_BYTE]; candidates[i].addr.uint8[ETX_IPV6_LAST_BYTE];
packet->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET] = packet->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET] =
etx_count_packet_tx(&candidates[i]); etx_count_packet_tx(&candidates[i]);
p_length = p_length + ETX_TUPLE_SIZE; p_length = p_length + ETX_PKT_HDR_LEN;
} }
} }
packet->length = p_length; packet->length = p_length;
while (true) {
thread_sleep();
//mutex_lock(&etx_mutex);
send_ieee802154_frame(&empty_addr, &etx_send_buf[0], send_ieee802154_frame(&empty_addr, &etx_send_buf[0],
ETX_DATA_MAXLEN+ETX_PKT_HDR_LEN, 1); ETX_DATA_MAXLEN+ETX_PKT_HDR_LEN, 1);
DEBUG("sent beacon!\n"); DEBUG("sent beacon!\n");
@ -187,19 +187,7 @@ void etx_beacon(void) {
} }
cur_round = 0; cur_round = 0;
} }
//mutex_unlock(&etx_mutex,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;
} }
} }
@ -388,9 +376,9 @@ void etx_radio(void) {
//up to 8 bits //up to 8 bits
candidate_addr.uint8[ETX_IPV6_LAST_BYTE] = (uint8_t) p->src; candidate_addr.uint8[ETX_IPV6_LAST_BYTE] = (uint8_t) p->src;
//handle the beacon //handle the beacon
//mutex_lock(&etx_mutex); mutex_lock(&etx_mutex);
etx_handle_beacon(&candidate_addr); etx_handle_beacon(&candidate_addr);
//mutex_unlock(&etx_mutex,0); mutex_unlock(&etx_mutex,1);
} }
p->processing--; 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++) { for (uint8_t i = 0; i < ETX_WINDOW; i++) {
if (i != cur_round) { if (i != cur_round) {
pkt_count = pkt_count + candidate->packets_tx[i]; pkt_count = pkt_count + candidate->packets_tx[i];
#ifdef ENABLE_DEBUG //so ugly delete TODO #ifdef ENABLE_DEBUG
DEBUG("%d",candidate->packets_tx[i]); DEBUG("%d",candidate->packets_tx[i]);
if (i < ETX_WINDOW - 1) { if (i < ETX_WINDOW - 1) {
DEBUG(","); 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 //Didn't receive a packet, zero the field and don't add
candidate->packets_tx[i] = 0; candidate->packets_tx[i] = 0;
#ifdef ENABLE_DEBUG #ifdef ENABLE_DEBUG
DEBUG("%d",candidate->packets_tx[i]); DEBUG("%d!",candidate->packets_tx[i]);
if (i < ETX_WINDOW - 1) { if (i < ETX_WINDOW - 1) {
DEBUG(","); DEBUG(",");
} }
@ -481,7 +469,7 @@ static uint8_t etx_count_packet_tx(etx_neighbor_t * candidate) {
pkt_count = pkt_count + 1; pkt_count = pkt_count + 1;
candidate->packets_tx[i] = 1; candidate->packets_tx[i] = 1;
#ifdef ENABLE_DEBUG #ifdef ENABLE_DEBUG
DEBUG("%d",candidate->packets_tx[i]); DEBUG("%d!",candidate->packets_tx[i]);
if (i < ETX_WINDOW - 1) { if (i < ETX_WINDOW - 1) {
DEBUG(","); DEBUG(",");
} }

View File

@ -12,7 +12,7 @@
#include "sys/net/sixlowpan/sixlowip.h" #include "sys/net/sixlowpan/sixlowip.h"
//For debugging purposes //For debugging purposes
//#define ENABLE_DEBUG #define ENABLE_DEBUG
#include <debug.h> #include <debug.h>
#ifdef ENABLE_DEBUG #ifdef ENABLE_DEBUG
@ -52,6 +52,7 @@
*/ */
#define ETX_INTERVAL (1000) #define ETX_INTERVAL (1000)
#define ETX_WINDOW (10) //10 is the default value #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_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_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 #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 { typedef struct etx_neighbor_t {
ipv6_addr_t addr; //The address of this node 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 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 uint8_t packets_rx; //The packets this node has received FROM ME
double cur_etx; //The currently calculated ETX-value double cur_etx; //The currently calculated ETX-value
uint8_t used; //The indicator if this node is active or not uint8_t used; //The indicator if this node is active or not

View File

@ -31,17 +31,19 @@ void reset(rpl_dodag_t *dodag) {
} }
static uint16_t calc_path_cost(rpl_parent_t * parent) { 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 * Calculates the path cost through the parent, for now, only for ETX
*/ */
if (parent == NULL ) { if (parent == NULL ) {
// Shouldn't ever happen since this function is supposed to be always // 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. // 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; return DEFAULT_MIN_HOP_RANK_INCREASE;
} }
double etx_value = etx_get_metric(&(parent->addr)); double etx_value = etx_get_metric(&(parent->addr));
printf("Metric for parent returned: %f", etx_value);
if (etx_value != 0) { if (etx_value != 0) {
/* /*
* (ETX_for_link_to_neighbor * 128) + Rank_of_that_neighbor * (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) { static uint16_t calc_rank(rpl_parent_t * parent, uint16_t base_rank) {
puts("calc_rank");
/* /*
* Return the rank for this node. * 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) { 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. * Return the parent with the lowest path cost.
* Before returning any of the two given parents, make sure that a switch is * Before returning any of the two given parents, make sure that a switch is

View File

@ -1,3 +1,8 @@
//For debugging purposes
#define ENABLE_DEBUG
#include <debug.h>
#include "rpl_structs.h" #include "rpl_structs.h"
/* /*

View File

@ -158,7 +158,10 @@ uint8_t rpl_init(transceiver_type_t trans, uint16_t rpl_address){
//INSERT NEW OBJECTIVE FUNCTIONS HERE //INSERT NEW OBJECTIVE FUNCTIONS HERE
objective_functions[0] = rpl_get_of0(); objective_functions[0] = rpl_get_of0();
puts("OF0 added.");//todo del
objective_functions[1] = rpl_get_of_mrhof(); objective_functions[1] = rpl_get_of_mrhof();
puts("OF_MRHOF added.");//todo del
sixlowpan_init(trans,rpl_address,0); sixlowpan_init(trans,rpl_address,0);
//Wir benötigen einen Link Local prefix, um unsere entsprechende Addresse im Netz abzufragen //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->version = RPL_COUNTER_INIT;
dodag->grounded = RPL_GROUNDED; dodag->grounded = RPL_GROUNDED;
dodag->node_status = (uint8_t) ROOT_NODE; 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->joined = 1;
dodag->my_preferred_parent = NULL; dodag->my_preferred_parent = NULL;
} }
@ -222,7 +225,7 @@ void rpl_init_root(){
void send_DIO(ipv6_addr_t* destination){ void send_DIO(ipv6_addr_t* destination){
//puts("\nSEND DIO"); puts("=================SEND DIO=================");//TODO comment out
mutex_lock(&rpl_send_mutex); mutex_lock(&rpl_send_mutex);
rpl_dodag_t * mydodag; rpl_dodag_t * mydodag;
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); 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){ void send_DIS(ipv6_addr_t *destination){
//puts("Send DIS"); puts("=================Send DIS=================");
mutex_lock(&rpl_send_mutex); mutex_lock(&rpl_send_mutex);
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); 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){ if(i_am_root){
return; return;
} }
puts("=================Send DAO=================");//todo del
mutex_lock(&rpl_send_mutex); mutex_lock(&rpl_send_mutex);
rpl_dodag_t * my_dodag; rpl_dodag_t * my_dodag;
my_dodag = rpl_get_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){ void send_DAO_ACK(ipv6_addr_t *destination){
//puts("Send DAO_ACK to"); puts("=================Send DAO_ACK to=================");
ipv6_print_addr(destination); ipv6_print_addr(destination);
rpl_dodag_t * my_dodag; rpl_dodag_t * my_dodag;
my_dodag = rpl_get_my_dodag(); my_dodag = rpl_get_my_dodag();
@ -410,7 +414,7 @@ void send_DAO_ACK(ipv6_addr_t *destination){
} }
void rpl_process(void){ void rpl_process(void){
puts("rpl process here!");//todo del
msg_t m_recv; msg_t m_recv;
msg_init_queue(msg_queue, RPL_PKT_RECV_BUF_SIZE); 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); memcpy(&rpl_buffer,ipv6_buf,ipv6_buf->length+IPV6_HDR_LEN);
switch(*code) { switch(*code) {
case(ICMP_CODE_DIS):{ case(ICMP_CODE_DIS):{
puts("=================processing DIS!=================");//todo del
recv_rpl_dis(); recv_rpl_dis();
mutex_unlock(&rpl_recv_mutex, 0); mutex_unlock(&rpl_recv_mutex, 0);
//mutex_unlock(&rpl_send_mutex, 0); //mutex_unlock(&rpl_send_mutex, 0);
break; break;
} }
case(ICMP_CODE_DIO):{ case(ICMP_CODE_DIO):{
puts("=================processing DIO!=================");//todo del
recv_rpl_dio(); recv_rpl_dio();
mutex_unlock(&rpl_recv_mutex, 0); mutex_unlock(&rpl_recv_mutex, 0);
//mutex_unlock(&rpl_send_mutex, 0); //mutex_unlock(&rpl_send_mutex, 0);
break; break;
} }
case(ICMP_CODE_DAO):{ case(ICMP_CODE_DAO):{
puts("=================processing DAO!=================");//todo del
recv_rpl_dao(); recv_rpl_dao();
mutex_unlock(&rpl_recv_mutex, 0); mutex_unlock(&rpl_recv_mutex, 0);
//mutex_unlock(&rpl_send_mutex, 0); //mutex_unlock(&rpl_send_mutex, 0);
break; break;
} }
case(ICMP_CODE_DAO_ACK):{ case(ICMP_CODE_DAO_ACK):{
puts("=================processing DAOACK!=================");//todo del
recv_rpl_dao_ack(); recv_rpl_dao_ack();
mutex_unlock(&rpl_recv_mutex, 0); mutex_unlock(&rpl_recv_mutex, 0);
//mutex_unlock(&rpl_send_mutex, 0); //mutex_unlock(&rpl_send_mutex, 0);
@ -451,7 +459,7 @@ void rpl_process(void){
default: default:
mutex_unlock(&rpl_recv_mutex, 0); mutex_unlock(&rpl_recv_mutex, 0);
//mutex_unlock(&rpl_send_mutex, 0); //mutex_unlock(&rpl_send_mutex, 0);
puts("default unlock"); puts("=================default unlock=================");
break; break;
} }
} }

View File

@ -51,19 +51,17 @@ void reset_trickletimer(void){
} }
void init_trickle(void){ void init_trickle(void){
puts("trickle init!"); timer_over_buf = calloc(TRICKLE_TIMER_STACKSIZE,sizeof(char));
//malloc thread stacks
timer_over_buf = malloc(TRICKLE_TIMER_STACKSIZE*sizeof(char));
if(timer_over_buf == NULL){ if(timer_over_buf == NULL){
puts("[ERROR] Could not allocate enough memory for timer_over_buf!"); puts("[ERROR] Could not allocate enough memory for timer_over_buf!");
return; return;
} }
interval_over_buf = malloc(TRICKLE_INTERVAL_STACKSIZE*sizeof(char)); interval_over_buf = calloc(TRICKLE_INTERVAL_STACKSIZE,sizeof(char));
if(interval_over_buf == NULL){ if(interval_over_buf == NULL){
puts("[ERROR] Could not allocate enough memory for interval_over_buf!"); puts("[ERROR] Could not allocate enough memory for interval_over_buf!");
return; 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){ if(dao_delay_over_buf == NULL){
puts("[ERROR] Could not allocate enough memory for interval_over_buf!"); puts("[ERROR] Could not allocate enough memory for interval_over_buf!");
return; return;

View File

@ -191,7 +191,7 @@ void send_ieee802154_frame(ieee_802154_long_t *addr, uint8_t *payload,
p.data = buf; p.data = buf;
msg_send_receive(&mesg, &transceiver_rsp, transceiver_pid); 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); hwtimer_wait(5000);
} }