From 78b7a7a9a8634a78d5cd60dcfcb8f54c253dfd10 Mon Sep 17 00:00:00 2001 From: vrobic Date: Tue, 14 Feb 2017 09:34:13 +0100 Subject: [PATCH] affectation rang selon rssi et lqi --- RIOT/examples/dynamic_app/Makefile | 2 +- RIOT/sys/include/net/gnrc/rpl/structs.h | 29 +++++++++++++++++++++++++---- RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl.c | 20 ++++++++++++++++---- RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c | 20 ++++++++++++++++---- RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c | 6 +++++- RIOT/sys/net/gnrc/routing/rpl/of0.c | 20 +++++++++++++++++--- 6 files changed, 80 insertions(+), 17 deletions(-) diff --git a/RIOT/examples/dynamic_app/Makefile b/RIOT/examples/dynamic_app/Makefile index eb114a0..2a61adb 100755 --- a/RIOT/examples/dynamic_app/Makefile +++ b/RIOT/examples/dynamic_app/Makefile @@ -1,5 +1,5 @@ # name of your application -APPLICATION = real_time_app +APPLICATION = dynamic_app # If no BOARD is found in the environment, use this default: BOARD ?= native diff --git a/RIOT/sys/include/net/gnrc/rpl/structs.h b/RIOT/sys/include/net/gnrc/rpl/structs.h index 56a6946..2760236 100755 --- a/RIOT/sys/include/net/gnrc/rpl/structs.h +++ b/RIOT/sys/include/net/gnrc/rpl/structs.h @@ -74,7 +74,14 @@ extern "C" { * RFC6550, section 6.7.1, RPL Control Message Option Generic Format * */ - +/*******************************************************************/ +//ADDED BY PFE7 2017 +typedef struct __attribute__((packed)) { + uint8_t rssi; /*Received Signal Strength Indication*/ + uint8_t lqi; /*Link Quality Indicator*/ +} rpl_metric_container; +//\ADDED BY PFE7 2017 +/*******************************************************************/ typedef struct __attribute__((packed)) { @@ -97,6 +104,11 @@ typedef struct __attribute__((packed)) { uint8_t flags; /**< unused */ uint8_t reserved; /**< reserved */ ipv6_addr_t dodag_id; /**< id of the dodag */ + /*******************************************************************/ + //ADDED BY PFE7 2017 + rpl_metric_container mc; + //\ADDED BY PFE7 2017 + /*******************************************************************/ } gnrc_rpl_dio_t; /** @@ -218,8 +230,13 @@ struct gnrc_rpl_parent { uint16_t rank; /**< rank of the parent */ gnrc_rpl_dodag_t *dodag; /**< DODAG the parent belongs to */ uint32_t lifetime; /**< lifetime of this parent in seconds */ - double link_metric; /**< metric of the link */ - uint8_t link_metric_type; /**< type of the metric */ + /*******************************************************************/ + //ADDED BY PFE7 2017 + rpl_metric_container mc; + //double link_metric; /**< metric of the link */ + //uint8_t link_metric_type; /**< type of the metric */ + //\ADDED BY PFE7 2017 + /*******************************************************************/ }; /** @@ -278,7 +295,11 @@ struct gnrc_rpl_instance { uint16_t max_rank_inc; /**< max increase in the rank */ int8_t cleanup; /**< cleanup time in seconds */ }; - +/*******************************************************************/ +//ADDED BY PFE7 2017 +static uint8_t dodag_insert; +//\ADDED BY PFE7 2017 +/*******************************************************************/ #ifdef __cplusplus } #endif diff --git a/RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl.c b/RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl.c index 0868299..3b52d81 100755 --- a/RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl.c +++ b/RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl.c @@ -25,7 +25,13 @@ #include "net/gnrc/rpl/p2p.h" #include "net/gnrc/rpl/p2p_dodag.h" #endif +/*******************************************************************/ +//ADDED BY PFE7 2017 +//#include "../../boards/stm32f4discovery/include/board.h" +//#include "../../boards/stm32f4discovery/include/periph_conf.h" +//\ADDED BY PFE7 2017 +/*******************************************************************/ #define ENABLE_DEBUG (0) #include "debug.h" @@ -103,7 +109,7 @@ gnrc_rpl_instance_t *gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_ } dodag = &inst->dodag; - + dodag->dtsn = 1; dodag->prf = 0; dodag->dio_interval_doubl = GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS; @@ -119,7 +125,6 @@ gnrc_rpl_instance_t *gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_ #ifndef GNRC_RPL_WITHOUT_PIO dodag->dio_opts |= GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO; #endif - trickle_start(gnrc_rpl_pid, &dodag->trickle, GNRC_RPL_MSG_TYPE_TRICKLE_INTERVAL, GNRC_RPL_MSG_TYPE_TRICKLE_CALLBACK, (1 << dodag->dio_min), dodag->dio_interval_doubl, dodag->dio_redun); @@ -133,12 +138,11 @@ static void _receive(gnrc_pktsnip_t *icmpv6) ipv6_hdr_t *ipv6_hdr; icmpv6_hdr_t *icmpv6_hdr; kernel_pid_t iface = KERNEL_PID_UNDEF; - + assert(icmpv6 != NULL); ipv6 = gnrc_pktsnip_search_type(icmpv6, GNRC_NETTYPE_IPV6); netif = gnrc_pktsnip_search_type(icmpv6, GNRC_NETTYPE_NETIF); - assert(ipv6 != NULL); if (netif) { @@ -156,6 +160,14 @@ static void _receive(gnrc_pktsnip_t *icmpv6) break; case GNRC_RPL_ICMPV6_CODE_DIO: DEBUG("RPL: DIO received\n"); + /*******************************************************************/ + //ADDED BY PFE7 2017 + gnrc_netif_hdr_t* header=(gnrc_netif_hdr_t*)netif->data; + gnrc_rpl_dio_t * dio_msg=(gnrc_rpl_dio_t *)(icmpv6_hdr + 1); + dio_msg->mc.rssi=header->rssi; + dio_msg->mc.lqi=header->lqi; + //\ADDED BY PFE7 2017 + /*******************************************************************/ gnrc_rpl_recv_DIO((gnrc_rpl_dio_t *)(icmpv6_hdr + 1), iface, &ipv6_hdr->src, &ipv6_hdr->dst, byteorder_ntohs(ipv6_hdr->len)); break; diff --git a/RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c b/RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c index 4f012eb..129f677 100755 --- a/RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c +++ b/RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c @@ -477,7 +477,7 @@ void gnrc_rpl_recv_DIO(gnrc_rpl_dio_t *dio, kernel_pid_t iface, ipv6_addr_t *src /* new instance and DODAG */ if (byteorder_ntohs(dio->rank) == GNRC_RPL_INFINITE_RANK) { - DEBUG("RPL: ignore INFINITE_RANK DIO when we are not yet part of this DODAG\n"); + puts("RPL: ignore INFINITE_RANK DIO when we are not yet part of this DODAG\n"); gnrc_rpl_instance_remove(inst); return; } @@ -500,7 +500,7 @@ void gnrc_rpl_recv_DIO(gnrc_rpl_dio_t *dio, kernel_pid_t iface, ipv6_addr_t *src gnrc_rpl_parent_t *parent = NULL; if (!gnrc_rpl_parent_add_by_addr(dodag, src, &parent) && (parent == NULL)) { - DEBUG("RPL: Could not allocate new parent.\n"); + puts("RPL: Could not allocate new parent.\n"); gnrc_rpl_instance_remove(inst); return; } @@ -508,7 +508,14 @@ void gnrc_rpl_recv_DIO(gnrc_rpl_dio_t *dio, kernel_pid_t iface, ipv6_addr_t *src dodag->version = dio->version_number; dodag->grounded = dio->g_mop_prf >> GNRC_RPL_GROUNDED_SHIFT; dodag->prf = dio->g_mop_prf & GNRC_RPL_PRF_MASK; - + /*******************************************************************/ + //ADDED BY PFE7 2017 + parent->mc.rssi=dio->mc.rssi; + parent->mc.lqi=dio->mc.lqi; + //\ADDED BY PFE7 2017 + /*******************************************************************/ + + parent->rank = byteorder_ntohs(dio->rank); uint32_t included_opts = 0; @@ -625,7 +632,12 @@ void gnrc_rpl_recv_DIO(gnrc_rpl_dio_t *dio, kernel_pid_t iface, ipv6_addr_t *src /* gnrc_rpl_parent_add_by_addr should have set this already */ assert(parent != NULL); - + /*******************************************************************/ + //ADDED BY PFE7 2017 + parent->mc.rssi=dio->mc.rssi; + parent->mc.lqi=dio->mc.lqi; + //\ADDED BY PFE7 2017 + /*******************************************************************/ parent->rank = byteorder_ntohs(dio->rank); gnrc_rpl_parent_update(dodag, parent); diff --git a/RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c b/RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c index 8d0522f..38bc1d8 100755 --- a/RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c +++ b/RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c @@ -288,6 +288,7 @@ void gnrc_rpl_parent_update(gnrc_rpl_dodag_t *dodag, gnrc_rpl_parent_t *parent) } if (_gnrc_rpl_find_preferred_parent(dodag) == NULL) { + puts("local repair"); gnrc_rpl_local_repair(dodag); } } @@ -308,6 +309,7 @@ static gnrc_rpl_parent_t *_gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *doda gnrc_rpl_parent_t *elt, *tmp; if (dodag->parents == NULL) { + puts("NULL 1"); return NULL; } @@ -316,6 +318,7 @@ static gnrc_rpl_parent_t *_gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *doda } if (new_best->rank == GNRC_RPL_INFINITE_RANK) { + puts("NULL 2"); return NULL; } @@ -346,8 +349,9 @@ static gnrc_rpl_parent_t *_gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *doda #endif } - + printf("AVmy_rank : %d\n",dodag->my_rank); dodag->my_rank = dodag->instance->of->calc_rank(dodag->parents, 0); + printf("my_rank : %d\n",dodag->my_rank); if (dodag->my_rank != old_rank) { trickle_reset_timer(&dodag->trickle); } diff --git a/RIOT/sys/net/gnrc/routing/rpl/of0.c b/RIOT/sys/net/gnrc/routing/rpl/of0.c index 3bd5d5f..cf79fec 100755 --- a/RIOT/sys/net/gnrc/routing/rpl/of0.c +++ b/RIOT/sys/net/gnrc/routing/rpl/of0.c @@ -54,25 +54,39 @@ uint16_t calc_rank(gnrc_rpl_parent_t *parent, uint16_t base_rank) { if (base_rank == 0) { if (parent == NULL) { + puts("pas parent"); return GNRC_RPL_INFINITE_RANK; } - + puts("if1"); base_rank = parent->rank; + } uint16_t add; if (parent != NULL) { - add = parent->dodag->instance->min_hop_rank_inc; + puts("if2"); + //add = parent->dodag->instance->min_hop_rank_inc; + /*******************************************************************/ + //ADDED BY PFE7 2017 + + add = 256 - (parent->mc.rssi + parent->mc.lqi)/10; + parent->dodag->instance->min_hop_rank_inc=add; + printf("add= %u\n",add); + + //\ADDED BY PFE7 2017 + /*******************************************************************/ } else { + puts("else1"); add = GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE; + } if ((base_rank + add) < base_rank) { + puts("b_r + add < br"); return GNRC_RPL_INFINITE_RANK; } - return base_rank + add; } -- libgit2 0.21.2