/* $Id: mcl_debug.cpp,v 1.3 2003/10/27 09:55:48 roca Exp $ */ /* * Copyright (c) 2003 INRIA - All rights reserved * (main author: Vincent Roca - vincent.roca@inrialpes.fr) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ #ifdef ALC #include "../alc/mcl_includes.h" #elif defined(NORM) #include "../norm/mcl_includes.h" extern void mcl_exit (int n); #endif // ALC|NORM #ifdef DEBUG /* * Called only when an ASSERT failes. Usefull to set up a breakpoint. */ void mcl_assert (void) { mcl_exit(-1); } /* * Call it when you want to easily setup a breakpoint somewhere in code. */ void mcl_break (void) { return; } #endif /* DEBUG */ /** * Dump a data buffer. * @param len total length of the buffer * @param to_dump number of UINT32 words to dump */ void mcl_dump_buffer (char *buf, int len, int to_dump) /* number of u32 words to dump */ { int i, j; int *ptr; #ifndef min #define min(a,b) ((a) <= (b) ? (a) : (b)) #endif i = min(to_dump, (len >> 2)); j = 0; PRINT_OUT((mcl_stdout, "\tDUMP %d first bytes...\n\t", i * sizeof(int))) for (ptr = (int*)buf; i > 0; i--, ptr++) { /* convert to big endian format to be sure of byte order */ PRINT_OUT((mcl_stdout, "%08lx ", htonl(*ptr))) if (++j == 8) { j = 0; PRINT_OUT((mcl_stdout, "\n\t")) } } PRINT_OUT((mcl_stdout, "\n")) } /** * Dump a data buffer containing ascii content. * @param to_dump number of bytes to dump */ void mcl_dump_ascii_buffer (char *buf, int to_dump) /* number of bytes to dump */ { int i, j; char *ptr; #ifndef min #define min(a,b) ((a) <= (b) ? (a) : (b)) #endif i = to_dump; j = 0; PRINT_OUT((mcl_stdout, "\tDUMP %d first bytes...\n---START-----\n\t", i * sizeof(int))) for (ptr = buf; i > 0; i--, ptr++) { /* convert to big endian format to be sure of byte order */ PRINT_OUT((mcl_stdout, "%c", *ptr)) if (++j == 40) { j = 0; PRINT_OUT((mcl_stdout, "\n\t")) } } PRINT_OUT((mcl_stdout, "\n---END-------\n")) } #ifdef ALC /* * print packets in an easily understandable format */ void PrintRcvdDU (mclcb_t *mclcb, int type, /* 0 (data) or EH_SIG */ int val, /* sub-type or layer */ hdr_infos_t *hdr_infos) { static int prev_level=-1; /* for verbose mode only */ ASSERT(EH_SIG > 0); /* to avoid confusion ! */ if (type == EH_SIG && val == SIG_NONEWADU) { PRINT_OUT((mcl_stdout, "No New ADU (seq: %d to %d)\n", mcl_iss, hdr_infos->max_idf_adu)) } else if (type == EH_SIG && val == SIG_CLOSE) { PRINT_OUT((mcl_stdout, "\nClose\n")) } else { ASSERT(type != EH_SIG); if (mclcb->verbose == 1) { /* * produce traces for standard compact analysis */ if (val == 0) { PRINT_OUT((mcl_stdout, "\n\t")) } if (val != prev_level && val > 0) { PRINT_OUT((mcl_stdout, "\t\t")) } prev_level = val; if (hdr_infos->is_fec) { PRINT_OUT((mcl_stdout, "((%d/%d/%d)) ", hdr_infos->idf_adu, hdr_infos->idf_block, hdr_infos->idf_du)) } else { PRINT_OUT((mcl_stdout, "[%d/%d/%d] ", hdr_infos->idf_adu, hdr_infos->idf_block, hdr_infos->idf_du)) } } else if (mclcb->verbose == 2) { /* * produce traces for timely analysis */ struct timeval time; time = mcl_get_tvtime(); PRINT_OUT((mcl_stdout, "\n%ld.%06ld\tpkt_rcvd lay=%d aseq=%d bseq=%d dseq=%d %s\n", time.tv_sec, time.tv_usec, val, hdr_infos->idf_adu, hdr_infos->idf_block, hdr_infos->idf_du, (hdr_infos->is_fec ? "fec" : "data"))) } else { /* * produce traces for detailed analysis */ PRINT_OUT((mcl_stdout, "pkt on lay=%d time=%d aseq=%d/bseq=%d/dseq=%d/%s\n", val, mcl_time_count, hdr_infos->idf_adu, hdr_infos->idf_block, hdr_infos->idf_du, (hdr_infos->is_fec ? "fec" : "data"))) } } } /* * print packets in an easily understandable format */ void PrintSentDU (mclcb_t *mclcb, int type, /* 0 (data) or EH_SIG */ int val, /* sub-type or layer */ hdr_infos_t *hdr_infos) { if (type > 0) { return; } if (mclcb->verbose == 2) { /* * produce traces for timely analysis */ struct timeval time; time = mcl_get_tvtime(); PRINT_OUT((mcl_stdout, "\n%ld.%06ld\tpkt_sent lay=%d aseq=%d bseq=%d dseq=%d %s\n", time.tv_sec, time.tv_usec, val, hdr_infos->idf_adu, hdr_infos->idf_block, hdr_infos->idf_du, (hdr_infos->is_fec ? "fec" : "data"))) } else if (mclcb->verbose >= 3) { PRINT_OUT((mcl_stdout, "pkt on lay=%d time=%d aseq=%d/bseq=%d/dseq=%d/%s\n", val, mcl_time_count, hdr_infos->idf_adu, hdr_infos->idf_block, hdr_infos->idf_du, (hdr_infos->is_fec ? "fec" : "data"))) } } #elif defined(NORM) /* * print packets in an easily understandable format */ void mcl_print_sent_du (mcl_cb *const mclcb, //common_norm_hdr_t *hdr, mcl_du *const du) { if (!du) { PRINT_OUT((mcl_stdout, "CMD pkt time=%d\n", mcl_time_count)) return; } if (mclcb->get_verbosity() == 2) { /* * produce traces for timely analysis */ struct timeval time; time = mcl_get_tvtime(); PRINT_OUT((mcl_stdout, "\n%ld.%06ld\tpkt_sent aseq=%d bseq=%d dseq=%d %s\n", time.tv_sec, time.tv_usec, du->block->adu->get_seq(), du->block->seq, du->seq, (du->is_fec ? "fec" : "data"))) } else if (mclcb->get_verbosity() >= 3) { PRINT_OUT((mcl_stdout, "pkt time=%d aseq=%d/bseq=%d/dseq=%d/%s\n", mcl_time_count, du->block->adu->get_seq(), du->block->seq, du->seq, (du->is_fec ? "fec" : "data"))) } } void mcl_print_recvd_du (mcl_cb *const mclcb, bool is_data, UINT32 val, // add info, eg NEW_ADU, CLOSE mcl_data_hdr_infos_t *dhdr_infos) { if (mclcb->get_verbosity() <= 0) return; if (is_data) { switch (mclcb->get_verbosity()) { case 1: /* * produce traces for standard compact analysis */ PRINT_OUT((mcl_stdout, "\t%s %d/%d/%d\n", (dhdr_infos->is_fec ? "fec " : "data"), dhdr_infos->idf_adu, dhdr_infos->idf_block, dhdr_infos->idf_du)) break; case 2: /* * produce traces for timely analysis */ struct timeval time; time = mcl_get_tvtime(); PRINT_OUT((mcl_stdout, "\n%ld.%06ld\tpkt_rcvd aseq=%d bseq=%d dseq=%d %s\n", time.tv_sec, time.tv_usec, dhdr_infos->idf_adu, dhdr_infos->idf_block, dhdr_infos->idf_du, (dhdr_infos->is_fec ? "fec" : "data"))) break; default: /* * produce traces for detailed analysis */ PRINT_OUT((mcl_stdout, "pkt time=%d aseq=%d/bseq=%d/dseq=%d/%s\n", mcl_time_count, dhdr_infos->idf_adu, dhdr_infos->idf_block, dhdr_infos->idf_du, (dhdr_infos->is_fec ? "fec" : "data"))) break; } } else if (val == MCL_SIG_NEWADU) { PRINT_OUT((mcl_stdout, "New ADU (%d: %d bytes, %d blocks)\n", dhdr_infos->idf_adu, dhdr_infos->adu_len, (int)ceil((double)dhdr_infos->adu_len / (double)dhdr_infos->block_len))) } else if (val == MCL_SIG_NONEWADU) { PRINT_OUT((mcl_stdout, "No New ADU (seq: %d to ?)\n", mcl_iss)) //PRINT_OUT((mcl_stdout, "No New ADU (seq: %d to %d)\n", // mcl_iss, dhdr_infos->max_idf_adu)) } else if (val == MCL_SIG_CLOSE) { PRINT_OUT((mcl_stdout, "\nClose\n")) } } #endif // ALC || NORM