Routing API: add function node_has_joined

This commit is contained in:
Simon Duquennoy 2017-12-13 12:55:22 -08:00
parent 177a68db53
commit fe7ded0762
7 changed files with 34 additions and 1 deletions

View File

@ -82,6 +82,12 @@ leave_network(void)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
node_has_joined(void)
{
return 1;
}
/*---------------------------------------------------------------------------*/
static int
node_is_reachable(void) node_is_reachable(void)
{ {
return 1; return 1;
@ -151,6 +157,7 @@ const struct routing_driver nullrouting_driver = {
get_root_ipaddr, get_root_ipaddr,
get_sr_node_ipaddr, get_sr_node_ipaddr,
leave_network, leave_network,
node_has_joined,
node_is_reachable, node_is_reachable,
global_repair, global_repair,
local_repair, local_repair,

View File

@ -93,6 +93,12 @@ struct routing_driver {
* *
*/ */
void (* leave_network)(void); void (* leave_network)(void);
/**
* Tells whether the node is currently part of a network
*
* \return 1 if we have joined a network, 0 otherwise.
*/
int (* node_has_joined)(void);
/** /**
* Tells whether the node is currently reachable as part of the network * Tells whether the node is currently reachable as part of the network
* *

View File

@ -1006,6 +1006,12 @@ rpl_move_parent(rpl_dag_t *dag_src, rpl_dag_t *dag_dst, rpl_parent_t *parent)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
rpl_has_joined(void)
{
return rpl_get_any_dag() != NULL;
}
/*---------------------------------------------------------------------------*/
int
rpl_has_downward_route(void) rpl_has_downward_route(void)
{ {
int i; int i;

View File

@ -423,6 +423,7 @@ const struct routing_driver rpl_classic_driver = {
get_root_ipaddr, get_root_ipaddr,
get_sr_node_ipaddr, get_sr_node_ipaddr,
leave_network, leave_network,
rpl_has_joined,
rpl_has_downward_route, rpl_has_downward_route,
global_repair, global_repair,
local_repair, local_repair,

View File

@ -327,6 +327,12 @@ enum rpl_mode rpl_set_mode(enum rpl_mode mode);
*/ */
enum rpl_mode rpl_get_mode(void); enum rpl_mode rpl_get_mode(void);
/**
* Tells whether the node has joined a network or not
*
* \retval 1 if we have joined a network, 0 if not.
*/
int rpl_has_joined(void);
/** /**
* Get the RPL's best guess on if we have downward route or not. * Get the RPL's best guess on if we have downward route or not.

View File

@ -109,6 +109,12 @@ rpl_link_callback(const linkaddr_t *addr, int status, int numtx)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
rpl_has_joined(void)
{
return curr_instance.used && curr_instance.dag.state >= DAG_JOINED;
}
/*---------------------------------------------------------------------------*/
int
rpl_is_reachable(void) rpl_is_reachable(void)
{ {
return curr_instance.used && curr_instance.dag.state == DAG_REACHABLE; return curr_instance.used && curr_instance.dag.state == DAG_REACHABLE;
@ -226,6 +232,7 @@ const struct routing_driver rpl_lite_driver = {
rpl_dag_get_root_ipaddr, rpl_dag_get_root_ipaddr,
get_sr_node_ipaddr, get_sr_node_ipaddr,
rpl_dag_poison_and_leave, rpl_dag_poison_and_leave,
rpl_has_joined,
rpl_is_reachable, rpl_is_reachable,
rpl_global_repair, rpl_global_repair,
rpl_local_repair, rpl_local_repair,

View File

@ -49,7 +49,7 @@ AUTOSTART_PROCESSES(&wait_for_dag);
static void static void
timeout_handler(void) timeout_handler(void)
{ {
if(NETSTACK_ROUTING.node_is_reachable()) { if(NETSTACK_ROUTING.node_has_joined()) {
PRINTF("DAG Found\n"); PRINTF("DAG Found\n");
} }
} }