Deployment: use node-id for compact address logging

This commit is contained in:
Simon Duquennoy 2018-05-26 05:04:03 -07:00
parent 9ae283031a
commit 95208a804a
5 changed files with 58 additions and 15 deletions

View File

@ -258,7 +258,11 @@ uip_sr_link_snprint(char *buf, int buflen, uip_sr_node_t *link)
NETSTACK_ROUTING.get_sr_node_ipaddr(&child_ipaddr, link);
NETSTACK_ROUTING.get_sr_node_ipaddr(&parent_ipaddr, link->parent);
index += uiplib_ipaddr_snprint(buf+index, buflen-index, &child_ipaddr);
if(LOG_WITH_COMPACT_ADDR) {
index += log_6addr_compact_snprint(buf+index, buflen-index, &child_ipaddr);
} else {
index += uiplib_ipaddr_snprint(buf+index, buflen-index, &child_ipaddr);
}
if(index >= buflen) {
return index;
}
@ -273,7 +277,11 @@ uip_sr_link_snprint(char *buf, int buflen, uip_sr_node_t *link)
if(index >= buflen) {
return index;
}
index += uiplib_ipaddr_snprint(buf+index, buflen-index, &parent_ipaddr);
if(LOG_WITH_COMPACT_ADDR) {
index += log_6addr_compact_snprint(buf+index, buflen-index, &parent_ipaddr);
} else {
index += uiplib_ipaddr_snprint(buf+index, buflen-index, &parent_ipaddr);
}
if(index >= buflen) {
return index;
}

View File

@ -94,7 +94,11 @@ rpl_neighbor_snprint(char *buf, int buflen, rpl_nbr_t *nbr)
const struct link_stats *stats = rpl_neighbor_get_link_stats(nbr);
clock_time_t clock_now = clock_time();
index += uiplib_ipaddr_snprint(buf+index, buflen-index, rpl_neighbor_get_ipaddr(nbr));
if(LOG_WITH_COMPACT_ADDR) {
index += log_6addr_compact_snprint(buf+index, buflen-index, rpl_neighbor_get_ipaddr(nbr));
} else {
index += uiplib_ipaddr_snprint(buf+index, buflen-index, rpl_neighbor_get_ipaddr(nbr));
}
if(index >= buflen) {
return index;
}

View File

@ -46,7 +46,8 @@
#ifndef __LOG_CONF_H__
#define __LOG_CONF_H__
/* Log only the last 16 bytes of link-layer and IPv6 addresses */
/* Log only the last 16 bytes of link-layer and IPv6 addresses (or, if)
* the deployment module is enabled, the node IDs */
#ifdef LOG_CONF_WITH_COMPACT_ADDR
#define LOG_WITH_COMPACT_ADDR LOG_CONF_WITH_COMPACT_ADDR
#else /* LOG_CONF_WITH_COMPACT_ADDR */

View File

@ -51,6 +51,7 @@
#include "sys/log.h"
#include "net/ipv6/ip64-addr.h"
#include "net/ipv6/uiplib.h"
#include "deployment/deployment.h"
int curr_log_level_rpl = LOG_CONF_LEVEL_RPL;
int curr_log_level_tcpip = LOG_CONF_LEVEL_TCPIP;
@ -90,22 +91,36 @@ log_6addr(const uip_ipaddr_t *ipaddr)
LOG_OUTPUT("%s", buf);
}
/*---------------------------------------------------------------------------*/
int
log_6addr_compact_snprint(char *buf, size_t size, const uip_ipaddr_t *ipaddr)
{
if(ipaddr == NULL) {
return snprintf(buf, size, "6A-NULL");
} else {
char *prefix = NULL;
if(uip_is_addr_mcast(ipaddr)) {
prefix = "6M";
} else if(uip_is_addr_linklocal(ipaddr)) {
prefix = "6L";
} else {
prefix = "6G";
}
#if BUILD_WITH_DEPLOYMENT
return snprintf(buf, size, "%s-%03u", prefix, deployment_id_from_iid(ipaddr));
#else /* BUILD_WITH_DEPLOYMENT */
return snprintf(buf, size, "%s-%04x", prefix, UIP_HTONS(ipaddr->u16[sizeof(uip_ipaddr_t)/2-1]));
#endif /* BUILD_WITH_DEPLOYMENT */
}
}
/*---------------------------------------------------------------------------*/
void
log_6addr_compact(const uip_ipaddr_t *ipaddr)
{
if(ipaddr == NULL) {
LOG_OUTPUT("6A-NULL");
} else if(uip_is_addr_mcast(ipaddr)) {
LOG_OUTPUT("6M-%04x", UIP_HTONS(ipaddr->u16[sizeof(uip_ipaddr_t)/2-1]));
} else if(uip_is_addr_linklocal(ipaddr)) {
LOG_OUTPUT("6L-%04x", UIP_HTONS(ipaddr->u16[sizeof(uip_ipaddr_t)/2-1]));
} else {
LOG_OUTPUT("6G-%04x", UIP_HTONS(ipaddr->u16[sizeof(uip_ipaddr_t)/2-1]));
}
char buf[8];
log_6addr_compact_snprint(buf, sizeof(buf), ipaddr);
LOG_OUTPUT("%s", buf);
}
#endif /* NETSTACK_CONF_WITH_IPV6 */
/*---------------------------------------------------------------------------*/
void
log_lladdr(const linkaddr_t *lladdr)
@ -130,11 +145,15 @@ log_lladdr_compact(const linkaddr_t *lladdr)
if(lladdr == NULL || linkaddr_cmp(lladdr, &linkaddr_null)) {
LOG_OUTPUT("LL-NULL");
} else {
#if BUILD_WITH_DEPLOYMENT
LOG_OUTPUT("LL-%04u", deployment_id_from_lladdr(lladdr));
#else /* BUILD_WITH_DEPLOYMENT */
#if LINKADDR_SIZE == 8
LOG_OUTPUT("LL-%04x", UIP_HTONS(lladdr->u16[LINKADDR_SIZE/2-1]));
#elif LINKADDR_SIZE == 2
LOG_OUTPUT("LL-%04x", UIP_HTONS(lladdr->u16));
#endif
#endif /* BUILD_WITH_DEPLOYMENT */
}
}
/*---------------------------------------------------------------------------*/

View File

@ -194,6 +194,17 @@ void log_6addr(const uip_ipaddr_t *ipaddr);
*/
void log_6addr_compact(const uip_ipaddr_t *ipaddr);
/**
* Write at most size - 1 characters of the IP address to the output string,
* in a compact representation. The output is always null-terminated, unless
* size is 0.
*
* \param buf A pointer to an output string with at least size bytes.
* \param size The max number of characters to write to the output string.
* \param ipaddr A pointer to a uip_ipaddr_t that will be printed with printf().
*/
int log_6addr_compact_snprint(char *buf, size_t size, const uip_ipaddr_t *ipaddr);
#endif /* NETSTACK_CONF_WITH_IPV6 */
/**