2 * mgcpstat 2003 Lars Roland
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"
41 #include "plugins/mgcp/packet-mgcp.h"
42 #include "timestats.h"
44 #define NUM_TIMESTATS 11
46 /* used to keep track of the statistics for an entire program interface */
47 typedef struct _mgcpstat_t {
49 timestat_t rtd[NUM_TIMESTATS];
56 static const value_string mgcp_mesage_type[] = {
70 mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pmi)
72 mgcpstat_t *ms=(mgcpstat_t *)pms;
73 const mgcp_info_t *mi=pmi;
76 switch (mi->mgcp_type) {
80 /* Duplicate is ignored */
92 /* Duplicate is ignored */
96 else if (!mi->request_available) {
97 /* no request was seen */
103 /* calculate time delta between request and response */
104 delta.secs=pinfo->fd->abs_secs-mi->req_time.secs;
105 delta.nsecs=pinfo->fd->abs_usecs*1000-mi->req_time.nsecs;
107 delta.nsecs+=1000000000;
111 time_stat_update(&(ms->rtd[0]),&delta, pinfo);
113 if (strncasecmp(mi->code, "EPCF", 4) == 0 ) {
114 time_stat_update(&(ms->rtd[1]),&delta, pinfo);
116 else if (strncasecmp(mi->code, "CRCX", 4) == 0 ) {
117 time_stat_update(&(ms->rtd[2]),&delta, pinfo);
119 else if (strncasecmp(mi->code, "MDCX", 4) == 0 ) {
120 time_stat_update(&(ms->rtd[3]),&delta, pinfo);
122 else if (strncasecmp(mi->code, "DLCX", 4) == 0 ) {
123 time_stat_update(&(ms->rtd[4]),&delta, pinfo);
125 else if (strncasecmp(mi->code, "RQNT", 4) == 0 ) {
126 time_stat_update(&(ms->rtd[5]),&delta, pinfo);
128 else if (strncasecmp(mi->code, "NTFY", 4) == 0 ) {
129 time_stat_update(&(ms->rtd[6]),&delta, pinfo);
131 else if (strncasecmp(mi->code, "AUEP", 4) == 0 ) {
132 time_stat_update(&(ms->rtd[7]),&delta, pinfo);
134 else if (strncasecmp(mi->code, "AUCX", 4) == 0 ) {
135 time_stat_update(&(ms->rtd[8]),&delta, pinfo);
137 else if (strncasecmp(mi->code, "RSIP", 4) == 0 ) {
138 time_stat_update(&(ms->rtd[9]),&delta, pinfo);
141 time_stat_update(&(ms->rtd[10]),&delta, pinfo);
155 mgcpstat_draw(void *pms)
157 mgcpstat_t *ms=(mgcpstat_t *)pms;
160 /* printing results */
162 printf("=====================================================================================================\n");
163 printf("MGCP Response Time Delay (RTD) Statistics:\n");
164 printf("Filter for statistics: %s\n",ms->filter?ms->filter:"");
165 printf("Duplicate requests: %u\n",ms->req_dup_num);
166 printf("Duplicate responses: %u\n",ms->rsp_dup_num);
167 printf("Open requests: %u\n",ms->open_req_num);
168 printf("Discarded responses: %u\n",ms->disc_rsp_num);
169 printf("Type | Messages | Min RTD | Max RTD | Avg RTD | Min in Frame | Max in Frame |\n");
170 for(i=0;i<NUM_TIMESTATS;i++) {
172 printf("%s | %7u | %8.2f msec | %8.2f msec | %8.2f msec | %10u | %10u |\n",
173 val_to_str(i,mgcp_mesage_type,"Other "),ms->rtd[i].num,
174 nstime_to_msec(&(ms->rtd[i].min)), nstime_to_msec(&(ms->rtd[i].max)),
175 get_average(&(ms->rtd[i].tot), ms->rtd[i].num),
176 ms->rtd[i].min_num, ms->rtd[i].max_num
180 printf("=====================================================================================================\n");
185 mgcpstat_init(const char *optarg)
189 const char *filter=NULL;
190 GString *error_string;
192 if(!strncmp(optarg,"mgcp,rtd,",9)){
198 ms=g_malloc(sizeof(mgcpstat_t));
199 ms->filter=g_malloc(strlen(filter)+1);
200 strcpy(ms->filter, filter);
202 for(i=0;i<NUM_TIMESTATS;i++) {
204 ms->rtd[i].min_num=0;
205 ms->rtd[i].max_num=0;
206 ms->rtd[i].min.secs=0;
207 ms->rtd[i].min.nsecs=0;
208 ms->rtd[i].max.secs=0;
209 ms->rtd[i].max.nsecs=0;
210 ms->rtd[i].tot.secs=0;
211 ms->rtd[i].tot.nsecs=0;
219 error_string=register_tap_listener("mgcp", ms, filter, NULL, mgcpstat_packet, mgcpstat_draw);
221 /* error, we failed to attach to the tap. clean up */
225 fprintf(stderr, "tethereal: Couldn't register mgcp,rtd tap: %s\n",
227 g_string_free(error_string, TRUE);
234 register_tap_listener_mgcpstat(void)
236 /* We don't register this tap, if we don't have the mgcp plugin loaded.*/
237 if (find_tap_id("mgcp")) {
238 register_stat_cmd_arg("mgcp,rtd", mgcpstat_init);