Skip to content

Commit

Permalink
Add and use aodv_debug.h
Browse files Browse the repository at this point in the history
...which creates and prints debug messages starting with [aodvv2]
  • Loading branch information
Lotterleben committed Nov 4, 2014
1 parent 3df09f2 commit ae33b42
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 51 deletions.
45 changes: 25 additions & 20 deletions sys/net/routing/aodvv2/aodv.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#define ENABLE_DEBUG (0)
#include "debug.h"

#ifdef DEBUG
#define ENABLE_AODV_DEBUG (1)
#include "aodv_debug.h"
#endif

#define UDP_BUFFER_SIZE (128) /** with respect to IEEE 802.15.4's MTU */
#define RCV_MSG_Q_SIZE (32) /* TODO: check if smaller values work, too */

Expand Down Expand Up @@ -56,7 +61,7 @@ static struct writer_target *wt;

void aodv_init(void)
{
DEBUG("[aodvv2] %s()\n", __func__);
AODV_DEBUG("%s()\n", __func__);

/* TODO: set if_id properly */
int if_id = 0;
Expand All @@ -82,7 +87,7 @@ void aodv_init(void)
/* start listening & enable sending */
thread_create(aodv_rcv_stack_buf, sizeof(aodv_rcv_stack_buf), PRIORITY_MAIN,
CREATE_STACKTEST, _aodv_receiver_thread, NULL, "_aodv_receiver_thread");
DEBUG("[aodvv2] listening on port %d\n", HTONS(MANET_PORT));
AODV_DEBUG("listening on port %d\n", HTONS(MANET_PORT));
sender_thread = thread_create(aodv_snd_stack_buf, KERNEL_CONF_STACKSIZE_MAIN,
PRIORITY_MAIN, CREATE_STACKTEST, _aodv_sender_thread,
NULL, "_aodv_sender_thread");
Expand All @@ -102,7 +107,7 @@ void aodv_set_metric_type(aodvv2_metric_t metric_type)

void aodv_send_rreq(struct aodvv2_packet_data *packet_data)
{
DEBUG("[aodvv2] %s()\n", __func__);
AODV_DEBUG("%s()\n", __func__);

struct aodvv2_packet_data *pd = malloc(sizeof(struct aodvv2_packet_data));
memcpy(pd, packet_data, sizeof(struct aodvv2_packet_data));
Expand All @@ -129,7 +134,7 @@ void aodv_send_rreq(struct aodvv2_packet_data *packet_data)

void aodv_send_rrep(struct aodvv2_packet_data *packet_data, struct netaddr *next_hop)
{
DEBUG("[aodvv2] %s()\n", __func__);
AODV_DEBUG("%s()\n", __func__);

struct aodvv2_packet_data *pd = malloc(sizeof(struct aodvv2_packet_data));
memcpy(pd, packet_data, sizeof(struct aodvv2_packet_data));
Expand Down Expand Up @@ -159,7 +164,7 @@ void aodv_send_rrep(struct aodvv2_packet_data *packet_data, struct netaddr *next

void aodv_send_rerr(struct unreachable_node unreachable_nodes[], size_t len, struct netaddr *next_hop)
{
DEBUG("[aodvv2] %s()\n", __func__);
AODV_DEBUG("%s()\n", __func__);

struct rerr_data *rerrd = malloc(sizeof(struct rerr_data));
*rerrd = (struct rerr_data)
Expand Down Expand Up @@ -192,12 +197,12 @@ static void _init_addresses(void)
{
/* init multicast address: set to to a link-local all nodes multicast address */
ipv6_addr_set_all_nodes_addr(&_v6_addr_mcast);
DEBUG("[aodvv2] my multicast address is: %s\n",
AODV_DEBUG("my multicast address is: %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &_v6_addr_mcast));

/* get best IP for sending */
ipv6_net_if_get_best_src_addr(&_v6_addr_local, &_v6_addr_mcast);
DEBUG("[aodvv2] my src address is: %s\n",
AODV_DEBUG("my src address is: %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &_v6_addr_local));

/* store src & multicast address as netaddr as well for easy interaction
Expand All @@ -217,7 +222,7 @@ static void _init_sock_snd(void)
_sock_snd = socket_base_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);

if (-1 == _sock_snd) {
DEBUG("[aodvv2] Error Creating Socket!\n");
AODV_DEBUG("Error Creating Socket!\n");
return;
}
}
Expand All @@ -230,10 +235,10 @@ static void *_aodv_sender_thread(void *arg)

msg_t msgq[RCV_MSG_Q_SIZE];
msg_init_queue(msgq, sizeof msgq);
DEBUG("[aodvv2] _aodv_sender_thread initialized.\n");
AODV_DEBUG("_aodv_sender_thread initialized.\n");

while (true) {
DEBUG("[aodvv2] %s()\n", __func__);
AODV_DEBUG("%s()\n", __func__);
msg_t msg;
msg_receive(&msg);
struct msg_container *mc = (struct msg_container *) msg.content.ptr;
Expand Down Expand Up @@ -265,7 +270,7 @@ static void *_aodv_receiver_thread(void *arg)
{
(void) arg;

DEBUG("[aodvv2] %s()\n", __func__);
AODV_DEBUG("%s()\n", __func__);
uint32_t fromlen;
int32_t rcv_size;
char buf_rcv[UDP_BUFFER_SIZE];
Expand All @@ -284,16 +289,16 @@ static void *_aodv_receiver_thread(void *arg)
socket_base_close(sock_rcv);
}

DEBUG("[aodvv2] ready to receive data\n");
AODV_DEBUG("ready to receive data\n");
while (true) {
rcv_size = socket_base_recvfrom(sock_rcv, (void *)buf_rcv, UDP_BUFFER_SIZE, 0,
&sa_rcv, &fromlen);

if (rcv_size < 0) {
DEBUG("[aodvv2] ERROR receiving data!\n");
AODV_DEBUG("ERROR receiving data!\n");
}

DEBUG("[aodvv2] _aodv_receiver_thread() %s:",
AODV_DEBUG("_aodv_receiver_thread() %s:",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &_v6_addr_local));
DEBUG(" UDP packet received from %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &sa_rcv.sin6_addr));
Expand All @@ -303,7 +308,7 @@ static void *_aodv_receiver_thread(void *arg)

/* For some reason we sometimes get passed our own packets. drop them. */
if (!netaddr_cmp(&_sender, &na_local) == 0) {
DEBUG("[aodvv2] received our own packet, dropping it.\n");
AODV_DEBUG("received our own packet, dropping it.\n");
reader_handle_packet((void *) buf_rcv, rcv_size, &_sender);
}
}
Expand All @@ -315,7 +320,7 @@ static void *_aodv_receiver_thread(void *arg)

ipv6_addr_t *aodv_get_next_hop(ipv6_addr_t *dest)
{
DEBUG("[aodvv2] aodv_get_next_hop() %s:",
AODV_DEBUG("aodv_get_next_hop() %s:",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &_v6_addr_local));
DEBUG(" getting next hop for %s\n",
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, dest));
Expand All @@ -328,7 +333,7 @@ ipv6_addr_t *aodv_get_next_hop(ipv6_addr_t *dest)

/* The network stack sometimes asks us for the next hop towards our own IP */
if (memcmp(dest, &_v6_addr_local, sizeof(ipv6_addr_t)) == 0) {
DEBUG("[aodvv2] That's me, returning loopback\n");
AODV_DEBUG("That's me, returning loopback\n");
return &_v6_addr_loopback;
}

Expand Down Expand Up @@ -438,7 +443,7 @@ static void _write_packet(struct rfc5444_writer *wr __attribute__ ((unused)),
struct rfc5444_writer_target *iface __attribute__((unused)),
void *buffer, size_t length)
{
DEBUG("[aodvv2] %s()\n", __func__);
AODV_DEBUG("%s()\n", __func__);
/* generate hexdump and human readable representation of packet
* and print to console */
abuf_hexdump(&_hexbuf, "\t", buffer, length);
Expand All @@ -455,7 +460,7 @@ static void _write_packet(struct rfc5444_writer *wr __attribute__ ((unused)),
/* When originating a RREQ, add it to our RREQ table/update its predecessor */
if (wt->type == RFC5444_MSGTYPE_RREQ
&& netaddr_cmp(&wt->packet_data.origNode.addr, &na_local) == 0) {
DEBUG("[aodvv2] originating RREQ with SeqNum %d towards %s via %s; updating RREQ table...\n",
AODV_DEBUG("originating RREQ with SeqNum %d towards %s via %s; updating RREQ table...\n",
wt->packet_data.origNode.seqnum,
netaddr_to_string(&nbuf, &wt->packet_data.targNode.addr),
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &sa_wp.sin6_addr));
Expand All @@ -466,7 +471,7 @@ static void _write_packet(struct rfc5444_writer *wr __attribute__ ((unused)),
0, &sa_wp, sizeof sa_wp);

(void) bytes_sent;
DEBUG("[aodvv2] %d bytes sent.\n", bytes_sent);
AODV_DEBUG("%d bytes sent.\n", bytes_sent);
}

/* free the matryoshka doll of cobbled-together structs that the sender_thread receives */
Expand Down
47 changes: 47 additions & 0 deletions sys/net/routing/aodvv2/aodv_debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @addtogroup core_util
* @{
*
* @ingroup aodvv2
* @brief Debug-header for aodvv2 debug messages
*
*
* @author Lotte Steenbrink <[email protected]>
*/

#ifndef AODV_DEBUG_H_
#define AODV_DEBUG_H_

#include <stdio.h>
#include "sched.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Print aodvv2 specific debug information to std-out with [aodvv2] prefix
*
*/
#if ENABLE_AODV_DEBUG
#include "tcb.h"
#define AODV_DEBUG(...) \
do { \
printf("[aodvv2] "); \
printf(__VA_ARGS__); \
} while (0)
#endif

#ifdef __cplusplus
}
#endif

#endif /* AODVV2_DEBUG_H_*/
36 changes: 19 additions & 17 deletions sys/net/routing/aodvv2/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
#define ENABLE_DEBUG (0)
#include "debug.h"

#ifdef DEBUG
#define ENABLE_AODV_DEBUG (1)
#include "aodv_debug.h"
#endif

#define VERBOSE_DEBUG (0)
#if VERBOSE_DEBUG
#define VDEBUG(...) printf(__VA_ARGS__)
#undef VERBOSE_DEBUG
#else
#define VDEBUG(...)
#define VDEBUG(...) AODV_DEBUG(__VA_ARGS__)
#endif

static enum rfc5444_result _cb_rreq_blocktlv_addresstlvs_okay(
Expand Down Expand Up @@ -167,7 +169,7 @@ static struct rfc5444_reader_tlvblock_consumer_entry _rerr_address_consumer_entr
*/
static enum rfc5444_result _cb_rreq_blocktlv_messagetlvs_okay(struct rfc5444_reader_tlvblock_context *cont)
{
VDEBUG("[aodvv2] %s()\n", __func__);
VDEBUG("%s()\n", __func__);

if (!cont->has_hoplimit) {
DEBUG("\tERROR: missing hop limit\n");
Expand Down Expand Up @@ -198,7 +200,7 @@ static enum rfc5444_result _cb_rreq_blocktlv_addresstlvs_okay(struct rfc5444_rea
bool is_origNode_addr = false;
bool is_targNode_addr = false;

VDEBUG("[aodvv2] %s()\n", __func__);
VDEBUG("%s()\n", __func__);
DEBUG("\taddr: %s\n", netaddr_to_string(&nbuf, &cont->addr));

/* handle OrigNode SeqNum TLV */
Expand Down Expand Up @@ -366,14 +368,14 @@ static enum rfc5444_result _cb_rreq_end_callback(
* processing continues as follows.
*/
if (clienttable_is_client(&packet_data.targNode.addr)) {
DEBUG("[aodvv2] TargNode is in client list, sending RREP\n");
AODV_DEBUG("TargNode is in client list, sending RREP\n");

/* make sure to start with a clean metric value */
packet_data.targNode.metric = 0;
aodv_send_rrep(&packet_data, &packet_data.sender);
}
else {
DEBUG("[aodvv2] I am not TargNode, forwarding RREQ\n");
AODV_DEBUG("I am not TargNode, forwarding RREQ\n");
aodv_send_rreq(&packet_data);
}
return RFC5444_OKAY;
Expand All @@ -387,7 +389,7 @@ static enum rfc5444_result _cb_rreq_end_callback(
*/
static enum rfc5444_result _cb_rrep_blocktlv_messagetlvs_okay(struct rfc5444_reader_tlvblock_context *cont)
{
VDEBUG("[aodvv2] %s()\n", __func__);
VDEBUG("%s()\n", __func__);

if (!cont->has_hoplimit) {
VDEBUG("\tERROR: missing hop limit\n");
Expand Down Expand Up @@ -418,7 +420,7 @@ static enum rfc5444_result _cb_rrep_blocktlv_addresstlvs_okay(struct rfc5444_rea
struct rfc5444_reader_tlvblock_entry *tlv;
bool is_targNode_addr = false;

VDEBUG("[aodvv2] %s()\n", __func__);
VDEBUG("%s()\n", __func__);
VDEBUG("\taddr: %s\n", netaddr_to_string(&nbuf, &cont->addr));

/* handle TargNode SeqNum TLV */
Expand Down Expand Up @@ -477,7 +479,7 @@ static enum rfc5444_result _cb_rrep_end_callback(
{
(void) cont;

VDEBUG("[aodvv2] %s()\n", __func__);
VDEBUG("%s()\n", __func__);

struct aodvv2_routing_entry_t *rt_entry;
#ifdef DEBUG
Expand Down Expand Up @@ -576,7 +578,7 @@ static enum rfc5444_result _cb_rrep_end_callback(
/* If HandlingRtr is not RREQ_Gen then the outgoing RREP is sent to the
* Route.NextHopAddress for the RREP.AddrBlk[OrigNodeNdx]. */
else {
DEBUG("[aodvv2] Not my RREP, passing it on to the next hop\n");
AODV_DEBUG("Not my RREP, passing it on to the next hop\n");
aodv_send_rrep(&packet_data,
routingtable_get_next_hop(&packet_data.origNode.addr,packet_data.metricType));
}
Expand All @@ -585,7 +587,7 @@ static enum rfc5444_result _cb_rrep_end_callback(

static enum rfc5444_result _cb_rerr_blocktlv_messagetlvs_okay(struct rfc5444_reader_tlvblock_context *cont)
{
VDEBUG("[aodvv2] %s()\n", __func__);
VDEBUG("%s()\n", __func__);

if (!cont->has_hoplimit) {
VDEBUG("\tERROR: missing hop limit\n");
Expand Down Expand Up @@ -616,7 +618,7 @@ static enum rfc5444_result _cb_rerr_blocktlv_addresstlvs_okay(struct rfc5444_rea
struct aodvv2_routing_entry_t *unreachable_entry;
struct rfc5444_reader_tlvblock_entry *tlv;

VDEBUG("[aodvv2] %s()\n", __func__);
VDEBUG("%s()\n", __func__);
VDEBUG("\tmessage type: %d\n", cont->type);
VDEBUG("\taddr: %s\n", netaddr_to_string(&nbuf, &cont->addr));

Expand Down Expand Up @@ -675,7 +677,7 @@ static enum rfc5444_result _cb_rerr_end_callback(struct rfc5444_reader_tlvblock_

void reader_init(void)
{
VDEBUG("[aodvv2] %s()\n", __func__);
VDEBUG("%s()\n", __func__);

/* initialize reader */
rfc5444_reader_init(&reader);
Expand Down Expand Up @@ -703,13 +705,13 @@ void reader_init(void)

void reader_cleanup(void)
{
VDEBUG("[aodvv2] %s()\n", __func__);
VDEBUG("%s()\n", __func__);
rfc5444_reader_cleanup(&reader);
}

int reader_handle_packet(void *buffer, size_t length, struct netaddr *sender)
{
DEBUG("[aodvv2] %s()\n", __func__);
AODV_DEBUG("%s()\n", __func__);
memcpy(&packet_data.sender, sender, sizeof(*sender));
DEBUG("\t sender: %s\n", netaddr_to_string(&nbuf, &packet_data.sender));

Expand Down
7 changes: 6 additions & 1 deletion sys/net/routing/aodvv2/routingtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#define ENABLE_DEBUG (0)
#include "debug.h"

#ifdef DEBUG
#define ENABLE_AODV_DEBUG (1)
#include "aodv_debug.h"
#endif

/* helper functions */
static void _reset_entry_if_stale(uint8_t i);

Expand All @@ -43,7 +48,7 @@ void routingtable_init(void)
for (unsigned i = 0; i < AODVV2_MAX_ROUTING_ENTRIES; i++) {
memset(&routing_table[i], 0, sizeof(routing_table[i]));
}
DEBUG("[aodvv2] routing table initialized.\n");
AODV_DEBUG("routing table initialized.\n");
}

struct netaddr *routingtable_get_next_hop(struct netaddr *dest, aodvv2_metric_t metricType)
Expand Down
Loading

0 comments on commit ae33b42

Please sign in to comment.