aboutsummaryrefslogtreecommitdiffstats
path: root/tap-megaco-common.c
blob: 6bbfc937e31f950fe03e41d9aadbcbacec8aed19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* megaco_stat.c
 * megaco-statistics for Wireshark
 * Copyright 2003 Lars Roland
 * Copyright 2008 Ericsson AB
 * By Balint Reczey <balint.reczey@ericsson.com>
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <string.h>

#include <epan/packet_info.h>
#include <epan/epan.h>
#include <epan/value_string.h>
#include <epan/tap.h>
#include "epan/gcp.h"

#include "../timestats.h"
#include "../file.h"
#include "../globals.h"
#include "../stat_menu.h"

#include "tap-megaco-common.h"

static gboolean
megacostat_is_duplicate_reply(const gcp_cmd_t* cmd)
{
	switch (cmd->type) {

        GCP_CMD_REPLY_CASE
		{
			gcp_cmd_msg_t *cmd_msg;
			/* cycle through commands to find same command in the transaction */
			for (cmd_msg = cmd->trx->cmds;
			     (cmd_msg != NULL) && (cmd_msg->cmd->msg->framenum != cmd->msg->framenum);
			     cmd_msg = cmd_msg->next) {
				if (cmd_msg->cmd->type == cmd->type)
					return TRUE;
			}

			return FALSE;
		}
		break;
	default:
		return FALSE;
		break;
	}


}

static gboolean
megacostat_had_request(const gcp_cmd_t* cmd)
{
	switch (cmd->type) {

        GCP_CMD_REPLY_CASE
		{
			gcp_cmd_msg_t *cmd_msg;
			/* cycle through commands to find a request in the transaction */
			for (cmd_msg = cmd->trx->cmds;
			     (cmd_msg != NULL) && (cmd_msg->cmd->msg->framenum != cmd->msg->framenum);
			     cmd_msg = cmd_msg->next) {

				switch (cmd_msg->cmd->type) {

        			GCP_CMD_REQ_CASE
					return TRUE;
					break;
				default:
					return FALSE;
					break;
				}
			}

			return FALSE;
		}
		break;
	default:
		return FALSE;
		break;
	}
}

int
megacostat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pmi)
{
	megacostat_t *ms=(megacostat_t *)pms;
	const gcp_cmd_t *mi=(const gcp_cmd_t*)pmi;
	nstime_t delta;
	int ret = 0;

	switch (mi->type) {

        GCP_CMD_REQ_CASE
		if(!mi->trx->initial) {
			/* Track Context is probably disabled, we cannot
			 * measure service response time */
			return 0;
		}

		else if(mi->trx->initial->framenum != mi->msg->framenum){
			/* Duplicate is ignored */
			ms->req_dup_num++;
		}
		else {
			ms->open_req_num++;
		}
		break;

        GCP_CMD_REPLY_CASE
		if(megacostat_is_duplicate_reply(mi)){
			/* Duplicate is ignored */
			ms->rsp_dup_num++;
		}
		else if (!megacostat_had_request(mi)) {
			/* no request was seen */
			ms->disc_rsp_num++;
		}
		else {
			ms->open_req_num--;
			/* calculate time delta between request and response */
			nstime_delta(&delta, &pinfo->fd->abs_ts, &mi->trx->initial->time);

			switch(mi->type) {

			case GCP_CMD_ADD_REPLY:
				time_stat_update(&(ms->rtd[0]),&delta, pinfo);
				break;
			case GCP_CMD_MOVE_REPLY:
				time_stat_update(&(ms->rtd[1]),&delta, pinfo);
				break;
			case GCP_CMD_MOD_REPLY:
				time_stat_update(&(ms->rtd[2]),&delta, pinfo);
				break;
			case GCP_CMD_SUB_REPLY:
				time_stat_update(&(ms->rtd[3]),&delta, pinfo);
				break;
			case GCP_CMD_AUDITCAP_REPLY:
				time_stat_update(&(ms->rtd[4]),&delta, pinfo);
				break;
			case GCP_CMD_AUDITVAL_REPLY:
				time_stat_update(&(ms->rtd[5]),&delta, pinfo);
				break;
			case GCP_CMD_NOTIFY_REPLY:
				time_stat_update(&(ms->rtd[6]),&delta, pinfo);
				break;
			case GCP_CMD_SVCCHG_REPLY:
				time_stat_update(&(ms->rtd[7]),&delta, pinfo);
				break;
			case GCP_CMD_TOPOLOGY_REPLY:
				time_stat_update(&(ms->rtd[8]),&delta, pinfo);
				break;
			case GCP_CMD_REPLY:
				time_stat_update(&(ms->rtd[9]),&delta, pinfo);
				break;
			default:
				time_stat_update(&(ms->rtd[11]),&delta, pinfo);
			}
			time_stat_update(&(ms->rtd[10]),&delta, pinfo);

			ret = 1;
		}
		break;

	default:
		break;
	}

	return ret;
}