Use ENC_NA as proto_tree_add_item() encoding arg for FT_ETHER hf[] field type.
[obnox/wireshark/wip.git] / tap-h225rassrt.c
1 /* tap_h225rassrt.c
2  * h225 RAS Service Response Time statistics for wireshark
3  * Copyright 2003 Lars Roland
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
34 #endif
35
36 #include <string.h>
37 #include "epan/packet.h"
38 #include "epan/packet_info.h"
39 #include <epan/tap.h>
40 #include <epan/stat_cmd_args.h>
41 #include "epan/value_string.h"
42 #include <epan/dissectors/packet-h225.h>
43 #include "timestats.h"
44
45 /* following values represent the size of their valuestring arrays */
46 #define NUM_RAS_STATS 7
47
48 static const value_string ras_message_category[] = {
49   {  0, "Gatekeeper    "},
50   {  1, "Registration  "},
51   {  2, "UnRegistration"},
52   {  3, "Admission     "},
53   {  4, "Bandwidth     "},
54   {  5, "Disengage     "},
55   {  6, "Location      "},
56   {  0, NULL }
57 };
58
59 typedef enum _ras_type {
60         RAS_REQUEST,
61         RAS_CONFIRM,
62         RAS_REJECT,
63         RAS_OTHER
64 }ras_type;
65
66 typedef enum _ras_category {
67         RAS_GATEKEEPER,
68         RAS_REGISTRATION,
69         RAS_UNREGISTRATION,
70         RAS_ADMISSION,
71         RAS_BANDWIDTH,
72         RAS_DISENGAGE,
73         RAS_LOCATION,
74         RAS_OTHERS
75 }ras_category;
76
77 /* Summary of response-time calculations*/
78 typedef struct _h225_rtd_t {
79         guint32 open_req_num;
80         guint32 disc_rsp_num;
81         guint32 req_dup_num;
82         guint32 rsp_dup_num;
83         timestat_t stats;
84 } h225_rtd_t;
85
86 /* used to keep track of the statistics for an entire program interface */
87 typedef struct _h225rassrt_t {
88         char *filter;
89         h225_rtd_t ras_rtd[NUM_RAS_STATS];
90 } h225rassrt_t;
91
92
93 static void
94 h225rassrt_reset(void *phs)
95 {
96         h225rassrt_t *hs=(h225rassrt_t *)phs;
97         int i;
98
99         for(i=0;i<NUM_RAS_STATS;i++) {
100                 hs->ras_rtd[i].stats.num = 0;
101                 hs->ras_rtd[i].stats.min_num = 0;
102                 hs->ras_rtd[i].stats.max_num = 0;
103                 hs->ras_rtd[i].stats.min.secs = 0;
104                 hs->ras_rtd[i].stats.min.nsecs = 0;
105                 hs->ras_rtd[i].stats.max.secs = 0;
106                 hs->ras_rtd[i].stats.max.nsecs = 0;
107                 hs->ras_rtd[i].stats.tot.secs = 0;
108                 hs->ras_rtd[i].stats.tot.nsecs = 0;
109                 hs->ras_rtd[i].open_req_num = 0;
110                 hs->ras_rtd[i].disc_rsp_num = 0;
111                 hs->ras_rtd[i].req_dup_num = 0;
112                 hs->ras_rtd[i].rsp_dup_num = 0;
113         }
114
115 }
116
117 static int
118 h225rassrt_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *phi)
119 {
120         h225rassrt_t *hs=(h225rassrt_t *)phs;
121         const h225_packet_info *pi=phi;
122
123         ras_type rasmsg_type = RAS_OTHER;
124         ras_category rascategory = RAS_OTHERS;
125
126         if (pi->msg_type != H225_RAS || pi->msg_tag == -1) {
127                 /* No RAS Message or uninitialized msg_tag -> return */
128                 return 0;
129         }
130
131         if (pi->msg_tag < 21) {
132                 /* */
133                 rascategory = pi->msg_tag / 3;
134                 rasmsg_type = pi->msg_tag % 3;
135         }
136         else {
137                 /* No SRT yet (ToDo) */
138                 return 0;
139         }
140
141         switch(rasmsg_type) {
142
143         case RAS_REQUEST:
144                 if(pi->is_duplicate){
145                         hs->ras_rtd[rascategory].req_dup_num++;
146                 }
147                 else {
148                         hs->ras_rtd[rascategory].open_req_num++;
149                 }
150                 break;
151
152         case RAS_CONFIRM:
153                 /* no break - delay calculation is identical for Confirm and Reject  */
154         case RAS_REJECT:
155                 if(pi->is_duplicate){
156                         /* Duplicate is ignored */
157                         hs->ras_rtd[rascategory].rsp_dup_num++;
158                 }
159                 else if (!pi->request_available) {
160                         /* no request was seen, ignore response  */
161                         hs->ras_rtd[rascategory].disc_rsp_num++;
162                 }
163                 else {
164                         hs->ras_rtd[rascategory].open_req_num--;
165                         time_stat_update(&(hs->ras_rtd[rascategory].stats),&(pi->delta_time), pinfo);
166                 }
167                 break;
168
169         default:
170                 return 0;
171         }
172         return 1;
173 }
174
175 static void
176 h225rassrt_draw(void *phs)
177 {
178         h225rassrt_t *hs=(h225rassrt_t *)phs;
179         int i;
180         timestat_t *rtd_temp;
181
182         printf("======================================== H225 RAS Service Response Time ========================================\n");
183         printf("H225 RAS Service Response Time (SRT) Statistics:\n");
184         printf("RAS-Messages   | Measurements |     Min SRT    |     Max SRT    |     Avg SRT    | Min in Frame | Max in Frame |\n");
185         for(i=0;i<NUM_RAS_STATS;i++) {
186                 rtd_temp = &(hs->ras_rtd[i].stats);
187                 if(rtd_temp->num){
188                         printf("%s | %10u   | %9.2f msec | %9.2f msec | %9.2f msec |  %10u  |  %10u  |\n",
189                                 val_to_str(i,ras_message_category,"Unknown       "),rtd_temp->num,
190                                 nstime_to_msec(&(rtd_temp->min)), nstime_to_msec(&(rtd_temp->max)),
191                                 get_average(&(rtd_temp->tot), rtd_temp->num),
192                                 rtd_temp->min_num, rtd_temp->max_num
193                         );
194                 }
195         }
196         printf("================================================================================================================\n");
197         printf("RAS-Messages   |   Open REQ   |  Discarded RSP  |   Repeated REQ  |   Repeated RSP  |\n");
198         for(i=0;i<NUM_RAS_STATS;i++) {
199                 rtd_temp = &(hs->ras_rtd[i].stats);
200                 if(rtd_temp->num){
201                         printf("%s | %10u   |    %10u   |    %10u   |    %10u   |\n",
202                                 val_to_str(i,ras_message_category,"Unknown       "),
203                                 hs->ras_rtd[i].open_req_num, hs->ras_rtd[i].disc_rsp_num,
204                                 hs->ras_rtd[i].req_dup_num, hs->ras_rtd[i].rsp_dup_num
205                         );
206                 }
207         }
208         printf("================================================================================================================\n");
209
210 }
211
212
213 static void
214 h225rassrt_init(const char *optarg, void* userdata _U_)
215 {
216         h225rassrt_t *hs;
217         GString *error_string;
218
219         hs = g_malloc(sizeof(h225rassrt_t));
220         if(!strncmp(optarg,"h225,srt,",9)){
221                 hs->filter=g_strdup(optarg+9);
222         } else {
223                 hs->filter=NULL;
224         }
225
226         h225rassrt_reset(hs);
227
228         error_string=register_tap_listener("h225", hs, hs->filter, 0, NULL, h225rassrt_packet, h225rassrt_draw);
229         if(error_string){
230                 /* error, we failed to attach to the tap. clean up */
231                 g_free(hs->filter);
232                 g_free(hs);
233
234                 fprintf(stderr, "tshark: Couldn't register h225,srt tap: %s\n",
235                     error_string->str);
236                 g_string_free(error_string, TRUE);
237                 exit(1);
238         }
239 }
240
241
242 void
243 register_tap_listener_h225rassrt(void)
244 {
245         register_stat_cmd_arg("h225,srt", h225rassrt_init,NULL);
246 }