From d00abddee35f53ff8e74fed74a7be44523d6553c Mon Sep 17 00:00:00 2001 From: James Golovich Date: Mon, 15 Mar 2004 05:53:25 +0000 Subject: [PATCH] Add pri_dump_info and q921/q931 counters to libpri git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@78 2fbb986a-6c06-0410-b554-c9c1f0a7f128 --- Makefile | 5 ++++- libpri.h | 4 ++++ pri.c | 38 ++++++++++++++++++++++++++++++++++++++ pri_internal.h | 8 ++++++++ q921.c | 7 ++++++- q931.c | 6 ++++++ 6 files changed, 66 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d64bd9f..7ca3309 100755 --- a/Makefile +++ b/Makefile @@ -24,12 +24,15 @@ # Uncomment if you want libpri not send PROGRESS_INDICATOR w/ALERTING #ALERTING=-DALERTING_NO_PROGRESS +# Uncomment if you want libpri to count number of Q921/Q931 sent/received +#LIBPRI_COUNTERS=-DLIBPRI_COUNTERS + TOBJS=testpri.o STATIC_LIBRARY=libpri.a DYNAMIC_LIBRARY=libpri.so.1.0 STATIC_OBJS=pri.o q921.o prisched.o q931.o DYNAMIC_OBJS=pri.lo q921.lo prisched.lo q931.lo -CFLAGS=-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g $(ALERTING) +CFLAGS=-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g $(ALERTING) $(LIBPRI_COUNTERS) INSTALL_PREFIX= all: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY) diff --git a/libpri.h b/libpri.h index 9635268..276cc47 100755 --- a/libpri.h +++ b/libpri.h @@ -386,4 +386,8 @@ extern void pri_set_error(void (*__pri_error)(char *)); /* Set overlap mode */ #define PRI_SET_OVERLAPDIAL extern void pri_set_overlapdial(struct pri *pri,int state); + +#define PRI_DUMP_INFO +extern void pri_dump_info(struct pri *pri); + #endif diff --git a/pri.c b/pri.c index a0aea90..12812be 100755 --- a/pri.c +++ b/pri.c @@ -66,6 +66,12 @@ struct pri *pri_new(int fd, int node, int switchtype) p->localtype = node; p->switchtype = switchtype; p->cref = 1; +#ifdef LIBPRI_COUNTERS + p->q921_rxcount = 0; + p->q921_txcount = 0; + p->q931_rxcount = 0; + p->q931_txcount = 0; +#endif /* Start Q.921 layer */ q921_start(p, 1); } @@ -332,3 +338,35 @@ void pri_set_overlapdial(struct pri *pri,int state) pri->overlapdial = state; } +void pri_dump_info(struct pri *pri) +{ +#ifdef LIBPRI_COUNTERS + struct q921_frame *f; + int q921outstanding = 0; +#endif + if (!pri) + return; + + /* Might be nice to format these a little better */ + pri_message("Switchtype: %s\n", pri_switch2str(pri->switchtype)); + pri_message("Type: %s\n", pri_node2str(pri->localtype)); +#ifdef LIBPRI_COUNTERS + /* Remember that Q921 Counters include Q931 packets (and any retransmissions) */ + pri_message("Q931 RX: %d\n", pri->q931_rxcount); + pri_message("Q931 TX: %d\n", pri->q931_txcount); + pri_message("Q921 RX: %d\n", pri->q921_rxcount); + pri_message("Q921 TX: %d\n", pri->q921_txcount); + f = pri->txqueue; + while (f) { + q921outstanding++; + f = f->next; + } + pri_message("Q921 Outstanding: %d\n", q921outstanding); +#endif + pri_message("Sentrej: %d\n", pri->sentrej); + pri_message("SolicitFbit: %d\n", pri->solicitfbit); + pri_message("Retrans: %d\n", pri->retrans); + pri_message("Busy: %d\n", pri->busy); + pri_message("Overlap Dial: %d\n", pri->overlapdial); +} + diff --git a/pri_internal.h b/pri_internal.h index f394bd9..3d34680 100755 --- a/pri_internal.h +++ b/pri_internal.h @@ -82,6 +82,14 @@ struct pri { /* do we do overlap dialing */ int overlapdial; + +#ifdef LIBPRI_COUNTERS + /* q921/q931 packet counters */ + unsigned int q921_txcount; + unsigned int q921_rxcount; + unsigned int q931_txcount; + unsigned int q931_rxcount; +#endif }; extern int pri_schedule_event(struct pri *pri, int ms, void (*function)(void *data), void *data); diff --git a/q921.c b/q921.c index 82fbe74..456faf3 100755 --- a/q921.c +++ b/q921.c @@ -73,7 +73,9 @@ static int q921_transmit(struct pri *pri, q921_h *h, int len) return 0; } #endif - +#ifdef LIBPRI_COUNTERS + pri->q921_txcount++; +#endif /* Just send it raw */ if (pri->debug & PRI_DEBUG_Q921_DUMP) q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 1); @@ -858,6 +860,9 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len) pri_event *e; e = __q921_receive(pri, h, len); reschedule_t203(pri); +#ifdef LIBPRI_COUNTERS + pri->q921_rxcount++; +#endif return e; } diff --git a/q931.c b/q931.c index cccaf42..b94f21c 100755 --- a/q931.c +++ b/q931.c @@ -1476,6 +1476,9 @@ static int q931_xmit(struct pri *pri, q931_h *h, int len, int cr) right order in the log */ if (pri->debug & PRI_DEBUG_Q931_DUMP) q931_dump(h, len, 1); +#ifdef LIBPRI_COUNTERS + pri->q931_txcount++; +#endif return 0; } @@ -1935,6 +1938,9 @@ int q931_receive(struct pri *pri, q931_h *h, int len) int missingmand; if (pri->debug & PRI_DEBUG_Q931_DUMP) q931_dump(h, len, 0); +#ifdef LIBPRI_COUNTERS + pri->q931_rxcount++; +#endif mh = (q931_mh *)(h->contents + h->crlen); if (h->pd == 0x3) { /* This is the weird maintenance stuff. We majorly