LATER... ei_kerberos_kdc_session_key ...
[wireshark-sm.git] / ui / tap-iax2-analysis.c
blobf540565a182c34c23cc5bc4898efd22e2803083a
1 /* tap-iax2-analysis.c
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>
8 * based on tap_rtp.c
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
19 #include "config.h"
21 #include <math.h>
23 #include <glib.h>
25 #include <epan/dissectors/packet-iax2.h>
27 #include "tap-iax2-analysis.h"
29 /****************************************************************************/
30 /* This comes from tap-rtp-common.c */
31 /****************************************************************************/
33 void
34 iax2_packet_analyse(tap_iax2_stat_t *statinfo,
35 packet_info *pinfo,
36 const struct _iax2_info_t *iax2info)
38 double current_time;
39 double current_jitter;
40 double current_diff;
42 statinfo->flags = 0;
43 /* check payload type */
44 if (iax2info->ftype == AST_FRAME_VOICE) {
45 if (iax2info->csub != statinfo->pt) {
46 statinfo->flags |= STAT_FLAG_PT_CHANGE;
48 statinfo->pt = iax2info->csub;
51 /* store the current time and calculate the current jitter */
52 current_time = nstime_to_sec(&pinfo->rel_ts);
53 current_diff = fabs (current_time - statinfo->time - (((double)iax2info->timestamp - (double)statinfo->timestamp)/1000));
54 current_jitter = statinfo->jitter + ( current_diff - statinfo->jitter)/16;
55 statinfo->delta = current_time - (statinfo->time);
56 statinfo->jitter = current_jitter;
57 statinfo->diff = current_diff;
59 /* calculate the BW in Kbps adding the IP+IAX2 header to the RTP -> 20bytes(IP)+ 4bytes(Mini) = 24bytes */
60 statinfo->bw_history[statinfo->bw_index].bytes = iax2info->payload_len + 24;
61 statinfo->bw_history[statinfo->bw_index].time = current_time;
62 /* check if there are more than 1sec in the history buffer to calculate BW in bps. If so, remove those for the calculation */
63 while ((statinfo->bw_history[statinfo->bw_start_index].time+1) < current_time) {
64 statinfo->total_bytes -= statinfo->bw_history[statinfo->bw_start_index].bytes;
65 statinfo->bw_start_index++;
66 if (statinfo->bw_start_index == BUFF_BW) {
67 statinfo->bw_start_index = 0;
70 statinfo->total_bytes += iax2info->payload_len + 24;
71 statinfo->bandwidth = (double)(statinfo->total_bytes*8)/1000;
72 statinfo->bw_index++;
73 if (statinfo->bw_index == BUFF_BW) {
74 statinfo->bw_index = 0;
77 /* is this the first packet we got in this direction? */
78 if (statinfo->first_packet) {
79 statinfo->start_seq_nr = 0;
80 statinfo->start_time = current_time;
81 statinfo->delta = 0;
82 statinfo->jitter = 0;
83 statinfo->diff = 0;
84 statinfo->flags |= STAT_FLAG_FIRST;
85 statinfo->first_packet = false;
87 /* is it a regular packet? */
88 if (!(statinfo->flags & STAT_FLAG_FIRST)
89 && !(statinfo->flags & STAT_FLAG_MARKER)
90 && !(statinfo->flags & STAT_FLAG_PT_CN)
91 && !(statinfo->flags & STAT_FLAG_WRONG_TIMESTAMP)
92 && !(statinfo->flags & STAT_FLAG_FOLLOW_PT_CN)) {
93 /* include it in maximum delta calculation */
94 if (statinfo->delta > statinfo->max_delta) {
95 statinfo->max_delta = statinfo->delta;
96 statinfo->max_nr = pinfo->num;
98 /* maximum and mean jitter calculation */
99 if (statinfo->jitter > statinfo->max_jitter) {
100 statinfo->max_jitter = statinfo->jitter;
102 statinfo->mean_jitter = (statinfo->mean_jitter*statinfo->total_nr + current_jitter) / (statinfo->total_nr+1);
104 /* regular payload change? (CN ignored) */
105 if (!(statinfo->flags & STAT_FLAG_FIRST)
106 && !(statinfo->flags & STAT_FLAG_PT_CN)) {
107 if ((statinfo->pt != statinfo->reg_pt)
108 && (statinfo->reg_pt != PT_UNDEFINED)) {
109 statinfo->flags |= STAT_FLAG_REG_PT_CHANGE;
113 /* set regular payload*/
114 if (!(statinfo->flags & STAT_FLAG_PT_CN)) {
115 statinfo->reg_pt = statinfo->pt;
118 /* TODO: lost packets / duplicated: we should infer this from timestamp... */
119 statinfo->time = current_time;
120 statinfo->timestamp = iax2info->timestamp; /* millisecs */
121 statinfo->stop_seq_nr = 0;
122 statinfo->total_nr++;
124 return;