Updated the RPL code to better match the Contiki code style

This commit is contained in:
Adam Dunkels 2012-11-25 11:47:02 +01:00
parent 0cb4bf4808
commit db7cb567f5
4 changed files with 70 additions and 69 deletions

View file

@ -57,18 +57,18 @@
#include "net/neighbor-info.h"
/************************************************************************/
/*---------------------------------------------------------------------------*/
extern rpl_of_t RPL_OF;
static rpl_of_t * const objective_functions[] = {&RPL_OF};
/************************************************************************/
/*---------------------------------------------------------------------------*/
#ifndef RPL_CONF_MAX_PARENTS_PER_DAG
#define RPL_MAX_PARENTS_PER_DAG 8
#else
#define RPL_MAX_PARENTS_PER_DAG RPL_CONF_MAX_PARENTS_PER_DAG
#endif /* !RPL_CONF_MAX_PARENTS_PER_DAG */
/************************************************************************/
/*---------------------------------------------------------------------------*/
/* RPL definitions. */
#ifndef RPL_CONF_GROUNDED
@ -77,17 +77,17 @@ static rpl_of_t * const objective_functions[] = {&RPL_OF};
#define RPL_GROUNDED RPL_CONF_GROUNDED
#endif /* !RPL_CONF_GROUNDED */
/************************************************************************/
/*---------------------------------------------------------------------------*/
/* Allocate parents from the same static MEMB chunk to reduce memory waste. */
MEMB(parent_memb, struct rpl_parent,
RPL_MAX_PARENTS_PER_DAG * RPL_MAX_INSTANCES * RPL_MAX_DAG_PER_INSTANCE);
/************************************************************************/
/*---------------------------------------------------------------------------*/
/* Allocate instance table. */
rpl_instance_t instance_table[RPL_MAX_INSTANCES];
rpl_instance_t *default_instance;
/************************************************************************/
/*---------------------------------------------------------------------------*/
/* Greater-than function for the lollipop counter. */
/************************************************************************/
/*---------------------------------------------------------------------------*/
static int
lollipop_greater_than(int a, int b)
{
@ -101,7 +101,7 @@ lollipop_greater_than(int a, int b)
(a < b && (b - a) > (RPL_LOLLIPOP_CIRCULAR_REGION + 1-
RPL_LOLLIPOP_SEQUENCE_WINDOWS));
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
/* Remove DAG parents with a rank that is at least the same as minimum_rank. */
static void
remove_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank)
@ -118,7 +118,7 @@ remove_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank)
}
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static void
nullify_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank)
{
@ -134,7 +134,7 @@ nullify_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank)
}
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static void
remove_worst_parent(rpl_dag_t *dag, rpl_rank_t min_worst_rank)
{
@ -155,7 +155,7 @@ remove_worst_parent(rpl_dag_t *dag, rpl_rank_t min_worst_rank)
rpl_remove_parent(dag, worst);
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static int
should_send_dao(rpl_instance_t *instance, rpl_dio_t *dio, rpl_parent_t *p)
{
@ -167,7 +167,7 @@ should_send_dao(rpl_instance_t *instance, rpl_dio_t *dio, rpl_parent_t *p)
return p == instance->current_dag->preferred_parent &&
(lollipop_greater_than(dio->dtsn, p->dtsn));
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static int
acceptable_rank(rpl_dag_t *dag, rpl_rank_t rank)
{
@ -175,7 +175,7 @@ acceptable_rank(rpl_dag_t *dag, rpl_rank_t rank)
((dag->instance->max_rankinc == 0) ||
DAG_RANK(rank, dag->instance) <= DAG_RANK(dag->min_rank + dag->instance->max_rankinc, dag->instance));
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static rpl_dag_t *
get_dag(uint8_t instance_id, uip_ipaddr_t *dag_id)
{
@ -197,7 +197,7 @@ get_dag(uint8_t instance_id, uip_ipaddr_t *dag_id)
return NULL;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
rpl_dag_t *
rpl_set_root(uint8_t instance_id, uip_ipaddr_t *dag_id)
{
@ -270,7 +270,7 @@ rpl_set_root(uint8_t instance_id, uip_ipaddr_t *dag_id)
return dag;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
int
rpl_repair_root(uint8_t instance_id)
{
@ -287,7 +287,7 @@ rpl_repair_root(uint8_t instance_id)
rpl_reset_dio_timer(instance);
return 1;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static void
set_ip_from_prefix(uip_ipaddr_t *ipaddr, rpl_prefix_t *prefix)
{
@ -295,7 +295,7 @@ set_ip_from_prefix(uip_ipaddr_t *ipaddr, rpl_prefix_t *prefix)
memcpy(ipaddr, &prefix->prefix, (prefix->length + 7) / 8);
uip_ds6_set_addr_iid(ipaddr, &uip_lladdr);
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static void
check_prefix(rpl_prefix_t *last_prefix, rpl_prefix_t *new_prefix)
{
@ -331,7 +331,7 @@ check_prefix(rpl_prefix_t *last_prefix, rpl_prefix_t *new_prefix)
}
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
int
rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, unsigned len)
{
@ -349,7 +349,7 @@ rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, unsigned len)
check_prefix(NULL, &dag->prefix_info);
return 1;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
int
rpl_set_default_route(rpl_instance_t *instance, uip_ipaddr_t *from)
{
@ -376,13 +376,14 @@ rpl_set_default_route(rpl_instance_t *instance, uip_ipaddr_t *from)
}
return 1;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
rpl_instance_t *
rpl_alloc_instance(uint8_t instance_id)
{
rpl_instance_t *instance, *end;
for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; instance < end; ++instance) {
for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES;
instance < end; ++instance) {
if(instance->used == 0) {
memset(instance, 0, sizeof(*instance));
instance->instance_id = instance_id;
@ -393,7 +394,7 @@ rpl_alloc_instance(uint8_t instance_id)
}
return NULL;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
rpl_dag_t *
rpl_alloc_dag(uint8_t instance_id, uip_ipaddr_t *dag_id)
{
@ -425,13 +426,13 @@ rpl_alloc_dag(uint8_t instance_id, uip_ipaddr_t *dag_id)
rpl_free_instance(instance);
return NULL;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_set_default_instance(rpl_instance_t *instance)
{
default_instance = instance;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_free_instance(rpl_instance_t *instance)
{
@ -458,7 +459,7 @@ rpl_free_instance(rpl_instance_t *instance)
instance->used = 0;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_free_dag(rpl_dag_t *dag)
{
@ -480,7 +481,7 @@ rpl_free_dag(rpl_dag_t *dag)
}
dag->used = 0;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
rpl_parent_t *
rpl_add_parent(rpl_dag_t *dag, rpl_dio_t *dio, uip_ipaddr_t *addr)
{
@ -504,7 +505,7 @@ rpl_add_parent(rpl_dag_t *dag, rpl_dio_t *dio, uip_ipaddr_t *addr)
list_add(dag->parents, p);
return p;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
rpl_parent_t *
rpl_find_parent(rpl_dag_t *dag, uip_ipaddr_t *addr)
{
@ -518,7 +519,7 @@ rpl_find_parent(rpl_dag_t *dag, uip_ipaddr_t *addr)
return NULL;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static rpl_dag_t *
find_parent_dag(rpl_instance_t *instance, uip_ipaddr_t *addr)
{
@ -536,7 +537,7 @@ find_parent_dag(rpl_instance_t *instance, uip_ipaddr_t *addr)
}
return NULL;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
rpl_parent_t *
rpl_find_parent_any_dag(rpl_instance_t *instance, uip_ipaddr_t *addr)
{
@ -554,7 +555,7 @@ rpl_find_parent_any_dag(rpl_instance_t *instance, uip_ipaddr_t *addr)
}
return NULL;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
rpl_dag_t *
rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p)
{
@ -645,7 +646,7 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p)
}
return best_dag;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
rpl_parent_t *
rpl_select_parent(rpl_dag_t *dag)
{
@ -668,7 +669,7 @@ rpl_select_parent(rpl_dag_t *dag)
return best;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_remove_parent(rpl_dag_t *dag, rpl_parent_t *parent)
{
@ -681,7 +682,7 @@ rpl_remove_parent(rpl_dag_t *dag, rpl_parent_t *parent)
list_remove(dag->parents, parent);
memb_free(&parent_memb, parent);
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_nullify_parent(rpl_dag_t *dag, rpl_parent_t *parent)
{
@ -706,7 +707,7 @@ rpl_nullify_parent(rpl_dag_t *dag, rpl_parent_t *parent)
PRINT6ADDR(&parent->addr);
PRINTF("\n");
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_move_parent(rpl_dag_t *dag_src, rpl_dag_t *dag_dst, rpl_parent_t *parent)
{
@ -735,7 +736,7 @@ rpl_move_parent(rpl_dag_t *dag_src, rpl_dag_t *dag_dst, rpl_parent_t *parent)
parent->dag = dag_dst;
list_add(dag_dst->parents, parent);
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
rpl_dag_t *
rpl_get_any_dag(void)
{
@ -748,7 +749,7 @@ rpl_get_any_dag(void)
}
return NULL;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
rpl_instance_t *
rpl_get_instance(uint8_t instance_id)
{
@ -761,7 +762,7 @@ rpl_get_instance(uint8_t instance_id)
}
return NULL;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
rpl_of_t *
rpl_find_of(rpl_ocp_t ocp)
{
@ -777,7 +778,7 @@ rpl_find_of(rpl_ocp_t ocp)
return NULL;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
{
@ -874,7 +875,7 @@ rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_add_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
{
@ -954,7 +955,7 @@ rpl_add_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
p->dtsn = dio->dtsn;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static void
global_repair(uip_ipaddr_t *from, rpl_dag_t *dag, rpl_dio_t *dio)
{
@ -981,7 +982,7 @@ global_repair(uip_ipaddr_t *from, rpl_dag_t *dag, rpl_dio_t *dio)
RPL_STAT(rpl_stats.global_repairs++);
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_local_repair(rpl_instance_t *instance)
{
@ -999,7 +1000,7 @@ rpl_local_repair(rpl_instance_t *instance)
RPL_STAT(rpl_stats.local_repairs++);
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_recalculate_ranks(void)
{
@ -1035,7 +1036,7 @@ rpl_recalculate_ranks(void)
}
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
int
rpl_process_parent_event(rpl_instance_t *instance, rpl_parent_t *p)
{
@ -1082,7 +1083,7 @@ rpl_process_parent_event(rpl_instance_t *instance, rpl_parent_t *p)
return return_value;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
{
@ -1219,4 +1220,4 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
}
p->dtsn = dio->dtsn;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/

View file

@ -53,7 +53,7 @@
#include <limits.h>
#include <string.h>
/************************************************************************/
/*---------------------------------------------------------------------------*/
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_HBHO_BUF ((struct uip_hbho_hdr *)&uip_buf[uip_l2_l3_hdr_len])
@ -61,7 +61,7 @@
#define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
/************************************************************************/
/*---------------------------------------------------------------------------*/
int
rpl_verify_header(int uip_ext_opt_offset)
{
@ -118,7 +118,7 @@ rpl_verify_header(int uip_ext_opt_offset)
return 0;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static void
set_rpl_opt(unsigned uip_ext_opt_offset)
{
@ -141,7 +141,7 @@ set_rpl_opt(unsigned uip_ext_opt_offset)
UIP_IP_BUF->len[0]++;
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_update_header_empty(void)
{
@ -192,7 +192,7 @@ rpl_update_header_empty(void)
return;
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
int
rpl_update_header_final(uip_ipaddr_t *addr)
{
@ -230,7 +230,7 @@ rpl_update_header_final(uip_ipaddr_t *addr)
}
return 0;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_remove_header(void)
{
@ -257,7 +257,7 @@ rpl_remove_header(void)
PRINTF("RPL: No hop-by-hop Option found\n");
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
uint8_t
rpl_invert_header(void)
{
@ -292,4 +292,4 @@ rpl_invert_header(void)
return 0;
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/

View file

@ -47,7 +47,7 @@
#define DEBUG DEBUG_NONE
#include "net/uip-debug.h"
/************************************************************************/
/*---------------------------------------------------------------------------*/
static struct ctimer periodic_timer;
static void handle_periodic_timer(void *ptr);
@ -59,7 +59,7 @@ static uint16_t next_dis;
/* dio_send_ok is true if the node is ready to send DIOs */
static uint8_t dio_send_ok;
/************************************************************************/
/*---------------------------------------------------------------------------*/
static void
handle_periodic_timer(void *ptr)
{
@ -76,7 +76,7 @@ handle_periodic_timer(void *ptr)
#endif
ctimer_reset(&periodic_timer);
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static void
new_dio_interval(rpl_instance_t *instance)
{
@ -122,7 +122,7 @@ new_dio_interval(rpl_instance_t *instance)
PRINTF("RPL: Scheduling DIO timer %lu ticks in future (Interval)\n", time);
ctimer_set(&instance->dio_timer, time, &handle_dio_timer, instance);
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static void
handle_dio_timer(void *ptr)
{
@ -165,14 +165,14 @@ handle_dio_timer(void *ptr)
new_dio_interval(instance);
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_reset_periodic_timer(void)
{
next_dis = RPL_DIS_INTERVAL - RPL_DIS_START_DELAY;
ctimer_set(&periodic_timer, CLOCK_SECOND, handle_periodic_timer, NULL);
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
/* Resets the DIO timer in the instance to its minimal interval. */
void
rpl_reset_dio_timer(rpl_instance_t *instance)
@ -190,7 +190,7 @@ rpl_reset_dio_timer(rpl_instance_t *instance)
#endif /* RPL_CONF_STATS */
#endif /* RPL_LEAF_ONLY */
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static void
handle_dao_timer(void *ptr)
{
@ -214,7 +214,7 @@ handle_dao_timer(void *ptr)
}
ctimer_stop(&instance->dao_timer);
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_schedule_dao(rpl_instance_t *instance)
{
@ -233,4 +233,4 @@ rpl_schedule_dao(rpl_instance_t *instance)
handle_dao_timer, instance);
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/

View file

@ -74,7 +74,7 @@ rpl_purge_routes(void)
}
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_remove_routes(rpl_dag_t *dag)
{
@ -86,7 +86,7 @@ rpl_remove_routes(rpl_dag_t *dag)
}
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_remove_routes_by_nexthop(uip_ipaddr_t *nexthop, rpl_dag_t *dag)
{
@ -103,7 +103,7 @@ rpl_remove_routes_by_nexthop(uip_ipaddr_t *nexthop, rpl_dag_t *dag)
}
ANNOTATE("#L %u 0\n",nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
uip_ds6_route_t *
rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len,
uip_ipaddr_t *next_hop)
@ -136,7 +136,7 @@ rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len,
return rep;
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
static void
rpl_link_neighbor_callback(const rimeaddr_t *addr, int known, int etx)
{
@ -179,7 +179,7 @@ rpl_link_neighbor_callback(const rimeaddr_t *addr, int known, int etx)
uip_ds6_route_rm_by_nexthop(&ipaddr);
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_ipv6_neighbor_callback(uip_ds6_nbr_t *nbr)
{
@ -203,7 +203,7 @@ rpl_ipv6_neighbor_callback(uip_ds6_nbr_t *nbr)
}
}
}
/************************************************************************/
/*---------------------------------------------------------------------------*/
void
rpl_init(void)
{
@ -222,4 +222,4 @@ rpl_init(void)
memset(&rpl_stats, 0, sizeof(rpl_stats));
#endif
}
/************************************************************************/
/*---------------------------------------------------------------------------*/