Logging fixes

This commit is contained in:
Simon Duquennoy 2017-06-20 18:26:31 +02:00
parent 661f4c5023
commit 4c68f68b07
12 changed files with 63 additions and 174 deletions

View File

@ -1,53 +0,0 @@
/*
* Copyright (c) 2009, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Default log levels for a number of modules
* \author
* Simon Duquennoy <simon.duquennoy@ri.se>
*/
/** \addtogroup uip6
* @{ */
#ifndef __IPV6_LOG_CONF_H__
#define __IPV6_LOG_CONF_H__
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE_STR "IPv6"
#define LOG_LEVEL IPV6_LOG_LEVEL
#endif /* __IPV6_LOG_CONF_H__ */
/** @} */

View File

@ -626,7 +626,7 @@ send_data(struct websocket *s, const void *data,
if(datalen > sizeof(buf) - 4 - 4) {
LOG_ERR("trying to send too large data chunk %d > %d\n",
datalen, sizeof(buf) - 4 - 4);
datalen, (int)sizeof(buf) - 4 - 4);
return -1;
}

View File

@ -40,8 +40,10 @@
#include <string.h>
#include "net/mac/framer/frame802154e-ie.h"
#define DEBUG DEBUG_NONE
#include "net/net-debug.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE_STR "Frame 802.15.4e"
#define LOG_LEVEL FRAMER_LOG_LEVEL
/* c.f. IEEE 802.15.4e Table 4b */
enum ieee802154e_header_ie_id {
@ -470,27 +472,27 @@ frame802154e_parse_information_elements(const uint8_t *buf, uint8_t buf_size,
buf_size -= 2;
buf += 2;
type = ie_desc & 0x8000 ? 1 : 0; /* b15 */
PRINTF("frame802154e: ie type %u, current state %u\n", type, parsing_state);
LOG_DBG("ie type %u, current state %u\n", type, parsing_state);
switch(parsing_state) {
case PARSING_HEADER_IE:
if(type != 0) {
PRINTF("frame802154e: wrong type %04x\n", ie_desc);
LOG_ERR("wrong type %04x\n", ie_desc);
return -1;
}
/* Header IE: 2 bytes descriptor, c.f. fig 48n in IEEE 802.15.4e */
len = ie_desc & 0x007f; /* b0-b6 */
id = (ie_desc & 0x7f80) >> 7; /* b7-b14 */
PRINTF("frame802154e: header ie len %u id %x\n", len, id);
LOG_DBG("header ie len %u id %x\n", len, id);
switch(id) {
case HEADER_IE_LIST_TERMINATION_1:
if(len == 0) {
/* End of payload IE list, now expect payload IEs */
parsing_state = PARSING_PAYLOAD_IE;
ies->ie_payload_ie_offset = buf - start; /* Save IE header len */
PRINTF("frame802154e: list termination 1, look for payload IEs\n");
LOG_DBG("list termination 1, look for payload IEs\n");
} else {
PRINTF("frame802154e: list termination 1, wrong len %u\n", len);
LOG_ERR("list termination 1, wrong len %u\n", len);
return -1;
}
break;
@ -498,15 +500,15 @@ frame802154e_parse_information_elements(const uint8_t *buf, uint8_t buf_size,
/* End of IE parsing */
if(len == 0) {
ies->ie_payload_ie_offset = buf - start; /* Save IE header len */
PRINTF("frame802154e: list termination 2\n");
LOG_DBG("list termination 2\n");
return buf + len - start;
} else {
PRINTF("frame802154e: list termination 2, wrong len %u\n", len);
LOG_ERR("list termination 2, wrong len %u\n", len);
return -1;
}
default:
if(len > buf_size || frame802154e_parse_header_ie(buf, len, id, ies) == -1) {
PRINTF("frame802154e: failed to parse\n");
LOG_ERR("failed to parse\n");
return -1;
}
break;
@ -514,26 +516,26 @@ frame802154e_parse_information_elements(const uint8_t *buf, uint8_t buf_size,
break;
case PARSING_PAYLOAD_IE:
if(type != 1) {
PRINTF("frame802154e: wrong type %04x\n", ie_desc);
LOG_ERR("wrong type %04x\n", ie_desc);
return -1;
}
/* Payload IE: 2 bytes descriptor, c.f. fig 48o in IEEE 802.15.4e */
len = ie_desc & 0x7ff; /* b0-b10 */
id = (ie_desc & 0x7800) >> 11; /* b11-b14 */
PRINTF("frame802154e: payload ie len %u id %x\n", len, id);
LOG_DBG("payload ie len %u id %x\n", len, id);
switch(id) {
case PAYLOAD_IE_MLME:
/* Now expect 'len' bytes of MLME sub-IEs */
parsing_state = PARSING_MLME_SUBIE;
nested_mlme_len = len;
len = 0; /* Reset len as we want to read subIEs and not jump over them */
PRINTF("frame802154e: entering MLME ie with len %u\n", nested_mlme_len);
LOG_DBG("entering MLME ie with len %u\n", nested_mlme_len);
break;
case PAYLOAD_IE_LIST_TERMINATION:
PRINTF("frame802154e: payload ie list termination %u\n", len);
LOG_DBG("payload ie list termination %u\n", len);
return (len == 0) ? buf + len - start : -1;
default:
PRINTF("frame802154e: non-supported payload ie\n");
LOG_ERR("non-supported payload ie\n");
return -1;
}
break;
@ -544,30 +546,30 @@ frame802154e_parse_information_elements(const uint8_t *buf, uint8_t buf_size,
/* Short sub-IE, c.f. fig 48r in IEEE 802.15.4e */
len = ie_desc & 0x00ff; /* b0-b7 */
id = (ie_desc & 0x7f00) >> 8; /* b8-b14 */
PRINTF("frame802154e: short mlme ie len %u id %x\n", len, id);
LOG_DBG("short mlme ie len %u id %x\n", len, id);
if(len > buf_size || frame802154e_parse_mlme_short_ie(buf, len, id, ies) == -1) {
PRINTF("frame802154e: failed to parse ie\n");
LOG_ERR("failed to parse ie\n");
return -1;
}
} else {
/* Long sub-IE, c.f. fig 48s in IEEE 802.15.4e */
len = ie_desc & 0x7ff; /* b0-b10 */
id = (ie_desc & 0x7800) >> 11; /* b11-b14 */
PRINTF("frame802154e: long mlme ie len %u id %x\n", len, id);
LOG_DBG("long mlme ie len %u id %x\n", len, id);
if(len > buf_size || frame802154e_parse_mlme_long_ie(buf, len, id, ies) == -1) {
PRINTF("frame802154e: failed to parse ie\n");
LOG_ERR("failed to parse ie\n");
return -1;
}
}
/* Update remaining nested MLME len */
nested_mlme_len -= 2 + len;
if(nested_mlme_len < 0) {
PRINTF("frame802154e: found more sub-IEs than initially advertised\n");
LOG_ERR("found more sub-IEs than initially advertised\n");
/* We found more sub-IEs than initially advertised */
return -1;
}
if(nested_mlme_len == 0) {
PRINTF("frame802154e: end of MLME IE parsing\n");
LOG_DBG("end of MLME IE parsing\n");
/* End of IE parsing, look for another payload IE */
parsing_state = PARSING_PAYLOAD_IE;
}

View File

@ -43,16 +43,10 @@
#include "lib/random.h"
#include <string.h>
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINTADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7])
#else
#define PRINTF(...)
#define PRINTADDR(addr)
#endif
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE_STR "Frame 802.15.4e"
#define LOG_LEVEL FRAMER_LOG_LEVEL
/** \brief The sequence number (0x00 - 0xff) added to the transmitted
* data or MAC command frame. The default is a random value within
@ -180,13 +174,13 @@ create_frame(int type, int do_create)
} else if(packetbuf_hdralloc(hdr_len)) {
frame802154_create(&params, packetbuf_hdrptr());
PRINTF("15.4-OUT: %2X", params.fcf.frame_type);
PRINTADDR(params.dest_addr);
PRINTF("%d %u (%u)\n", hdr_len, packetbuf_datalen(), packetbuf_totlen());
LOG_INFO("Out: %2X", params.fcf.frame_type);
LOG_INFO_LLADDR((const linkaddr_t *)params.dest_addr);
LOG_INFO("%d %u (%u)\n", hdr_len, packetbuf_datalen(), packetbuf_totlen());
return hdr_len;
} else {
PRINTF("15.4-OUT: too large header: %u\n", hdr_len);
LOG_ERR("Out: too large header: %u\n", hdr_len);
return FRAMER_FAILED;
}
}
@ -218,7 +212,7 @@ parse(void)
if(frame.dest_pid != frame802154_get_pan_id() &&
frame.dest_pid != FRAME802154_BROADCASTPANDID) {
/* Packet to another PAN */
PRINTF("15.4: for another pan %u\n", frame.dest_pid);
LOG_WARN("In: for another pan %u\n", frame.dest_pid);
return FRAMER_FAILED;
}
if(!frame802154_is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
@ -243,10 +237,10 @@ parse(void)
}
#endif /* LLSEC802154_USES_AUX_HEADER */
PRINTF("15.4-IN: %2X", frame.fcf.frame_type);
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
PRINTF("%d %u (%u)\n", hdr_len, packetbuf_datalen(), packetbuf_totlen());
LOG_INFO("In: %2X", frame.fcf.frame_type);
LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
LOG_INFO("%d %u (%u)\n", hdr_len, packetbuf_datalen(), packetbuf_totlen());
return hdr_len;
}

View File

@ -41,6 +41,14 @@
/******** Configuration *******/
/* TSCH per-slot logging. Enabled by default if DBG is enabled */
#ifdef TSCH_LOG_CONF_PER_SLOT
#define TSCH_LOG_PER_SLOT TSCH_LOG_CONF_PER_SLOT
#else /* TSCH_LOG_CONF_PER_SLOT */
#include "sys/log.h"
#define TSCH_LOG_PER_SLOT (MAC_LOG_LEVEL >= LOG_LEVEL_DBG)
#endif /* TSCH_LOG_CONF_PER_SLOT */
/* The length of the log queue, i.e. maximum number postponed log messages */
#ifdef TSCH_LOG_CONF_QUEUE_LEN
#define TSCH_LOG_QUEUE_LEN TSCH_LOG_CONF_QUEUE_LEN
@ -55,16 +63,6 @@
#define TSCH_LOG_ID_FROM_LINKADDR(addr) ((addr) ? (addr)->u8[LINKADDR_SIZE - 1] : 0)
#endif /* TSCH_LOG_ID_FROM_LINKADDR */
/* TSCH log levels:
* 0: no log
* 1: basic PRINTF enabled
* 2: basic PRINTF enabled and tsch-log module enabled */
#ifdef TSCH_LOG_CONF_PER_SLOT
#define TSCH_LOG_PER_SLOT TSCH_LOG_CONF_PER_SLOT
#else /* TSCH_LOG_CONF_PER_SLOT */
#define TSCH_LOG_PER_SLOT 0
#endif /* TSCH_LOG_CONF_PER_SLOT */
#if (TSCH_LOG_PER_SLOT == 0)
#define tsch_log_init()

View File

@ -361,9 +361,9 @@ tsch_packet_parse_eb(const uint8_t *buf, int buf_size,
LOG_ERR("! parse_eb: frame is not a valid TSCH beacon. Frame version %u, type %u, FCF %02x %02x\n",
frame->fcf.frame_version, frame->fcf.frame_type, buf[0], buf[1]);
LOG_ERR("! parse_eb: frame was from 0x%x/", frame->src_pid);
LOG_ERR_LLADDR((const uip_lladdr_t *)&frame->src_addr);
LOG_ERR_LLADDR((const linkaddr_t *)&frame->src_addr);
LOG_ERR(" to 0x%x/", frame->dest_pid);
LOG_ERR_LLADDR((const uip_lladdr_t *)&frame->dest_addr);
LOG_ERR_LLADDR((const linkaddr_t *)&frame->dest_addr);
LOG_ERR("\n");
return 0;
}

View File

@ -52,6 +52,7 @@
#include "net/mac/tsch/tsch-queue.h"
#include "net/mac/tsch/tsch-schedule.h"
#include "net/mac/tsch/tsch-slot-operation.h"
#include "net/mac/tsch/tsch-log.h"
#include <string.h>
/* Log configuration */

View File

@ -40,8 +40,8 @@
*
*/
#include "contiki.h"
#include "dev/radio.h"
#include "contiki.h"
#include "net/netstack.h"
#include "net/packetbuf.h"
#include "net/queuebuf.h"
@ -59,12 +59,7 @@
#include "sys/cooja_mt.h"
#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */
#if TSCH_LOG_LEVEL >= 1
#define DEBUG DEBUG_PRINT
#else /* TSCH_LOG_LEVEL */
#define DEBUG DEBUG_NONE
#endif /* TSCH_LOG_LEVEL */
#include "net/net-debug.h"
#include <stdio.h>
/* TSCH debug macros, i.e. to set LEDs or GPIOs on various TSCH
* timeslot events */

View File

@ -938,7 +938,7 @@ send_packet(mac_callback_t sent, void *ptr)
tsch_queue_packet_count(addr),
p->header_len,
queuebuf_datalen(p->qb));
(void)packet_count_before; /* Discard "variable set but unused"warning in case of TSCH_LOG_LEVEL of 0 */
(void)packet_count_before; /* Discard "variable set but unused" warning in case of TSCH_LOG_PER_SLOT */
}
}
if(ret != MAC_TX_DEFERRED) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, Swedish Institute of Computer Science.
* Copyright (c) 2017, RISE SICS.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -61,9 +61,13 @@
#endif /* TCPIP_LOG_LEVEL */
#ifndef MAC_LOG_LEVEL
#define MAC_LOG_LEVEL LOG_LEVEL_WARN
#define MAC_LOG_LEVEL LOG_LEVEL_NONE
#endif /* MAC_LOG_LEVELL */
#ifndef FRAMER_LOG_LEVEL
#define FRAMER_LOG_LEVEL LOG_LEVEL_NONE
#endif /* FRAMER_LOG_LEVEL */
#endif /* __LOG_CONF_H__ */
/** @} */

View File

@ -1,52 +0,0 @@
/*
* Copyright (c) 2009, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Per-module, per-level logging
* \author
* Simon Duquennoy <simon.duquennoy@ri.se>
*/
/**
* \addtogroup log
* @{
*/
#include "contiki-conf.h"
#include "sys/log.h"
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, Swedish Institute of Computer Science.
* Copyright (c) 2017, RISE SICS.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -66,7 +66,7 @@ void uip_debug_ipaddr_print(const uip_ipaddr_t *addr);
#define LOG_LEVEL_ERR 1 /* Errors */
#define LOG_LEVEL_WARN 2 /* Warnings */
#define LOG_LEVEL_INFO 3 /* Basic info */
#define LOG_LEVEL_DDG 4 /* Detailled debug */
#define LOG_LEVEL_DBG 4 /* Detailled debug */
#define LOG_LEVEL_ANNOTATE 5 /* Cooja annotations */
/* Prefix all logs with file name and line-of-code */
@ -119,23 +119,23 @@ void uip_debug_ipaddr_print(const uip_ipaddr_t *addr);
#define LOG_ERR(...) LOG(LOG_LEVEL_ERR, __VA_ARGS__)
#define LOG_WARN(...) LOG(LOG_LEVEL_WARN, __VA_ARGS__)
#define LOG_INFO(...) LOG(LOG_LEVEL_INFO, __VA_ARGS__)
#define LOG_DBG(...) LOG(LOG_LEVEL_DDG, __VA_ARGS__)
#define LOG_DBG(...) LOG(LOG_LEVEL_DBG, __VA_ARGS__)
#define LOG_ERR_LLADDR(...) LOG_LLADDR(LOG_LEVEL_ERR, __VA_ARGS__)
#define LOG_WARN_LLADDR(...) LOG_LLADDR(LOG_LEVEL_WARN, __VA_ARGS__)
#define LOG_INFO_LLADDR(...) LOG_LLADDR(LOG_LEVEL_INFO, __VA_ARGS__)
#define LOG_DBG_LLADDR(...) LOG_LLADDR(LOG_LEVEL_DDG, __VA_ARGS__)
#define LOG_DBG_LLADDR(...) LOG_LLADDR(LOG_LEVEL_DBG, __VA_ARGS__)
#define LOG_ERR_6ADDR(...) LOG_6ADDR(LOG_LEVEL_ERR, __VA_ARGS__)
#define LOG_WARN_6ADDR(...) LOG_6ADDR(LOG_LEVEL_WARN, __VA_ARGS__)
#define LOG_INFO_6ADDR(...) LOG_6ADDR(LOG_LEVEL_INFO, __VA_ARGS__)
#define LOG_DBG_6ADDR(...) LOG_6ADDR(LOG_LEVEL_DDG, __VA_ARGS__)
#define LOG_DBG_6ADDR(...) LOG_6ADDR(LOG_LEVEL_DBG, __VA_ARGS__)
/* For testing log level */
#define LOG_ERR_ENABLED (LOG_LEVEL >= LOG_LEVEL_ERR)
#define LOG_WARN_ENABLED (LOG_LEVEL >= LOG_LEVEL_WARN)
#define LOG_INFO_ENABLED (LOG_LEVEL >= LOG_LEVEL_INFO)
#define LOG_DBG_ENABLED (LOG_LEVEL >= LOG_LEVEL_DDG)
#define LOG_DBG_ENABLED (LOG_LEVEL >= LOG_LEVEL_DBG)
#define LOG_ANNOTATE_ENABLED (LOG_LEVEL >= LOG_LEVEL_ANNOTATE)
#endif /* __LOG_H__ */