HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / ui / cli / tap-h225rassrt.c
blob6fc19c20adbdbfe7931d16e8392e4489c824c569
1 /* tap_h225rassrt.c
2 * h225 RAS Service Response Time statistics for wireshark
3 * Copyright 2003 Lars Roland
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
32 #include "epan/packet.h"
33 #include "epan/packet_info.h"
34 #include <epan/tap.h>
35 #include <epan/stat_cmd_args.h>
36 #include "epan/value_string.h"
37 #include <epan/dissectors/packet-h225.h>
38 #include "epan/timestats.h"
40 /* following values represent the size of their valuestring arrays */
41 #define NUM_RAS_STATS 7
43 void register_tap_listener_h225rassrt(void);
45 static const value_string ras_message_category[] = {
46 { 0, "Gatekeeper "},
47 { 1, "Registration "},
48 { 2, "UnRegistration"},
49 { 3, "Admission "},
50 { 4, "Bandwidth "},
51 { 5, "Disengage "},
52 { 6, "Location "},
53 { 0, NULL }
56 typedef enum _ras_type {
57 RAS_REQUEST,
58 RAS_CONFIRM,
59 RAS_REJECT,
60 RAS_OTHER
61 }ras_type;
63 typedef enum _ras_category {
64 RAS_GATEKEEPER,
65 RAS_REGISTRATION,
66 RAS_UNREGISTRATION,
67 RAS_ADMISSION,
68 RAS_BANDWIDTH,
69 RAS_DISENGAGE,
70 RAS_LOCATION,
71 RAS_OTHERS
72 }ras_category;
74 /* Summary of response-time calculations*/
75 typedef struct _h225_rtd_t {
76 guint32 open_req_num;
77 guint32 disc_rsp_num;
78 guint32 req_dup_num;
79 guint32 rsp_dup_num;
80 timestat_t stats;
81 } h225_rtd_t;
83 /* used to keep track of the statistics for an entire program interface */
84 typedef struct _h225rassrt_t {
85 char *filter;
86 h225_rtd_t ras_rtd[NUM_RAS_STATS];
87 } h225rassrt_t;
90 static void
91 h225rassrt_reset(void *phs)
93 h225rassrt_t *hs=(h225rassrt_t *)phs;
94 int i;
96 for(i=0;i<NUM_RAS_STATS;i++) {
97 hs->ras_rtd[i].stats.num = 0;
98 hs->ras_rtd[i].stats.min_num = 0;
99 hs->ras_rtd[i].stats.max_num = 0;
100 hs->ras_rtd[i].stats.min.secs = 0;
101 hs->ras_rtd[i].stats.min.nsecs = 0;
102 hs->ras_rtd[i].stats.max.secs = 0;
103 hs->ras_rtd[i].stats.max.nsecs = 0;
104 hs->ras_rtd[i].stats.tot.secs = 0;
105 hs->ras_rtd[i].stats.tot.nsecs = 0;
106 hs->ras_rtd[i].open_req_num = 0;
107 hs->ras_rtd[i].disc_rsp_num = 0;
108 hs->ras_rtd[i].req_dup_num = 0;
109 hs->ras_rtd[i].rsp_dup_num = 0;
114 static int
115 h225rassrt_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *phi)
117 h225rassrt_t *hs=(h225rassrt_t *)phs;
118 const h225_packet_info *pi=(const h225_packet_info *)phi;
120 ras_type rasmsg_type = RAS_OTHER;
121 ras_category rascategory = RAS_OTHERS;
123 if (pi->msg_type != H225_RAS || pi->msg_tag == -1) {
124 /* No RAS Message or uninitialized msg_tag -> return */
125 return 0;
128 if (pi->msg_tag < 21) {
129 /* */
130 rascategory = (ras_category)(pi->msg_tag / 3);
131 rasmsg_type = (ras_type)(pi->msg_tag % 3);
133 else {
134 /* No SRT yet (ToDo) */
135 return 0;
138 switch(rasmsg_type) {
140 case RAS_REQUEST:
141 if(pi->is_duplicate){
142 hs->ras_rtd[rascategory].req_dup_num++;
144 else {
145 hs->ras_rtd[rascategory].open_req_num++;
147 break;
149 case RAS_CONFIRM:
150 /* no break - delay calculation is identical for Confirm and Reject */
151 case RAS_REJECT:
152 if(pi->is_duplicate){
153 /* Duplicate is ignored */
154 hs->ras_rtd[rascategory].rsp_dup_num++;
156 else if (!pi->request_available) {
157 /* no request was seen, ignore response */
158 hs->ras_rtd[rascategory].disc_rsp_num++;
160 else {
161 hs->ras_rtd[rascategory].open_req_num--;
162 time_stat_update(&(hs->ras_rtd[rascategory].stats),&(pi->delta_time), pinfo);
164 break;
166 default:
167 return 0;
169 return 1;
172 static void
173 h225rassrt_draw(void *phs)
175 h225rassrt_t *hs=(h225rassrt_t *)phs;
176 int i;
177 timestat_t *rtd_temp;
179 printf("======================================== H225 RAS Service Response Time ========================================\n");
180 printf("H225 RAS Service Response Time (SRT) Statistics:\n");
181 printf("RAS-Messages | Measurements | Min SRT | Max SRT | Avg SRT | Min in Frame | Max in Frame |\n");
182 for(i=0;i<NUM_RAS_STATS;i++) {
183 rtd_temp = &(hs->ras_rtd[i].stats);
184 if(rtd_temp->num){
185 printf("%s | %10u | %9.2f msec | %9.2f msec | %9.2f msec | %10u | %10u |\n",
186 val_to_str(i,ras_message_category,"Unknown "),rtd_temp->num,
187 nstime_to_msec(&(rtd_temp->min)), nstime_to_msec(&(rtd_temp->max)),
188 get_average(&(rtd_temp->tot), rtd_temp->num),
189 rtd_temp->min_num, rtd_temp->max_num
193 printf("================================================================================================================\n");
194 printf("RAS-Messages | Open REQ | Discarded RSP | Repeated REQ | Repeated RSP |\n");
195 for(i=0;i<NUM_RAS_STATS;i++) {
196 rtd_temp = &(hs->ras_rtd[i].stats);
197 if(rtd_temp->num){
198 printf("%s | %10u | %10u | %10u | %10u |\n",
199 val_to_str(i,ras_message_category,"Unknown "),
200 hs->ras_rtd[i].open_req_num, hs->ras_rtd[i].disc_rsp_num,
201 hs->ras_rtd[i].req_dup_num, hs->ras_rtd[i].rsp_dup_num
205 printf("================================================================================================================\n");
210 static void
211 h225rassrt_init(const char *opt_arg, void* userdata _U_)
213 h225rassrt_t *hs;
214 GString *error_string;
216 hs = g_new(h225rassrt_t,1);
217 if(!strncmp(opt_arg,"h225,srt,",9)){
218 hs->filter=g_strdup(opt_arg+9);
219 } else {
220 hs->filter=NULL;
223 h225rassrt_reset(hs);
225 error_string=register_tap_listener("h225", hs, hs->filter, 0, NULL, h225rassrt_packet, h225rassrt_draw);
226 if(error_string){
227 /* error, we failed to attach to the tap. clean up */
228 g_free(hs->filter);
229 g_free(hs);
231 fprintf(stderr, "tshark: Couldn't register h225,srt tap: %s\n",
232 error_string->str);
233 g_string_free(error_string, TRUE);
234 exit(1);
239 void
240 register_tap_listener_h225rassrt(void)
242 register_stat_cmd_arg("h225,srt", h225rassrt_init,NULL);