diff --git a/os/net/routing/nullrouting/nullrouting.c b/os/net/routing/nullrouting/nullrouting.c index fc788d58a..14c328b0c 100644 --- a/os/net/routing/nullrouting/nullrouting.c +++ b/os/net/routing/nullrouting/nullrouting.c @@ -82,6 +82,12 @@ leave_network(void) } /*---------------------------------------------------------------------------*/ static int +node_has_joined(void) +{ + return 1; +} +/*---------------------------------------------------------------------------*/ +static int node_is_reachable(void) { return 1; @@ -151,6 +157,7 @@ const struct routing_driver nullrouting_driver = { get_root_ipaddr, get_sr_node_ipaddr, leave_network, + node_has_joined, node_is_reachable, global_repair, local_repair, diff --git a/os/net/routing/routing.h b/os/net/routing/routing.h index 94cb874fd..7fe6e7ca8 100644 --- a/os/net/routing/routing.h +++ b/os/net/routing/routing.h @@ -93,6 +93,12 @@ struct routing_driver { * */ 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 * diff --git a/os/net/routing/rpl-classic/rpl-dag.c b/os/net/routing/rpl-classic/rpl-dag.c index a8ec7b3f4..899322264 100644 --- a/os/net/routing/rpl-classic/rpl-dag.c +++ b/os/net/routing/rpl-classic/rpl-dag.c @@ -1006,6 +1006,12 @@ rpl_move_parent(rpl_dag_t *dag_src, rpl_dag_t *dag_dst, rpl_parent_t *parent) } /*---------------------------------------------------------------------------*/ int +rpl_has_joined(void) +{ + return rpl_get_any_dag() != NULL; +} +/*---------------------------------------------------------------------------*/ +int rpl_has_downward_route(void) { int i; diff --git a/os/net/routing/rpl-classic/rpl.c b/os/net/routing/rpl-classic/rpl.c index 4b90165f0..b1905d611 100644 --- a/os/net/routing/rpl-classic/rpl.c +++ b/os/net/routing/rpl-classic/rpl.c @@ -423,6 +423,7 @@ const struct routing_driver rpl_classic_driver = { get_root_ipaddr, get_sr_node_ipaddr, leave_network, + rpl_has_joined, rpl_has_downward_route, global_repair, local_repair, diff --git a/os/net/routing/rpl-classic/rpl.h b/os/net/routing/rpl-classic/rpl.h index 85f092606..db87cc824 100644 --- a/os/net/routing/rpl-classic/rpl.h +++ b/os/net/routing/rpl-classic/rpl.h @@ -327,6 +327,12 @@ enum rpl_mode rpl_set_mode(enum rpl_mode mode); */ 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. diff --git a/os/net/routing/rpl-lite/rpl.c b/os/net/routing/rpl-lite/rpl.c index 07c8cf344..acfe94c37 100644 --- a/os/net/routing/rpl-lite/rpl.c +++ b/os/net/routing/rpl-lite/rpl.c @@ -109,6 +109,12 @@ rpl_link_callback(const linkaddr_t *addr, int status, int numtx) } /*---------------------------------------------------------------------------*/ int +rpl_has_joined(void) +{ + return curr_instance.used && curr_instance.dag.state >= DAG_JOINED; +} +/*---------------------------------------------------------------------------*/ +int rpl_is_reachable(void) { 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, get_sr_node_ipaddr, rpl_dag_poison_and_leave, + rpl_has_joined, rpl_is_reachable, rpl_global_repair, rpl_local_repair, diff --git a/tests/07-simulation-base/code-slip-radio/wait-dag.c b/tests/07-simulation-base/code-slip-radio/wait-dag.c index 06fa80250..a059661b4 100644 --- a/tests/07-simulation-base/code-slip-radio/wait-dag.c +++ b/tests/07-simulation-base/code-slip-radio/wait-dag.c @@ -49,7 +49,7 @@ AUTOSTART_PROCESSES(&wait_for_dag); static void timeout_handler(void) { - if(NETSTACK_ROUTING.node_is_reachable()) { + if(NETSTACK_ROUTING.node_has_joined()) { PRINTF("DAG Found\n"); } }