For AFP requests, add in the frame with the (last part of the) reply, if

possible, and, for AFP replies, add in the frame with the request and
the time between those two frames.

Have AFP per-request-type RTT statistics, similar to SMB's statistics.

svn path=/trunk/; revision=15456
This commit is contained in:
Guy Harris 2005-08-20 02:19:37 +00:00
parent e5c09b21aa
commit 2028488827
6 changed files with 584 additions and 9 deletions

View File

@ -112,6 +112,7 @@ ETHEREAL_COMMON_INCLUDES = \
# sources for Tethereal taps
TETHEREAL_TAP_SRC = \
tap-afpstat.c \
tap-ansi_astat.c \
tap-bootpstat.c \
tap-dcerpcstat.c \

View File

@ -39,6 +39,7 @@
/* #include <epan/strutil.h> */
#include <epan/conversation.h>
#include <epan/emem.h>
#include <epan/tap.h>
#include "packet-afp.h"
@ -166,6 +167,10 @@ static int hf_afp_user = -1;
static int hf_afp_passwd = -1;
static int hf_afp_random = -1;
static int hf_afp_response_to = -1;
static int hf_afp_time = -1;
static int hf_afp_response_in = -1;
static int hf_afp_login_flags = -1;
static int hf_afp_pad = -1;
@ -332,6 +337,8 @@ static int hf_afp_extattr_start_index = -1;
static int hf_afp_extattr_reply_size = -1;
static int ett_afp_extattr_names = -1;
static int afp_tap = -1;
static dissector_handle_t data_handle;
static const value_string vol_signature_vals[] = {
@ -341,7 +348,7 @@ static const value_string vol_signature_vals[] = {
{0, NULL }
};
static const value_string CommandCode_vals[] = {
const value_string CommandCode_vals[] = {
{AFP_BYTELOCK, "FPByteRangeLock" },
{AFP_CLOSEVOL, "FPCloseVol" },
{AFP_CLOSEDIR, "FPCloseDir" },
@ -956,10 +963,6 @@ typedef struct {
guint16 seq;
} afp_request_key;
typedef struct {
guint8 command;
} afp_request_val;
static GHashTable *afp_request_hash = NULL;
static guint Vol; /* volume */
@ -3999,14 +4002,15 @@ dissect_reply_afp_get_acl(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tre
static void
dissect_afp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
struct aspinfo *aspinfo = pinfo->private_data;
proto_tree *afp_tree = NULL;
struct aspinfo *aspinfo = pinfo->private_data;
proto_tree *afp_tree = NULL;
proto_item *ti;
conversation_t *conversation;
gint offset = 0;
afp_request_key request_key, *new_request_key;
afp_request_val *request_val;
guint8 afp_command;
guint8 afp_command;
nstime_t t, deltat;
int len = tvb_reported_length_remaining(tvb,0);
gint col_info = check_col(pinfo->cinfo, COL_INFO);
@ -4037,7 +4041,11 @@ dissect_afp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
*new_request_key = request_key;
request_val = se_alloc(sizeof(afp_request_val));
request_val->command = tvb_get_guint8(tvb, offset);
request_val->command = afp_command;
request_val->frame_req = pinfo->fd->num;
request_val->frame_res = 0;
request_val->req_time.secs=pinfo->fd->abs_secs;
request_val->req_time.nsecs=pinfo->fd->abs_usecs*1000;
g_hash_table_insert(afp_request_hash, new_request_key,
request_val);
@ -4084,6 +4092,18 @@ dissect_afp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
return;
}
}
/*
* Put in a field for the frame number of the frame to which
* this is a response if we know that frame number (i.e.,
* it's not 0).
*/
if (request_val->frame_res != 0) {
ti = proto_tree_add_uint(afp_tree, hf_afp_response_in,
tvb, 0, 0, request_val->frame_res);
PROTO_ITEM_SET_GENERATED(ti);
}
offset++;
switch(afp_command) {
case AFP_BYTELOCK:
@ -4219,11 +4239,42 @@ dissect_afp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
else {
proto_tree_add_uint(afp_tree, hf_afp_command, tvb, 0, 0, afp_command);
/*
* Put in fields for the frame with the response to this
* frame - if we know the frame number (i.e., it's not 0).
*/
if (request_val->frame_req != 0) {
ti = proto_tree_add_uint(afp_tree, hf_afp_response_to,
tvb, 0, 0, request_val->frame_req);
PROTO_ITEM_SET_GENERATED(ti);
t.secs = pinfo->fd->abs_secs;
t.nsecs = pinfo->fd->abs_usecs*1000;
get_timedelta(&deltat, &t, &request_val->req_time);
ti = proto_tree_add_time(afp_tree, hf_afp_time, tvb,
0, 0, &deltat);
PROTO_ITEM_SET_GENERATED(ti);
}
/*
* Set "frame_res" if it's not already known.
*/
if (request_val->frame_res == 0)
request_val->frame_res = pinfo->fd->num;
if (!len) {
/* for some calls if the reply is an error there's no data
*/
return;
}
/*
* Tap the packet before the dissectors are called so we
* still get the tap listener called even if there is an
* exception.
*/
tap_queue_packet(afp_tap, pinfo, request_val);
switch(afp_command) {
case AFP_BYTELOCK:
offset = dissect_reply_afp_byte_lock(tvb, pinfo, afp_tree, offset);break;
@ -4355,6 +4406,21 @@ proto_register_afp(void)
FT_BYTES, BASE_HEX, NULL, 0x0,
"UAM random number", HFILL }},
{ &hf_afp_response_to,
{ "Response to", "afp.response_to",
FT_FRAMENUM, BASE_NONE, NULL, 0x0,
"This packet is a response to the packet in this frame", HFILL }},
{ &hf_afp_time,
{ "Time from request", "afp.time",
FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0,
"Time between Request and Response for AFP cmds", HFILL }},
{ &hf_afp_response_in,
{ "Response in", "afp.response_in",
FT_FRAMENUM, BASE_NONE, NULL, 0x0,
"The response to this packet is in this packet", HFILL }},
{ &hf_afp_login_flags,
{ "Flags", "afp.afp_login_flags",
FT_UINT16, BASE_HEX, NULL, 0 /* 0x0FFF*/,
@ -5768,6 +5834,8 @@ proto_register_afp(void)
register_dissector("afp", dissect_afp, proto_afp);
data_handle = find_dissector("data");
afp_tap = register_tap("afp");
}
void

View File

@ -120,4 +120,19 @@ struct aspinfo {
gint32 code; /* error code/ offset NU */
};
/*
* value_string table for AFP command codes.
*/
extern const value_string CommandCode_vals[];
/*
* Value from table matching requests and responses; also passed to AFP
* tap for responses.
*/
typedef struct {
guint8 command;
guint32 frame_req, frame_res;
nstime_t req_time;
} afp_request_val;
#endif

View File

@ -105,6 +105,7 @@ ETHEREAL_GTK_SRC = \
ETHEREAL_TAP_SRC = \
afp_stat.c \
ansi_a_stat.c \
ansi_map_stat.c \
bootp_stat.c \

318
gtk/afp_stat.c Normal file
View File

@ -0,0 +1,318 @@
/* afp_stat.c
* Based on
* smb_stat 2003 Ronnie Sahlberg
*
* $Id$
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#include <string.h>
#include <gtk/gtk.h>
#include <epan/packet_info.h>
#include <epan/epan.h>
#include <epan/value_string.h>
#include <epan/stat.h>
#include "stat_menu.h"
#include <epan/tap.h>
#include <epan/dissectors/packet-afp.h>
#include "../register.h"
#include "../timestats.h"
#include "compat_macros.h"
#include "../simple_dialog.h"
#include "ui_util.h"
#include "dlg_utils.h"
#include "../file.h"
#include "../globals.h"
#include "filter_dlg.h"
#include "service_response_time_table.h"
#include "gtkglobals.h"
/* used to keep track of the statistics for an entire program interface */
typedef struct _afpstat_t {
GtkWidget *win;
srt_stat_table afp_srt_table;
} afpstat_t;
static void
afpstat_set_title(afpstat_t *ss)
{
char *title;
title = g_strdup_printf("AFP Service Response Time statistics: %s",
cf_get_display_name(&cfile));
gtk_window_set_title(GTK_WINDOW(ss->win), title);
g_free(title);
}
static void
afpstat_reset(void *pss)
{
afpstat_t *ss=(afpstat_t *)pss;
reset_srt_table_data(&ss->afp_srt_table);
afpstat_set_title(ss);
}
static int
afpstat_packet(void *pss, packet_info *pinfo, epan_dissect_t *edt _U_, const void *prv)
{
afpstat_t *ss=(afpstat_t *)pss;
const afp_request_val *request_val=prv;
/* if we havnt seen the request, just ignore it */
if(!request_val){
return 0;
}
add_srt_table_data(&ss->afp_srt_table, request_val->command, &request_val->req_time, pinfo);
return 1;
}
static void
afpstat_draw(void *pss)
{
afpstat_t *ss=(afpstat_t *)pss;
draw_srt_table_data(&ss->afp_srt_table);
}
void protect_thread_critical_region(void);
void unprotect_thread_critical_region(void);
static void
win_destroy_cb(GtkWindow *win _U_, gpointer data)
{
afpstat_t *ss=(afpstat_t *)data;
protect_thread_critical_region();
remove_tap_listener(ss);
unprotect_thread_critical_region();
free_srt_table_data(&ss->afp_srt_table);
g_free(ss);
}
static void
gtk_afpstat_init(const char *optarg)
{
afpstat_t *ss;
const char *filter=NULL;
GtkWidget *label;
char filter_string[256];
GString *error_string;
int i;
GtkWidget *vbox;
GtkWidget *bbox;
GtkWidget *close_bt;
if(!strncmp(optarg,"afp,srt,",8)){
filter=optarg+8;
} else {
filter=NULL;
}
ss=g_malloc(sizeof(afpstat_t));
ss->win=window_new(GTK_WINDOW_TOPLEVEL, "afp-stat");
gtk_window_set_default_size(GTK_WINDOW(ss->win), 550, 600);
afpstat_set_title(ss);
vbox=gtk_vbox_new(FALSE, 3);
gtk_container_add(GTK_CONTAINER(ss->win), vbox);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
label=gtk_label_new("AFP Service Response Time statistics");
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
g_snprintf(filter_string,255,"Filter:%s",filter?filter:"");
label=gtk_label_new(filter_string);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
label=gtk_label_new("AFP Commands");
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
/* We must display TOP LEVEL Widget before calling init_srt_table() */
gtk_widget_show_all(ss->win);
init_srt_table(&ss->afp_srt_table, 256, vbox, "afp.cmd");
for(i=0;i<256;i++){
init_srt_table_row(&ss->afp_srt_table, i, val_to_str(i, CommandCode_vals, "Unknown(%u)"));
}
error_string=register_tap_listener("afp", ss, filter, afpstat_reset, afpstat_packet, afpstat_draw);
if(error_string){
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
g_string_free(error_string, TRUE);
g_free(ss);
return;
}
/* Button row. */
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
window_set_cancel_button(ss->win, close_bt, window_cancel_button_cb);
SIGNAL_CONNECT(ss->win, "delete_event", window_delete_event_cb, NULL);
SIGNAL_CONNECT(ss->win, "destroy", win_destroy_cb, ss);
gtk_widget_show_all(ss->win);
window_present(ss->win);
cf_retap_packets(&cfile);
}
static GtkWidget *dlg=NULL;
static GtkWidget *filter_entry;
static void
dlg_destroy_cb(void)
{
dlg=NULL;
}
static void
afpstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
{
GString *str;
const char *filter;
str = g_string_new("afp,srt");
filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
if(filter[0]!=0){
g_string_sprintfa(str,",%s", filter);
}
gtk_afpstat_init(str->str);
g_string_free(str, TRUE);
}
static void
gtk_afpstat_cb(GtkWidget *w _U_, gpointer d _U_)
{
GtkWidget *dlg_box;
GtkWidget *filter_box, *filter_bt;
GtkWidget *bbox, *start_button, *cancel_button;
const char *filter;
static construct_args_t args = {
"Service Response Time Statistics Filter",
TRUE,
FALSE
};
/* if the window is already open, bring it to front */
if(dlg){
gdk_window_raise(dlg->window);
return;
}
dlg=dlg_window_new("Ethereal: Compute AFP SRT statistics");
gtk_window_set_default_size(GTK_WINDOW(dlg), 300, -1);
dlg_box=gtk_vbox_new(FALSE, 10);
gtk_container_border_width(GTK_CONTAINER(dlg_box), 10);
gtk_container_add(GTK_CONTAINER(dlg), dlg_box);
gtk_widget_show(dlg_box);
/* Filter box */
filter_box=gtk_hbox_new(FALSE, 3);
/* Filter button */
filter_bt=BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_DISPLAY_FILTER_ENTRY);
SIGNAL_CONNECT(filter_bt, "clicked", display_filter_construct_cb, &args);
gtk_box_pack_start(GTK_BOX(filter_box), filter_bt, FALSE, TRUE, 0);
gtk_widget_show(filter_bt);
/* Filter entry */
filter_entry=gtk_entry_new();
SIGNAL_CONNECT(filter_entry, "changed", filter_te_syntax_check_cb, NULL);
/* filter prefs dialog */
OBJECT_SET_DATA(filter_bt, E_FILT_TE_PTR_KEY, filter_entry);
/* filter prefs dialog */
gtk_box_pack_start(GTK_BOX(filter_box), filter_entry, TRUE, TRUE, 0);
filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
if(filter){
gtk_entry_set_text(GTK_ENTRY(filter_entry), filter);
}
gtk_widget_show(filter_entry);
gtk_box_pack_start(GTK_BOX(dlg_box), filter_box, TRUE, TRUE, 0);
gtk_widget_show(filter_box);
/* button box */
bbox = dlg_button_row_new(ETHEREAL_STOCK_CREATE_STAT, GTK_STOCK_CANCEL, NULL);
gtk_box_pack_start(GTK_BOX(dlg_box), bbox, FALSE, FALSE, 0);
gtk_widget_show(bbox);
start_button = OBJECT_GET_DATA(bbox, ETHEREAL_STOCK_CREATE_STAT);
SIGNAL_CONNECT_OBJECT(start_button, "clicked",
afpstat_start_button_clicked, NULL);
cancel_button = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
window_set_cancel_button(dlg, cancel_button, window_cancel_button_cb);
/* Catch the "activate" signal on the filter text entry, so that
if the user types Return there, we act as if the "Create Stat"
button had been selected, as happens if Return is typed if some
widget that *doesn't* handle the Return key has the input
focus. */
dlg_set_activate(filter_entry, start_button);
gtk_widget_grab_default(start_button );
/* Give the initial focus to the "Filter" entry box. */
gtk_widget_grab_focus(filter_entry);
SIGNAL_CONNECT(dlg, "delete_event", window_delete_event_cb, NULL);
SIGNAL_CONNECT(dlg, "destroy", dlg_destroy_cb, NULL);
gtk_widget_show_all(dlg);
window_present(dlg);
}
void
register_tap_listener_gtkafpstat(void)
{
register_stat_cmd_arg("afp,srt", gtk_afpstat_init);
register_stat_menu_item("AFP...", REGISTER_STAT_GROUP_RESPONSE_TIME,
gtk_afpstat_cb, NULL, NULL, NULL);
}

172
tap-afpstat.c Normal file
View File

@ -0,0 +1,172 @@
/* tap-afpstat.c
* Based on
* smbstat 2003 Ronnie Sahlberg
*
* $Id$
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#include <string.h>
#include <epan/packet_info.h>
#include <epan/tap.h>
#include <epan/stat.h>
#include <epan/value_string.h>
#include <epan/dissectors/packet-afp.h>
#include "register.h"
#include "timestats.h"
/* used to keep track of the statistics for an entire program interface */
typedef struct _afpstat_t {
char *filter;
timestat_t proc[256];
} afpstat_t;
static int
afpstat_packet(void *pss, packet_info *pinfo, epan_dissect_t *edt _U_, const void *prv)
{
afpstat_t *ss=(afpstat_t *)pss;
const afp_request_val *request_val=prv;
nstime_t t, deltat;
timestat_t *sp=NULL;
/* if we havnt seen the request, just ignore it */
if(!request_val){
return 0;
}
sp=&(ss->proc[request_val->command]);
/* calculate time delta between request and reply */
t.secs=pinfo->fd->abs_secs;
t.nsecs=pinfo->fd->abs_usecs*1000;
get_timedelta(&deltat, &t, &request_val->req_time);
if(sp){
time_stat_update(sp,&deltat, pinfo);
}
return 1;
}
static void
afpstat_draw(void *pss)
{
afpstat_t *ss=(afpstat_t *)pss;
guint32 i;
#ifdef G_HAVE_UINT64
guint64 td;
#else
guint32 td;
#endif
printf("\n");
printf("===================================================================\n");
printf("AFP RTT Statistics:\n");
printf("Filter: %s\n",ss->filter?ss->filter:"");
printf("Commands Calls Min RTT Max RTT Avg RTT\n");
for(i=0;i<256;i++){
/* nothing seen, nothing to do */
if(ss->proc[i].num==0){
continue;
}
/* scale it to units of 10us.*/
/* for long captures with a large tot time, this can overflow on 32bit */
td=(int)ss->proc[i].tot.secs;
td=td*100000+(int)ss->proc[i].tot.nsecs/10000;
if(ss->proc[i].num){
td/=ss->proc[i].num;
} else {
td=0;
}
printf("%-25s %6d %3d.%05d %3d.%05d %3d.%05d\n",
val_to_str(i, CommandCode_vals, "Unknown (%u)"),
ss->proc[i].num,
(int)ss->proc[i].min.secs,ss->proc[i].min.nsecs/10000,
(int)ss->proc[i].max.secs,ss->proc[i].max.nsecs/10000,
td/100000, td%100000
);
}
printf("===================================================================\n");
}
static void
afpstat_init(const char *optarg)
{
afpstat_t *ss;
guint32 i;
const char *filter=NULL;
GString *error_string;
if(!strncmp(optarg,"afp,rtt,",8)){
filter=optarg+8;
} else {
filter=NULL;
}
ss=g_malloc(sizeof(afpstat_t));
if(filter){
ss->filter=g_malloc(strlen(filter)+1);
strcpy(ss->filter, filter);
} else {
ss->filter=NULL;
}
for(i=0;i<256;i++){
ss->proc[i].num=0;
ss->proc[i].min_num=0;
ss->proc[i].max_num=0;
ss->proc[i].min.secs=0;
ss->proc[i].min.nsecs=0;
ss->proc[i].max.secs=0;
ss->proc[i].max.nsecs=0;
ss->proc[i].tot.secs=0;
ss->proc[i].tot.nsecs=0;
}
error_string=register_tap_listener("afp", ss, filter, NULL, afpstat_packet, afpstat_draw);
if(error_string){
/* error, we failed to attach to the tap. clean up */
g_free(ss->filter);
g_free(ss);
fprintf(stderr, "tethereal: Couldn't register afp,rtt tap: %s\n",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
}
void
register_tap_listener_afpstat(void)
{
register_stat_cmd_arg("afp,rtt", afpstat_init);
}