The Styleguide section has been moved to the Wireshark Developer's Guide.
[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; cmd_msg->cmd->msg->framenum != cmd->msg->framenum &&
61                                         cmd_msg != NULL; cmd_msg = cmd_msg->next) {
62                                 if (cmd_msg->cmd->type == cmd->type)
63                                         return TRUE;
64                         }
65
66                         return FALSE;
67                 }
68                 break;
69         default:
70                 return FALSE;
71                 break;
72         }
73
74
75 }
76
77 static gboolean
78 megacostat_had_request(const gcp_cmd_t* cmd)
79 {
80         switch (cmd->type) {
81
82         GCP_CMD_REPLY_CASE
83                 {
84                         gcp_cmd_msg_t *cmd_msg;
85                         /* cycle through commands to find a request in the transaction */
86                         for (cmd_msg = cmd->trx->cmds; cmd_msg->cmd->msg->framenum != cmd->msg->framenum &&
87                                         cmd_msg != NULL; cmd_msg = cmd_msg->next) {
88
89                                 switch (cmd_msg->cmd->type) {
90
91                                 GCP_CMD_REQ_CASE
92                                         return TRUE;
93                                         break;
94                                 default:
95                                         return FALSE;
96                                         break;
97                                 }
98                         }
99
100                         return FALSE;
101                 }
102                 break;
103         default:
104                 return FALSE;
105                 break;
106         }
107 }
108
109 int
110 megacostat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pmi)
111 {
112         megacostat_t *ms=(megacostat_t *)pms;
113         const gcp_cmd_t *mi=(const gcp_cmd_t*)pmi;
114         nstime_t delta;
115         int ret = 0;
116
117         switch (mi->type) {
118
119         GCP_CMD_REQ_CASE
120                 if(!mi->trx->initial) {
121                         /* Track Context is probably disabled, we cannot
122                          * measure service response time */
123                         return 0;
124                 }
125
126                 else if(mi->trx->initial->framenum != mi->msg->framenum){
127                         /* Duplicate is ignored */
128                         ms->req_dup_num++;
129                 }
130                 else {
131                         ms->open_req_num++;
132                 }
133                 break;
134
135         GCP_CMD_REPLY_CASE
136                 if(megacostat_is_duplicate_reply(mi)){
137                         /* Duplicate is ignored */
138                         ms->rsp_dup_num++;
139                 }
140                 else if (!megacostat_had_request(mi)) {
141                         /* no request was seen */
142                         ms->disc_rsp_num++;
143                 }
144                 else {
145                         ms->open_req_num--;
146                         /* calculate time delta between request and response */
147                         nstime_delta(&delta, &pinfo->fd->abs_ts, &mi->trx->initial->time);
148
149                         switch(mi->type) {
150
151                         case GCP_CMD_ADD_REPLY:
152                                 time_stat_update(&(ms->rtd[0]),&delta, pinfo);
153                                 break;
154                         case GCP_CMD_MOVE_REPLY:
155                                 time_stat_update(&(ms->rtd[1]),&delta, pinfo);
156                                 break;
157                         case GCP_CMD_MOD_REPLY:
158                                 time_stat_update(&(ms->rtd[2]),&delta, pinfo);
159                                 break;
160                         case GCP_CMD_SUB_REPLY:
161                                 time_stat_update(&(ms->rtd[3]),&delta, pinfo);
162                                 break;
163                         case GCP_CMD_AUDITCAP_REPLY:
164                                 time_stat_update(&(ms->rtd[4]),&delta, pinfo);
165                                 break;
166                         case GCP_CMD_AUDITVAL_REPLY:
167                                 time_stat_update(&(ms->rtd[5]),&delta, pinfo);
168                                 break;
169                         case GCP_CMD_NOTIFY_REPLY:
170                                 time_stat_update(&(ms->rtd[6]),&delta, pinfo);
171                                 break;
172                         case GCP_CMD_SVCCHG_REPLY:
173                                 time_stat_update(&(ms->rtd[7]),&delta, pinfo);
174                                 break;
175                         case GCP_CMD_TOPOLOGY_REPLY:
176                                 time_stat_update(&(ms->rtd[8]),&delta, pinfo);
177                                 break;
178                         case GCP_CMD_REPLY:
179                                 time_stat_update(&(ms->rtd[9]),&delta, pinfo);
180                                 break;
181                         default:
182                                 time_stat_update(&(ms->rtd[11]),&delta, pinfo);
183                         }
184                         time_stat_update(&(ms->rtd[10]),&delta, pinfo);
185
186                         ret = 1;
187                 }
188                 break;
189
190         default:
191                 break;
192         }
193
194         return ret;
195 }
196