Browse Source

Merge pull request #5129 from cgundogan/pr/gnrc_rpl/minor_cleanup

gnrc_rpl: minor enhancements
pr/gpio
Oleg Hahm 7 years ago
parent
commit
d1ccfea80a
  1. 5
      sys/include/net/gnrc/rpl.h
  2. 6
      sys/net/gnrc/routing/rpl/gnrc_rpl.c
  3. 21
      sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c
  4. 26
      sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c
  5. 3
      sys/shell/commands/sc_gnrc_rpl.c

5
sys/include/net/gnrc/rpl.h

@ -385,6 +385,11 @@ static inline bool GNRC_RPL_COUNTER_GREATER_THAN(uint8_t A, uint8_t B)
*/
extern kernel_pid_t gnrc_rpl_pid;
/**
* @brief @see @ref GNRC_RPL_ALL_NODES_ADDR
*/
extern const ipv6_addr_t ipv6_addr_all_rpl_nodes;
/**
* @brief Initialization of the RPL thread.
*

6
sys/net/gnrc/routing/rpl/gnrc_rpl.c

@ -27,6 +27,7 @@
static char _stack[GNRC_RPL_STACK_SIZE];
kernel_pid_t gnrc_rpl_pid = KERNEL_PID_UNDEF;
const ipv6_addr_t ipv6_addr_all_rpl_nodes = GNRC_RPL_ALL_NODES_ADDR;
static uint32_t _lt_time = GNRC_RPL_LIFETIME_UPDATE_STEP * SEC_IN_USEC;
static xtimer_t _lt_timer;
static msg_t _lt_msg = { .type = GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE };
@ -68,10 +69,9 @@ kernel_pid_t gnrc_rpl_init(kernel_pid_t if_pid)
}
/* register all_RPL_nodes multicast address */
ipv6_addr_t all_RPL_nodes = GNRC_RPL_ALL_NODES_ADDR;
gnrc_ipv6_netif_add_addr(if_pid, &all_RPL_nodes, IPV6_ADDR_BIT_LEN, 0);
gnrc_ipv6_netif_add_addr(if_pid, &ipv6_addr_all_rpl_nodes, IPV6_ADDR_BIT_LEN, 0);
gnrc_rpl_send_DIS(NULL, &all_RPL_nodes);
gnrc_rpl_send_DIS(NULL, (ipv6_addr_t *) &ipv6_addr_all_rpl_nodes);
return gnrc_rpl_pid;
}

21
sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c

@ -51,8 +51,8 @@ void gnrc_rpl_send(gnrc_pktsnip_t *pkt, ipv6_addr_t *src, ipv6_addr_t *dst, ipv6
{
(void) dodag_id;
gnrc_pktsnip_t *hdr;
ipv6_addr_t all_RPL_nodes = GNRC_RPL_ALL_NODES_ADDR, ll_addr;
kernel_pid_t iface = gnrc_ipv6_netif_find_by_addr(NULL, &all_RPL_nodes);
ipv6_addr_t ll_addr;
kernel_pid_t iface = gnrc_ipv6_netif_find_by_addr(NULL, &ipv6_addr_all_rpl_nodes);
if (iface == KERNEL_PID_UNDEF) {
DEBUG("RPL: no suitable interface found for this destination address\n");
gnrc_pktbuf_release(pkt);
@ -71,11 +71,11 @@ void gnrc_rpl_send(gnrc_pktsnip_t *pkt, ipv6_addr_t *src, ipv6_addr_t *dst, ipv6
}
if (dst == NULL) {
dst = &all_RPL_nodes;
dst = (ipv6_addr_t *) &ipv6_addr_all_rpl_nodes;
}
hdr = gnrc_ipv6_hdr_build(pkt, (uint8_t *)src, sizeof(ipv6_addr_t), (uint8_t *)dst,
sizeof(ipv6_addr_t));
sizeof(ipv6_addr_t));
if (hdr == NULL) {
DEBUG("RPL: Send - no space left in packet buffer\n");
@ -151,7 +151,7 @@ void gnrc_rpl_send_DIO(gnrc_rpl_instance_t *inst, ipv6_addr_t *destination)
}
gnrc_rpl_dodag_t *dodag = &inst->dodag;
gnrc_pktsnip_t *pkt = NULL, *tmp = NULL;
gnrc_pktsnip_t *pkt = NULL, *tmp;
gnrc_rpl_dio_t *dio;
#ifndef GNRC_RPL_WITHOUT_PIO
@ -419,8 +419,7 @@ bool _parse_options(int msg_type, gnrc_rpl_instance_t *inst, gnrc_rpl_opt_t *opt
dodag->dio_opts |= GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO;
#endif
gnrc_rpl_opt_prefix_info_t *pi = (gnrc_rpl_opt_prefix_info_t *) opt;
ipv6_addr_t all_RPL_nodes = GNRC_RPL_ALL_NODES_ADDR;
if_id = gnrc_ipv6_netif_find_by_addr(NULL, &all_RPL_nodes);
if_id = gnrc_ipv6_netif_find_by_addr(NULL, &ipv6_addr_all_rpl_nodes);
/* check for the auto address-configuration flag */
if ((gnrc_netapi_get(if_id, NETOPT_IPV6_IID, 0, &iid, sizeof(eui64_t)) < 0) &&
!(pi->LAR_flags & GNRC_RPL_PREFIX_AUTO_ADDRESS_BIT)) {
@ -469,8 +468,8 @@ bool _parse_options(int msg_type, gnrc_rpl_instance_t *inst, gnrc_rpl_opt_t *opt
*included_opts |= ((uint32_t) 1) << GNRC_RPL_OPT_TRANSIT;
gnrc_rpl_opt_transit_t *transit = (gnrc_rpl_opt_transit_t *) opt;
if (first_target == NULL) {
DEBUG("RPL: Encountered a RPL TRANSIT DAO option without \
a preceding RPL TARGET DAO option\n");
DEBUG("RPL: Encountered a RPL TRANSIT DAO option without "
"a preceding RPL TARGET DAO option\n");
break;
}
@ -560,7 +559,7 @@ void gnrc_rpl_recv_DIO(gnrc_rpl_dio_t *dio, ipv6_addr_t *src, uint16_t len)
uint32_t included_opts = 0;
if(!_parse_options(GNRC_RPL_ICMPV6_CODE_DIO, inst, (gnrc_rpl_opt_t *)(dio + 1), len,
NULL, &included_opts)) {
src, &included_opts)) {
DEBUG("RPL: Error encountered during DIO option parsing - remove DODAG\n");
gnrc_rpl_instance_remove(inst);
return;
@ -670,7 +669,7 @@ void gnrc_rpl_recv_DIO(gnrc_rpl_dio_t *dio, ipv6_addr_t *src, uint16_t len)
dodag->prf = dio->g_mop_prf & GNRC_RPL_PRF_MASK;
uint32_t included_opts = 0;
if(!_parse_options(GNRC_RPL_ICMPV6_CODE_DIO, inst, (gnrc_rpl_opt_t *)(dio + 1), len,
NULL, &included_opts)) {
src, &included_opts)) {
DEBUG("RPL: Error encountered during DIO option parsing - remove DODAG\n");
gnrc_rpl_instance_remove(inst);
return;

26
sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c

@ -39,7 +39,6 @@ static void _rpl_trickle_send_dio(void *args)
{
gnrc_rpl_instance_t *inst = (gnrc_rpl_instance_t *) args;
gnrc_rpl_dodag_t *dodag = &inst->dodag;
ipv6_addr_t all_RPL_nodes = GNRC_RPL_ALL_NODES_ADDR;
/* a leaf node does not send DIOs periodically */
if (dodag->node_status == GNRC_RPL_LEAF_NODE) {
@ -47,7 +46,7 @@ static void _rpl_trickle_send_dio(void *args)
return;
}
gnrc_rpl_send_DIO(inst, &all_RPL_nodes);
gnrc_rpl_send_DIO(inst, (ipv6_addr_t *) &ipv6_addr_all_rpl_nodes);
DEBUG("trickle callback: Instance (%d) | DODAG: (%s)\n", inst->id,
ipv6_addr_to_str(addr_str,&dodag->dodag_id, sizeof(addr_str)));
}
@ -231,14 +230,13 @@ void gnrc_rpl_parent_update(gnrc_rpl_dodag_t *dodag, gnrc_rpl_parent_t *parent)
if (parent != NULL) {
parent->lifetime = (now / SEC_IN_USEC) + ((dodag->default_lifetime * dodag->lifetime_unit));
if (parent == dodag->parents) {
ipv6_addr_t all_RPL_nodes = GNRC_RPL_ALL_NODES_ADDR;
kernel_pid_t if_id;
if ((if_id = gnrc_ipv6_netif_find_by_addr(NULL, &all_RPL_nodes)) != KERNEL_PID_UNDEF) {
if ((if_id = gnrc_ipv6_netif_find_by_addr(NULL, &ipv6_addr_all_rpl_nodes)) != KERNEL_PID_UNDEF) {
fib_add_entry(&gnrc_ipv6_fib_table,
if_id,
(uint8_t *) ipv6_addr_unspecified.u8,
sizeof(ipv6_addr_t),
(FIB_FLAG_NET_PREFIX | 0x0),
FIB_FLAG_NET_PREFIX,
parent->addr.u8,
sizeof(ipv6_addr_t),
FIB_FLAG_RPL_ROUTE,
@ -269,13 +267,14 @@ static gnrc_rpl_parent_t *_gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *doda
gnrc_rpl_parent_t *old_best = dodag->parents;
gnrc_rpl_parent_t *new_best = old_best;
uint16_t old_rank = dodag->my_rank;
gnrc_rpl_parent_t *elt = NULL, *tmp = NULL;
gnrc_rpl_parent_t *elt, *tmp;
kernel_pid_t if_id;
if (dodag->parents == NULL) {
return NULL;
}
LL_FOREACH_SAFE(dodag->parents, elt, tmp) {
LL_FOREACH(dodag->parents, elt) {
new_best = dodag->instance->of->which_parent(new_best, elt);
}
@ -290,12 +289,8 @@ static gnrc_rpl_parent_t *_gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *doda
gnrc_rpl_send_DAO(dodag->instance, &old_best->addr, 0);
gnrc_rpl_delay_dao(dodag);
}
fib_remove_entry(&gnrc_ipv6_fib_table,
(uint8_t *) ipv6_addr_unspecified.u8,
sizeof(ipv6_addr_t));
ipv6_addr_t all_RPL_nodes = GNRC_RPL_ALL_NODES_ADDR;
kernel_pid_t if_id = gnrc_ipv6_netif_find_by_addr(NULL, &all_RPL_nodes);
if_id = gnrc_ipv6_netif_find_by_addr(NULL, &ipv6_addr_all_rpl_nodes);
if (if_id == KERNEL_PID_UNDEF) {
DEBUG("RPL: no interface found for the parent address\n");
@ -306,7 +301,7 @@ static gnrc_rpl_parent_t *_gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *doda
if_id,
(uint8_t *) ipv6_addr_unspecified.u8,
sizeof(ipv6_addr_t),
(FIB_FLAG_NET_PREFIX | 0x0),
FIB_FLAG_NET_PREFIX,
dodag->parents->addr.u8,
sizeof(ipv6_addr_t),
FIB_FLAG_RPL_ROUTE,
@ -318,7 +313,6 @@ static gnrc_rpl_parent_t *_gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *doda
trickle_reset_timer(&dodag->trickle);
}
elt = NULL; tmp = NULL;
LL_FOREACH_SAFE(dodag->parents, elt, tmp) {
if (DAGRANK(dodag->my_rank, dodag->instance->min_hop_rank_inc)
<= DAGRANK(elt->rank, dodag->instance->min_hop_rank_inc)) {
@ -355,8 +349,8 @@ gnrc_rpl_instance_t *gnrc_rpl_root_instance_init(uint8_t instance_id, ipv6_addr_
}
if ((netif_addr = gnrc_ipv6_netif_addr_get(configured_addr)) == NULL) {
DEBUG("RPL: no netif address found for %s\n", ipv6_addr_to_str(addr_str, configured_addr,
sizeof(addr_str)));
DEBUG("RPL: no netif address found for %s\n",
ipv6_addr_to_str(addr_str, configured_addr, sizeof(addr_str)));
return NULL;
}

3
sys/shell/commands/sc_gnrc_rpl.c

@ -142,8 +142,7 @@ int _gnrc_rpl_trickle_start(char *arg1)
int _gnrc_rpl_send_dis(void)
{
ipv6_addr_t all_RPL_nodes = GNRC_RPL_ALL_NODES_ADDR;
gnrc_rpl_send_DIS(NULL, &all_RPL_nodes);
gnrc_rpl_send_DIS(NULL, (ipv6_addr_t *) &ipv6_addr_all_rpl_nodes);
puts("success: send a DIS\n");
return 0;

Loading…
Cancel
Save