Introduce rpl_neighbor_snprint, for consistent printing of a RPL neighbor to a string
This commit is contained in:
parent
29061e9885
commit
97a9d7707c
|
@ -46,6 +46,7 @@
|
||||||
#include "net/routing/rpl-lite/rpl.h"
|
#include "net/routing/rpl-lite/rpl.h"
|
||||||
#include "net/link-stats.h"
|
#include "net/link-stats.h"
|
||||||
#include "net/nbr-table.h"
|
#include "net/nbr-table.h"
|
||||||
|
#include "net/ipv6/uiplib.h"
|
||||||
|
|
||||||
/* Log configuration */
|
/* Log configuration */
|
||||||
#include "sys/log.h"
|
#include "sys/log.h"
|
||||||
|
@ -85,28 +86,24 @@ acceptable_rank(rpl_rank_t rank)
|
||||||
&& rank <= max_acceptable_rank();
|
&& rank <= max_acceptable_rank();
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
int
|
||||||
rpl_neighbor_print_list(const char *str)
|
rpl_neighbor_snprint(char *buf, int buflen, rpl_nbr_t *nbr)
|
||||||
{
|
{
|
||||||
if(curr_instance.used) {
|
int index = 0;
|
||||||
int curr_dio_interval = curr_instance.dag.dio_intcurrent;
|
|
||||||
int curr_rank = curr_instance.dag.rank;
|
|
||||||
rpl_nbr_t *nbr = nbr_table_head(rpl_neighbors);
|
|
||||||
rpl_nbr_t *best = best_parent(0);
|
rpl_nbr_t *best = best_parent(0);
|
||||||
|
const struct link_stats *stats = rpl_neighbor_get_link_stats(nbr);
|
||||||
clock_time_t clock_now = clock_time();
|
clock_time_t clock_now = clock_time();
|
||||||
|
|
||||||
LOG_INFO("nbr: own state, addr ");
|
index += snprintf(buf+index, buflen-index, "nbr: ");
|
||||||
LOG_INFO_6ADDR(rpl_get_global_address());
|
if(index >= buflen) {
|
||||||
LOG_INFO_(", DAG state: %s, MOP %u OCP %u rank %u max-rank %u, dioint %u, nbr count %u (%s)\n",
|
return index;
|
||||||
rpl_dag_state_to_str(curr_instance.dag.state),
|
}
|
||||||
curr_instance.mop, curr_instance.of->ocp, curr_rank,
|
index += uiplib_ipaddr_snprint(buf+index, buflen-index, rpl_neighbor_get_ipaddr(nbr));
|
||||||
max_acceptable_rank(),
|
if(index >= buflen) {
|
||||||
curr_dio_interval, rpl_neighbor_count(), str);
|
return index;
|
||||||
while(nbr != NULL) {
|
}
|
||||||
const struct link_stats *stats = rpl_neighbor_get_link_stats(nbr);
|
index += snprintf(buf+index, buflen-index,
|
||||||
LOG_INFO("nbr: ");
|
"%5u, %5u => %5u -- %2u %c%c%c%c%c",
|
||||||
LOG_INFO_6ADDR(rpl_neighbor_get_ipaddr(nbr));
|
|
||||||
LOG_INFO_(" %5u, %5u => %5u -- %2u %c%c%c%c%c",
|
|
||||||
nbr->rank,
|
nbr->rank,
|
||||||
rpl_neighbor_get_link_metric(nbr),
|
rpl_neighbor_get_link_metric(nbr),
|
||||||
rpl_neighbor_rank_via_nbr(nbr),
|
rpl_neighbor_rank_via_nbr(nbr),
|
||||||
|
@ -117,16 +114,50 @@ rpl_neighbor_print_list(const char *str)
|
||||||
link_stats_is_fresh(stats) ? 'f' : ' ',
|
link_stats_is_fresh(stats) ? 'f' : ' ',
|
||||||
nbr == curr_instance.dag.preferred_parent ? 'p' : ' '
|
nbr == curr_instance.dag.preferred_parent ? 'p' : ' '
|
||||||
);
|
);
|
||||||
|
if(index >= buflen) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
if(stats->last_tx_time > 0) {
|
if(stats->last_tx_time > 0) {
|
||||||
LOG_INFO_(" (last tx %u min ago", (unsigned)((clock_now - stats->last_tx_time) / (60 * CLOCK_SECOND)));
|
index += snprintf(buf+index, buflen-index,
|
||||||
|
" (last tx %u min ago",
|
||||||
|
(unsigned)((clock_now - stats->last_tx_time) / (60 * CLOCK_SECOND)));
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO_(" (no tx");
|
index += snprintf(buf+index, buflen-index,
|
||||||
|
" (no tx");
|
||||||
|
}
|
||||||
|
if(index >= buflen) {
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
if(nbr->better_parent_since > 0) {
|
if(nbr->better_parent_since > 0) {
|
||||||
LOG_INFO_(", better since %u min)\n", (unsigned)((clock_now - nbr->better_parent_since) / (60 * CLOCK_SECOND)));
|
index += snprintf(buf+index, buflen-index,
|
||||||
|
", better since %u min)",
|
||||||
|
(unsigned)((clock_now - nbr->better_parent_since) / (60 * CLOCK_SECOND)));
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO_(")\n");
|
index += snprintf(buf+index, buflen-index,
|
||||||
|
")");
|
||||||
}
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
rpl_neighbor_print_list(const char *str)
|
||||||
|
{
|
||||||
|
if(curr_instance.used) {
|
||||||
|
int curr_dio_interval = curr_instance.dag.dio_intcurrent;
|
||||||
|
int curr_rank = curr_instance.dag.rank;
|
||||||
|
rpl_nbr_t *nbr = nbr_table_head(rpl_neighbors);
|
||||||
|
|
||||||
|
LOG_INFO("nbr: own state, addr ");
|
||||||
|
LOG_INFO_6ADDR(rpl_get_global_address());
|
||||||
|
LOG_INFO_(", DAG state: %s, MOP %u OCP %u rank %u max-rank %u, dioint %u, nbr count %u (%s)\n",
|
||||||
|
rpl_dag_state_to_str(curr_instance.dag.state),
|
||||||
|
curr_instance.mop, curr_instance.of->ocp, curr_rank,
|
||||||
|
max_acceptable_rank(),
|
||||||
|
curr_dio_interval, rpl_neighbor_count(), str);
|
||||||
|
while(nbr != NULL) {
|
||||||
|
char buf[120];
|
||||||
|
rpl_neighbor_snprint(buf, sizeof(buf), nbr);
|
||||||
|
LOG_INFO("%s\n", buf);
|
||||||
nbr = nbr_table_next(rpl_neighbors, nbr);
|
nbr = nbr_table_next(rpl_neighbors, nbr);
|
||||||
}
|
}
|
||||||
LOG_INFO("nbr: end of list\n");
|
LOG_INFO("nbr: end of list\n");
|
||||||
|
|
|
@ -192,6 +192,17 @@ void rpl_neighbor_remove_all(void);
|
||||||
*/
|
*/
|
||||||
rpl_nbr_t *rpl_neighbor_select_best(void);
|
rpl_nbr_t *rpl_neighbor_select_best(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print a textual description of RPL neighbor into a string
|
||||||
|
*
|
||||||
|
* \param buf The buffer where to write content
|
||||||
|
* \param len The buffer len
|
||||||
|
* \param addr A pointer to a RPL neighbor that will be written to the buffer
|
||||||
|
* \return Identical to snprintf: number of bytes written excluding ending null
|
||||||
|
* byte. A value >= buflen if the buffer was too small.
|
||||||
|
*/
|
||||||
|
int rpl_neighbor_snprint(char *buf, int buflen, rpl_nbr_t *nbr);
|
||||||
|
|
||||||
typedef rpl_nbr_t rpl_parent_t;
|
typedef rpl_nbr_t rpl_parent_t;
|
||||||
#define rpl_parent_get_from_ipaddr(addr) rpl_neighbor_get_from_ipaddr(addr)
|
#define rpl_parent_get_from_ipaddr(addr) rpl_neighbor_get_from_ipaddr(addr)
|
||||||
#define rpl_parent_get_ipaddr(nbr) rpl_neighbor_get_ipaddr(nbr)
|
#define rpl_parent_get_ipaddr(nbr) rpl_neighbor_get_ipaddr(nbr)
|
||||||
|
|
Loading…
Reference in New Issue