White space changes.
[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 "../file.h"
46 #include "../globals.h"
47 #include "../stat_menu.h"
48
49 #include "tap-megaco-common.h"
50
51 static gboolean
52 megacostat_is_duplicate_reply(const gcp_cmd_t* cmd)
53 {
54         switch (cmd->type) {
55
56         GCP_CMD_REPLY_CASE
57                 {
58                         gcp_cmd_msg_t *cmd_msg;
59                         /* cycle through commands to find same command in the transaction */
60                         for (cmd_msg = cmd->trx->cmds;
61                              (cmd_msg != NULL) && (cmd_msg->cmd->msg->framenum != cmd->msg->framenum);
62                              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;
88                              (cmd_msg != NULL) && (cmd_msg->cmd->msg->framenum != cmd->msg->framenum);
89                              cmd_msg = cmd_msg->next) {
90
91                                 switch (cmd_msg->cmd->type) {
92
93                                 GCP_CMD_REQ_CASE
94                                         return TRUE;
95                                         break;
96                                 default:
97                                         return FALSE;
98                                         break;
99                                 }
100                         }
101
102                         return FALSE;
103                 }
104                 break;
105         default:
106                 return FALSE;
107                 break;
108         }
109 }
110
111 int
112 megacostat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pmi)
113 {
114         megacostat_t *ms=(megacostat_t *)pms;
115         const gcp_cmd_t *mi=(const gcp_cmd_t*)pmi;
116         nstime_t delta;
117         int ret = 0;
118
119         switch (mi->type) {
120
121         GCP_CMD_REQ_CASE
122                 if(!mi->trx->initial) {
123                         /* Track Context is probably disabled, we cannot
124                          * measure service response time */
125                         return 0;
126                 }
127
128                 else if(mi->trx->initial->framenum != mi->msg->framenum){
129                         /* Duplicate is ignored */
130                         ms->req_dup_num++;
131                 }
132                 else {
133                         ms->open_req_num++;
134                 }
135                 break;
136
137         GCP_CMD_REPLY_CASE
138                 if(megacostat_is_duplicate_reply(mi)){
139                         /* Duplicate is ignored */
140                         ms->rsp_dup_num++;
141                 }
142                 else if (!megacostat_had_request(mi)) {
143                         /* no request was seen */
144                         ms->disc_rsp_num++;
145                 }
146                 else {
147                         ms->open_req_num--;
148                         /* calculate time delta between request and response */
149                         nstime_delta(&delta, &pinfo->fd->abs_ts, &mi->trx->initial->time);
150
151                         switch(mi->type) {
152
153                         case GCP_CMD_ADD_REPLY:
154                                 time_stat_update(&(ms->rtd[0]),&delta, pinfo);
155                                 break;
156                         case GCP_CMD_MOVE_REPLY:
157                                 time_stat_update(&(ms->rtd[1]),&delta, pinfo);
158                                 break;
159                         case GCP_CMD_MOD_REPLY:
160                                 time_stat_update(&(ms->rtd[2]),&delta, pinfo);
161                                 break;
162                         case GCP_CMD_SUB_REPLY:
163                                 time_stat_update(&(ms->rtd[3]),&delta, pinfo);
164                                 break;
165                         case GCP_CMD_AUDITCAP_REPLY:
166                                 time_stat_update(&(ms->rtd[4]),&delta, pinfo);
167                                 break;
168                         case GCP_CMD_AUDITVAL_REPLY:
169                                 time_stat_update(&(ms->rtd[5]),&delta, pinfo);
170                                 break;
171                         case GCP_CMD_NOTIFY_REPLY:
172                                 time_stat_update(&(ms->rtd[6]),&delta, pinfo);
173                                 break;
174                         case GCP_CMD_SVCCHG_REPLY:
175                                 time_stat_update(&(ms->rtd[7]),&delta, pinfo);
176                                 break;
177                         case GCP_CMD_TOPOLOGY_REPLY:
178                                 time_stat_update(&(ms->rtd[8]),&delta, pinfo);
179                                 break;
180                         case GCP_CMD_REPLY:
181                                 time_stat_update(&(ms->rtd[9]),&delta, pinfo);
182                                 break;
183                         default:
184                                 time_stat_update(&(ms->rtd[11]),&delta, pinfo);
185                         }
186                         time_stat_update(&(ms->rtd[10]),&delta, pinfo);
187
188                         ret = 1;
189                 }
190                 break;
191
192         default:
193                 break;
194         }
195
196         return ret;
197 }
198