2 * mgcpstat 2003 Lars Roland
4 * $Id: tap-mgcpstat.c,v 1.3 2003/03/12 00:36:22 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
36 #include "epan/packet_info.h"
38 #include "epan/value_string.h"
40 #include "plugins/mgcp/packet-mgcp.h"
43 /* Summary of response-time calculations*/
44 typedef struct _rtd_t {
51 /* used to keep track of the statistics for an entire program interface */
52 typedef struct _mgcpstat_t {
55 long int open_req_num;
56 long int disc_rsp_num;
61 /* A Function to update a mgcp_rtd_t struct */
64 rtd_stat_update(rtd_t *rtd,nstime_t delta)
68 && (rtd->max.nsecs==0) ){
69 rtd->max.secs=delta.secs;
70 rtd->max.nsecs=delta.nsecs;
74 && (rtd->min.nsecs==0) ){
75 rtd->min.secs=delta.secs;
76 rtd->min.nsecs=delta.nsecs;
79 if( (delta.secs<rtd->min.secs)
80 ||( (delta.secs==rtd->min.secs)
81 &&(delta.nsecs<rtd->min.nsecs) ) ){
82 rtd->min.secs=delta.secs;
83 rtd->min.nsecs=delta.nsecs;
86 if( (delta.secs>rtd->max.secs)
87 ||( (delta.secs==rtd->max.secs)
88 &&(delta.nsecs>rtd->max.nsecs) ) ){
89 rtd->max.secs=delta.secs;
90 rtd->max.nsecs=delta.nsecs;
93 rtd->tot.secs += delta.secs;
94 rtd->tot.nsecs += delta.nsecs;
95 if(rtd->tot.nsecs>1000000000){
96 rtd->tot.nsecs-=1000000000;
104 mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, void *pmi)
106 mgcpstat_t *ms=(mgcpstat_t *)pms;
110 switch (mi->mgcp_type) {
113 if(mi->is_duplicate){
114 /* Duplicate is ignored */
125 if(mi->is_duplicate){
126 /* Duplicate is ignored */
130 else if (!mi->request_available) {
131 /* no request was seen */
137 /* calculate time delta between request and response */
138 delta.secs=pinfo->fd->abs_secs-mi->req_time.secs;
139 delta.nsecs=pinfo->fd->abs_usecs*1000-mi->req_time.nsecs;
141 delta.nsecs+=1000000000;
145 rtd_stat_update(&(ms->rtd),delta);
157 mgcpstat_draw(void *pms)
159 mgcpstat_t *ms=(mgcpstat_t *)pms;
168 /* calculating average rtd */
169 /* scale it to units of 10us.*/
170 /* for long captures with a large tot time, this can overflow on 32bit */
171 avg=(int)ms->rtd.tot.secs;
172 avg=avg*100000+(int)ms->rtd.tot.nsecs/10000;
179 /* printing results */
181 printf("===================================================================\n");
182 printf("MGCP Response Time Delay (RTD) Statistics:\n");
183 printf("Filter: %s\n",ms->filter?ms->filter:"");
184 printf("Duplicate requests: %ld\n",ms->req_dup_num);
185 printf("Duplicate responses: %ld\n",ms->rsp_dup_num);
186 printf("Open requests: %ld\n",ms->open_req_num);
187 printf("Discarded responses: %ld\n",ms->disc_rsp_num);
188 printf("Messages | Min RTD | Max RTD | Avg RTD \n");
189 printf("%7ld | %5d.%03d msec | %5d.%03d msec | %5d.%02d0 msec\n",
191 (int)((ms->rtd.min.secs*1000)+(ms->rtd.min.nsecs/1000000)),(ms->rtd.min.nsecs%1000000)/1000,
192 (int)((ms->rtd.max.secs*1000)+(ms->rtd.max.nsecs/1000000)),(ms->rtd.max.nsecs%1000000)/1000,
195 printf("===================================================================\n");
200 mgcpstat_init(char *optarg)
206 if(!strncmp(optarg,"mgcp,rtd,",9)){
212 ms=g_malloc(sizeof(mgcpstat_t));
214 ms->filter=g_malloc(strlen(filter)+1);
215 strcpy(ms->filter, filter);
233 if(register_tap_listener("mgcp", ms, filter, NULL, mgcpstat_packet, mgcpstat_draw)){
234 /* error, we failed to attach to the tap. clean up */
238 fprintf(stderr,"tethereal: mgcpstat_init() failed to attach to tap.\n");
245 register_tap_listener_mgcpstat(void)
247 register_ethereal_tap("mgcp,rtd", mgcpstat_init, NULL, NULL);