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