Change default for "Welcome screen and title bar shows version" to on per
[obnox/wireshark/wip.git] / tap-megaco-common.c
1 /* megaco_stat.c
2  * megaco-statistics for Wireshark
3  * Copyright 2003 Lars Roland
4  * Copyright 2008 Ericsson AB
5  * By Balint Reczey <balint.reczey@ericsson.com>
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
34 #endif
35
36 #include <string.h>
37
38 #include <epan/packet_info.h>
39 #include <epan/epan.h>
40 #include <epan/value_string.h>
41 #include <epan/tap.h>
42 #include "epan/gcp.h"
43
44 #include "../timestats.h"
45 #include "../simple_dialog.h"
46 #include "../file.h"
47 #include "../globals.h"
48 #include "../stat_menu.h"
49
50 #include "tap-megaco-common.h"
51
52 static gboolean
53 megacostat_is_duplicate_reply(const gcp_cmd_t* cmd)
54 {
55         switch (cmd->type) {
56
57         GCP_CMD_REPLY_CASE
58                 {
59                         gcp_cmd_msg_t *cmd_msg;
60                         /* cycle through commands to find same command in the transaction */
61                         for (cmd_msg = cmd->trx->cmds; cmd_msg->cmd->msg->framenum != cmd->msg->framenum &&
62                                         cmd_msg != NULL; cmd_msg = cmd_msg->next) {
63                                 if (cmd_msg->cmd->type == cmd->type)
64                                         return TRUE;
65                         }
66
67                         return FALSE;
68                 }
69                 break;
70         default:
71                 return FALSE;
72                 break;
73         }
74
75
76 }
77
78 static gboolean
79 megacostat_had_request(const gcp_cmd_t* cmd)
80 {
81         switch (cmd->type) {
82
83         GCP_CMD_REPLY_CASE
84                 {
85                         gcp_cmd_msg_t *cmd_msg;
86                         /* cycle through commands to find a request in the transaction */
87                         for (cmd_msg = cmd->trx->cmds; cmd_msg->cmd->msg->framenum != cmd->msg->framenum &&
88                                         cmd_msg != NULL; cmd_msg = cmd_msg->next) {
89
90                                 switch (cmd_msg->cmd->type) {
91
92                                 GCP_CMD_REQ_CASE
93                                         return TRUE;
94                                         break;
95                                 default:
96                                         return FALSE;
97                                         break;
98                                 }
99                         }
100
101                         return FALSE;
102                 }
103                 break;
104         default:
105                 return FALSE;
106                 break;
107         }
108 }
109
110 int
111 megacostat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pmi)
112 {
113         megacostat_t *ms=(megacostat_t *)pms;
114         const gcp_cmd_t *mi=(const gcp_cmd_t*)pmi;
115         nstime_t delta;
116         int ret = 0;
117
118         switch (mi->type) {
119
120         GCP_CMD_REQ_CASE
121                 if(!mi->trx->initial) {
122                         /* Track Context is probably disabled, we cannot
123                          * measure service response time */
124                         return 0;
125                 }
126
127                 else if(mi->trx->initial->framenum != mi->msg->framenum){
128                         /* Duplicate is ignored */
129                         ms->req_dup_num++;
130                 }
131                 else {
132                         ms->open_req_num++;
133                 }
134                 break;
135
136         GCP_CMD_REPLY_CASE
137                 if(megacostat_is_duplicate_reply(mi)){
138                         /* Duplicate is ignored */
139                         ms->rsp_dup_num++;
140                 }
141                 else if (!megacostat_had_request(mi)) {
142                         /* no request was seen */
143                         ms->disc_rsp_num++;
144                 }
145                 else {
146                         ms->open_req_num--;
147                         /* calculate time delta between request and response */
148                         nstime_delta(&delta, &pinfo->fd->abs_ts, &mi->trx->initial->time);
149
150                         switch(mi->type) {
151
152                         case GCP_CMD_ADD_REPLY:
153                                 time_stat_update(&(ms->rtd[0]),&delta, pinfo);
154                                 break;
155                         case GCP_CMD_MOVE_REPLY:
156                                 time_stat_update(&(ms->rtd[1]),&delta, pinfo);
157                                 break;
158                         case GCP_CMD_MOD_REPLY:
159                                 time_stat_update(&(ms->rtd[2]),&delta, pinfo);
160                                 break;
161                         case GCP_CMD_SUB_REPLY:
162                                 time_stat_update(&(ms->rtd[3]),&delta, pinfo);
163                                 break;
164                         case GCP_CMD_AUDITCAP_REPLY:
165                                 time_stat_update(&(ms->rtd[4]),&delta, pinfo);
166                                 break;
167                         case GCP_CMD_AUDITVAL_REPLY:
168                                 time_stat_update(&(ms->rtd[5]),&delta, pinfo);
169                                 break;
170                         case GCP_CMD_NOTIFY_REPLY:
171                                 time_stat_update(&(ms->rtd[6]),&delta, pinfo);
172                                 break;
173                         case GCP_CMD_SVCCHG_REPLY:
174                                 time_stat_update(&(ms->rtd[7]),&delta, pinfo);
175                                 break;
176                         case GCP_CMD_TOPOLOGY_REPLY:
177                                 time_stat_update(&(ms->rtd[8]),&delta, pinfo);
178                                 break;
179                         case GCP_CMD_REPLY:
180                                 time_stat_update(&(ms->rtd[9]),&delta, pinfo);
181                                 break;
182                         default:
183                                 time_stat_update(&(ms->rtd[11]),&delta, pinfo);
184                         }
185                         time_stat_update(&(ms->rtd[10]),&delta, pinfo);
186
187                         ret = 1;
188                 }
189                 break;
190
191         default:
192                 break;
193         }
194
195         return ret;
196 }
197