2 * IAX2 analysis addition for Wireshark
4 * based on rtp_analysis.c
5 * Copyright 2003, Alcatel Business Systems
6 * By Lars Ruoff <lars.ruoff@gmx.net>
9 * Copyright 2003, Iskratel, Ltd, Kranj
10 * By Miha Jemec <m.jemec@iskratel.si>
12 * Wireshark - Network traffic analyzer
13 * By Gerald Combs <gerald@wireshark.org>
14 * Copyright 1998 Gerald Combs
16 * SPDX-License-Identifier: GPL-2.0-or-later
25 #include <epan/dissectors/packet-iax2.h>
27 #include "tap-iax2-analysis.h"
29 /****************************************************************************/
30 /* This comes from tap-rtp-common.c */
31 /****************************************************************************/
34 iax2_packet_analyse(tap_iax2_stat_t *statinfo,
36 const struct _iax2_info_t *iax2info)
39 double current_jitter;
43 /* check payload type */
44 if (iax2info->ftype == AST_FRAME_VOICE) {
45 if (iax2info->csub != statinfo->pt)
46 statinfo->flags |= STAT_FLAG_PT_CHANGE;
47 statinfo->pt = iax2info->csub;
50 /* store the current time and calculate the current jitter */
51 current_time = nstime_to_sec(&pinfo->rel_ts);
52 current_diff = fabs (current_time - statinfo->time - (((double)iax2info->timestamp - (double)statinfo->timestamp)/1000));
53 current_jitter = statinfo->jitter + ( current_diff - statinfo->jitter)/16;
54 statinfo->delta = current_time - (statinfo->time);
55 statinfo->jitter = current_jitter;
56 statinfo->diff = current_diff;
58 /* calculate the BW in Kbps adding the IP+IAX2 header to the RTP -> 20bytes(IP)+ 4bytes(Mini) = 24bytes */
59 statinfo->bw_history[statinfo->bw_index].bytes = iax2info->payload_len + 24;
60 statinfo->bw_history[statinfo->bw_index].time = current_time;
61 /* check if there are more than 1sec in the history buffer to calculate BW in bps. If so, remove those for the calculation */
62 while ((statinfo->bw_history[statinfo->bw_start_index].time+1) < current_time) {
63 statinfo->total_bytes -= statinfo->bw_history[statinfo->bw_start_index].bytes;
64 statinfo->bw_start_index++;
65 if (statinfo->bw_start_index == BUFF_BW) statinfo->bw_start_index = 0;
67 statinfo->total_bytes += iax2info->payload_len + 24;
68 statinfo->bandwidth = (double)(statinfo->total_bytes*8)/1000;
70 if (statinfo->bw_index == BUFF_BW) statinfo->bw_index = 0;
73 /* is this the first packet we got in this direction? */
74 if (statinfo->first_packet) {
75 statinfo->start_seq_nr = 0;
76 statinfo->start_time = current_time;
80 statinfo->flags |= STAT_FLAG_FIRST;
81 statinfo->first_packet = FALSE;
83 /* is it a regular packet? */
84 if (!(statinfo->flags & STAT_FLAG_FIRST)
85 && !(statinfo->flags & STAT_FLAG_MARKER)
86 && !(statinfo->flags & STAT_FLAG_PT_CN)
87 && !(statinfo->flags & STAT_FLAG_WRONG_TIMESTAMP)
88 && !(statinfo->flags & STAT_FLAG_FOLLOW_PT_CN)) {
89 /* include it in maximum delta calculation */
90 if (statinfo->delta > statinfo->max_delta) {
91 statinfo->max_delta = statinfo->delta;
92 statinfo->max_nr = pinfo->num;
94 /* maximum and mean jitter calculation */
95 if (statinfo->jitter > statinfo->max_jitter) {
96 statinfo->max_jitter = statinfo->jitter;
98 statinfo->mean_jitter = (statinfo->mean_jitter*statinfo->total_nr + current_diff) / (statinfo->total_nr+1);
100 /* regular payload change? (CN ignored) */
101 if (!(statinfo->flags & STAT_FLAG_FIRST)
102 && !(statinfo->flags & STAT_FLAG_PT_CN)) {
103 if ((statinfo->pt != statinfo->reg_pt)
104 && (statinfo->reg_pt != PT_UNDEFINED)) {
105 statinfo->flags |= STAT_FLAG_REG_PT_CHANGE;
109 /* set regular payload*/
110 if (!(statinfo->flags & STAT_FLAG_PT_CN)) {
111 statinfo->reg_pt = statinfo->pt;
114 /* TODO: lost packets / duplicated: we should infer this from timestamp... */
115 statinfo->time = current_time;
116 statinfo->timestamp = iax2info->timestamp; /* millisecs */
117 statinfo->stop_seq_nr = 0;
118 statinfo->total_nr++;
124 * Editor modelines - http://www.wireshark.org/tools/modelines.html
129 * indent-tabs-mode: nil
132 * vi: set shiftwidth=4 tabstop=8 expandtab:
133 * :indentSize=4:tabSize=8:noTabs=true: