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