rpl: incremental instance id generation
This commit is contained in:
parent
f14ab00658
commit
3f238980f7
@ -132,6 +132,11 @@ extern "C" {
|
||||
*/
|
||||
#define GNRC_RPL_DEFAULT_OCP (0)
|
||||
|
||||
/**
|
||||
* @brief Default Instance ID
|
||||
*/
|
||||
#define GNRC_RPL_DEFAULT_INSTANCE (0)
|
||||
|
||||
/**
|
||||
* @name RPL Mode of Operations
|
||||
* @{
|
||||
@ -347,11 +352,16 @@ kernel_pid_t gnrc_rpl_init(kernel_pid_t if_pid);
|
||||
*
|
||||
* @param[in] instance_id Id of the instance
|
||||
* @param[in] dodag_id Id of the DODAG
|
||||
* @param[in] gen_inst_id Flag indicating whether to generate an instance id.
|
||||
* If true, @p instance_id will be ignored
|
||||
* @param[in] local_inst_id Flag indicating whether a local or global instance id
|
||||
* should be generatad
|
||||
*
|
||||
* @return Pointer to the new DODAG, on success.
|
||||
* @return NULL, otherwise.
|
||||
*/
|
||||
gnrc_rpl_dodag_t *gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_id);
|
||||
gnrc_rpl_dodag_t *gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_id, bool gen_inst_id,
|
||||
bool local_inst_id);
|
||||
|
||||
/**
|
||||
* @brief Send a DIO of the @p dodag to the @p destination.
|
||||
@ -458,6 +468,16 @@ gnrc_rpl_dodag_t *gnrc_rpl_root_dodag_init(uint8_t instance_id, ipv6_addr_t *dod
|
||||
* @param[in] dodag_id Id of the DODAG
|
||||
*/
|
||||
void gnrc_rpl_send(gnrc_pktsnip_t *pkt, ipv6_addr_t *src, ipv6_addr_t *dst, ipv6_addr_t *dodag_id);
|
||||
|
||||
/**
|
||||
* @brief Generate a local or global instance id
|
||||
*
|
||||
* @param[in] local flag to indicate whether a local or global instance id is requested
|
||||
*
|
||||
* @return Local instance id, if @p local is true
|
||||
* @return Global instance id, otherwise.
|
||||
*/
|
||||
uint8_t gnrc_rpl_gen_instance_id(bool local);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
#include "net/ipv6.h"
|
||||
#include "net/gnrc/ipv6/netif.h"
|
||||
#include "net/gnrc.h"
|
||||
#include "mutex.h"
|
||||
|
||||
#include "net/gnrc/rpl.h"
|
||||
|
||||
@ -31,6 +32,8 @@ static xtimer_t _lt_timer;
|
||||
static msg_t _lt_msg = { .type = GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE };
|
||||
static msg_t _msg_q[GNRC_RPL_MSG_QUEUE_SIZE];
|
||||
static gnrc_netreg_entry_t _me_reg;
|
||||
static mutex_t _inst_id_mutex = MUTEX_INIT;
|
||||
static uint8_t _instance_id;
|
||||
|
||||
gnrc_rpl_instance_t gnrc_rpl_instances[GNRC_RPL_INSTANCES_NUMOF];
|
||||
gnrc_rpl_dodag_t gnrc_rpl_dodags[GNRC_RPL_DODAGS_NUMOF];
|
||||
@ -45,6 +48,7 @@ kernel_pid_t gnrc_rpl_init(kernel_pid_t if_pid)
|
||||
{
|
||||
/* check if RPL was initialized before */
|
||||
if (gnrc_rpl_pid == KERNEL_PID_UNDEF) {
|
||||
_instance_id = 0;
|
||||
/* start the event loop */
|
||||
gnrc_rpl_pid = thread_create(_stack, sizeof(_stack), GNRC_RPL_PRIO, CREATE_STACKTEST,
|
||||
_event_loop, NULL, "RPL");
|
||||
@ -71,8 +75,13 @@ kernel_pid_t gnrc_rpl_init(kernel_pid_t if_pid)
|
||||
return gnrc_rpl_pid;
|
||||
}
|
||||
|
||||
gnrc_rpl_dodag_t *gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_id)
|
||||
gnrc_rpl_dodag_t *gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_id, bool gen_inst_id,
|
||||
bool local_inst_id)
|
||||
{
|
||||
if (gen_inst_id) {
|
||||
instance_id = gnrc_rpl_gen_instance_id(local_inst_id);
|
||||
}
|
||||
|
||||
gnrc_rpl_dodag_t *dodag = gnrc_rpl_root_dodag_init(instance_id, dodag_id, GNRC_RPL_DEFAULT_MOP);
|
||||
|
||||
if (!dodag) {
|
||||
@ -265,6 +274,22 @@ void _dao_handle_send(gnrc_rpl_dodag_t *dodag)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t gnrc_rpl_gen_instance_id(bool local)
|
||||
{
|
||||
mutex_lock(&_inst_id_mutex);
|
||||
uint8_t instance_id = GNRC_RPL_DEFAULT_INSTANCE;
|
||||
|
||||
if (local) {
|
||||
instance_id = ((_instance_id++) | GNRC_RPL_INSTANCE_ID_MSB);
|
||||
mutex_unlock(&_inst_id_mutex);
|
||||
return instance_id;
|
||||
}
|
||||
|
||||
instance_id = ((_instance_id++) & GNRC_RPL_GLOBAL_INSTANCE_MASK);
|
||||
mutex_unlock(&_inst_id_mutex);
|
||||
return instance_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@ -51,7 +51,7 @@ int _gnrc_rpl_dodag_root(char *arg1, char *arg2)
|
||||
}
|
||||
|
||||
gnrc_rpl_dodag_t *dodag = NULL;
|
||||
dodag = gnrc_rpl_root_init(instance_id, &dodag_id);
|
||||
dodag = gnrc_rpl_root_init(instance_id, &dodag_id, false, false);
|
||||
if (dodag == NULL) {
|
||||
char addr_str[IPV6_ADDR_MAX_STR_LEN];
|
||||
printf("error: could not add DODAG (%s) to instance (%d)\n",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user