nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* tap-iax2-analysis.c |
2 | * IAX2 analysis addition for Wireshark |
||
3 | * |
||
4 | * based on rtp_analysis.c |
||
5 | * Copyright 2003, Alcatel Business Systems |
||
6 | * By Lars Ruoff <lars.ruoff@gmx.net> |
||
7 | * |
||
8 | * based on tap_rtp.c |
||
9 | * Copyright 2003, Iskratel, Ltd, Kranj |
||
10 | * By Miha Jemec <m.jemec@iskratel.si> |
||
11 | * |
||
12 | * Wireshark - Network traffic analyzer |
||
13 | * By Gerald Combs <gerald@wireshark.org> |
||
14 | * Copyright 1998 Gerald Combs |
||
15 | * |
||
16 | * This program is free software; you can redistribute it and/or |
||
17 | * modify it under the terms of the GNU General Public License |
||
18 | * as published by the Free Software Foundation; either version 2 |
||
19 | * of the License, or (at your option) any later version. |
||
20 | * |
||
21 | * This program is distributed in the hope that it will be useful, |
||
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
24 | * GNU General Public License for more details. |
||
25 | * |
||
26 | * You should have received a copy of the GNU General Public License |
||
27 | * along with this program; if not, write to the Free Software |
||
28 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||
29 | */ |
||
30 | |||
31 | #include "config.h" |
||
32 | |||
33 | #include <math.h> |
||
34 | |||
35 | #include <glib.h> |
||
36 | |||
37 | #include <epan/circuit.h> |
||
38 | |||
39 | #include <epan/dissectors/packet-iax2.h> |
||
40 | |||
41 | #include "tap-iax2-analysis.h" |
||
42 | |||
43 | /****************************************************************************/ |
||
44 | /* This comes from tap-rtp-common.c */ |
||
45 | /****************************************************************************/ |
||
46 | |||
47 | void |
||
48 | iax2_packet_analyse(tap_iax2_stat_t *statinfo, |
||
49 | packet_info *pinfo, |
||
50 | const struct _iax2_info_t *iax2info) |
||
51 | { |
||
52 | double current_time; |
||
53 | double current_jitter; |
||
54 | double current_diff; |
||
55 | |||
56 | statinfo->flags = 0; |
||
57 | /* check payload type */ |
||
58 | if (iax2info->ftype == AST_FRAME_VOICE) { |
||
59 | if (iax2info->csub != statinfo->pt) |
||
60 | statinfo->flags |= STAT_FLAG_PT_CHANGE; |
||
61 | statinfo->pt = iax2info->csub; |
||
62 | } |
||
63 | |||
64 | /* store the current time and calculate the current jitter */ |
||
65 | current_time = nstime_to_sec(&pinfo->rel_ts); |
||
66 | current_diff = fabs (current_time - statinfo->time - (((double)iax2info->timestamp - (double)statinfo->timestamp)/1000)); |
||
67 | current_jitter = statinfo->jitter + ( current_diff - statinfo->jitter)/16; |
||
68 | statinfo->delta = current_time - (statinfo->time); |
||
69 | statinfo->jitter = current_jitter; |
||
70 | statinfo->diff = current_diff; |
||
71 | |||
72 | /* calculate the BW in Kbps adding the IP+IAX2 header to the RTP -> 20bytes(IP)+ 4bytes(Mini) = 24bytes */ |
||
73 | statinfo->bw_history[statinfo->bw_index].bytes = iax2info->payload_len + 24; |
||
74 | statinfo->bw_history[statinfo->bw_index].time = current_time; |
||
75 | /* check if there are more than 1sec in the history buffer to calculate BW in bps. If so, remove those for the calculation */ |
||
76 | while ((statinfo->bw_history[statinfo->bw_start_index].time+1) < current_time) { |
||
77 | statinfo->total_bytes -= statinfo->bw_history[statinfo->bw_start_index].bytes; |
||
78 | statinfo->bw_start_index++; |
||
79 | if (statinfo->bw_start_index == BUFF_BW) statinfo->bw_start_index = 0; |
||
80 | }; |
||
81 | statinfo->total_bytes += iax2info->payload_len + 24; |
||
82 | statinfo->bandwidth = (double)(statinfo->total_bytes*8)/1000; |
||
83 | statinfo->bw_index++; |
||
84 | if (statinfo->bw_index == BUFF_BW) statinfo->bw_index = 0; |
||
85 | |||
86 | |||
87 | /* is this the first packet we got in this direction? */ |
||
88 | if (statinfo->first_packet) { |
||
89 | statinfo->start_seq_nr = 0; |
||
90 | statinfo->start_time = current_time; |
||
91 | statinfo->delta = 0; |
||
92 | statinfo->jitter = 0; |
||
93 | statinfo->diff = 0; |
||
94 | statinfo->flags |= STAT_FLAG_FIRST; |
||
95 | statinfo->first_packet = FALSE; |
||
96 | } |
||
97 | /* is it a regular packet? */ |
||
98 | if (!(statinfo->flags & STAT_FLAG_FIRST) |
||
99 | && !(statinfo->flags & STAT_FLAG_MARKER) |
||
100 | && !(statinfo->flags & STAT_FLAG_PT_CN) |
||
101 | && !(statinfo->flags & STAT_FLAG_WRONG_TIMESTAMP) |
||
102 | && !(statinfo->flags & STAT_FLAG_FOLLOW_PT_CN)) { |
||
103 | /* include it in maximum delta calculation */ |
||
104 | if (statinfo->delta > statinfo->max_delta) { |
||
105 | statinfo->max_delta = statinfo->delta; |
||
106 | statinfo->max_nr = pinfo->num; |
||
107 | } |
||
108 | /* maximum and mean jitter calculation */ |
||
109 | if (statinfo->jitter > statinfo->max_jitter) { |
||
110 | statinfo->max_jitter = statinfo->jitter; |
||
111 | } |
||
112 | statinfo->mean_jitter = (statinfo->mean_jitter*statinfo->total_nr + current_diff) / (statinfo->total_nr+1); |
||
113 | } |
||
114 | /* regular payload change? (CN ignored) */ |
||
115 | if (!(statinfo->flags & STAT_FLAG_FIRST) |
||
116 | && !(statinfo->flags & STAT_FLAG_PT_CN)) { |
||
117 | if ((statinfo->pt != statinfo->reg_pt) |
||
118 | && (statinfo->reg_pt != PT_UNDEFINED)) { |
||
119 | statinfo->flags |= STAT_FLAG_REG_PT_CHANGE; |
||
120 | } |
||
121 | } |
||
122 | |||
123 | /* set regular payload*/ |
||
124 | if (!(statinfo->flags & STAT_FLAG_PT_CN)) { |
||
125 | statinfo->reg_pt = statinfo->pt; |
||
126 | } |
||
127 | |||
128 | /* TODO: lost packets / duplicated: we should infer this from timestamp... */ |
||
129 | statinfo->time = current_time; |
||
130 | statinfo->timestamp = iax2info->timestamp; /* millisecs */ |
||
131 | statinfo->stop_seq_nr = 0; |
||
132 | statinfo->total_nr++; |
||
133 | |||
134 | return; |
||
135 | } |
||
136 | |||
137 | /* |
||
138 | * Editor modelines - http://www.wireshark.org/tools/modelines.html |
||
139 | * |
||
140 | * Local variables: |
||
141 | * c-basic-offset: 4 |
||
142 | * tab-width: 8 |
||
143 | * indent-tabs-mode: nil |
||
144 | * End: |
||
145 | * |
||
146 | * vi: set shiftwidth=4 tabstop=8 expandtab: |
||
147 | * :indentSize=4:tabSize=8:noTabs=true: |
||
148 | */ |