aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2009-02-01 20:52:38 +0000
committerAnders Broman <anders.broman@ericsson.com>2009-02-01 20:52:38 +0000
commitf9bb905d13385c1e2ad840e397136316130b2bec (patch)
tree8cd6a200921086aea9c10375e08be754a5c0de70
parent64687d15edbffae083e9a7a2808a0588d8dd2a95 (diff)
Calculate the avrage setuptime.
svn path=/trunk/; revision=27342
-rw-r--r--epan/dissectors/packet-sip.c128
-rw-r--r--epan/dissectors/packet-sip.h1
-rw-r--r--gtk/sip_stat.c23
-rw-r--r--tap-sipstat.c12
4 files changed, 163 insertions, 1 deletions
diff --git a/epan/dissectors/packet-sip.c b/epan/dissectors/packet-sip.c
index bd336afda9..5682f61a5b 100644
--- a/epan/dissectors/packet-sip.c
+++ b/epan/dissectors/packet-sip.c
@@ -583,6 +583,11 @@ static guint sip_find_request(packet_info *pinfo,
guchar cseq_number_set, guint32 cseq_number,
guint32 *response_time);
+static guint sip_find_invite(packet_info *pinfo,
+ gchar* cseq_method,
+ gchar* call_id,
+ guchar cseq_number_set, guint32 cseq_number,
+ guint32 *response_time);
/* SIP content type and internet media type used by other dissectors
* are the same. List of media types from IANA at:
@@ -1613,6 +1618,7 @@ dissect_sip_common(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tr
stat_info->request_method = NULL;
stat_info->reason_phrase = NULL;
stat_info->resend = 0;
+ stat_info->setup_time = 0;
stat_info->tap_call_id = NULL;
stat_info->tap_from_addr = NULL;
stat_info->tap_to_addr = NULL;
@@ -2477,6 +2483,16 @@ separator_found2:
col_append_fstr(pinfo->cinfo, COL_INFO, " (%d bindings)", contacts);
}
}
+ /* Find the total setup time, Must be done before checking for resend
+ * As that will overwrite the "Request packet no".
+ */
+ if ((line_type == REQUEST_LINE)&&(strcmp(cseq_method, "ACK") == 0))
+ {
+ request_for_response = sip_find_invite(pinfo, cseq_method, call_id,
+ cseq_number_set, cseq_number,
+ &response_time);
+ stat_info->setup_time = response_time;
+ }
/* Check if this packet is a resend. */
resend_for_packet = sip_is_packet_resend(pinfo, cseq_method, call_id,
@@ -3090,6 +3106,118 @@ guint sip_find_request(packet_info *pinfo,
return result;
}
+/*
+ * Find the initial INVITE to calculate the total setup time
+ */
+guint sip_find_invite(packet_info *pinfo,
+ gchar *cseq_method,
+ gchar *call_id,
+ guchar cseq_number_set,
+ guint32 cseq_number,
+ guint32 *response_time)
+{
+ guint32 cseq_to_compare = 0;
+ sip_hash_key key;
+ sip_hash_value *p_val = 0;
+ sip_frame_result_value *sip_frame_result = NULL;
+ guint result = 0;
+ gint seconds_between_packets;
+ gint nseconds_between_packets;
+
+ /* Only consider UDP */
+ if (pinfo->ptype != PT_UDP)
+ {
+ return 0;
+ }
+
+ /* Ignore error (usually ICMP) frames */
+ if (pinfo->in_error_pkt)
+ {
+ return 0;
+ }
+
+ /* A broken packet may have no cseq number set. Ignore. */
+ if (!cseq_number_set)
+ {
+ return 0;
+ }
+
+ /* Return any answer stored from previous dissection */
+ if (pinfo->fd->flags.visited)
+ {
+ sip_frame_result = (sip_frame_result_value*)p_get_proto_data(pinfo->fd, proto_sip);
+ if (sip_frame_result != NULL)
+ {
+ *response_time = sip_frame_result->response_time;
+ return sip_frame_result->response_request_frame_num;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ /* No packet entry found, consult global hash table */
+
+ /* Prepare the key */
+ g_strlcpy(key.call_id, call_id, MAX_CALL_ID_SIZE);
+
+ /* Looking for matching INVITE */
+ SET_ADDRESS(&key.dest_address, pinfo->net_dst.type, pinfo->net_dst.len,
+ pinfo->net_dst.data);
+ SET_ADDRESS(&key.source_address, pinfo->net_src.type, pinfo->net_src.len,
+ pinfo->net_src.data);
+ key.dest_port = pinfo->destport;
+ key.source_port = pinfo->srcport;
+
+ /* Do the lookup */
+ p_val = (sip_hash_value*)g_hash_table_lookup(sip_hash, &key);
+
+ if (p_val)
+ {
+ /* Table entry found, we'll use its value for comparison */
+ cseq_to_compare = p_val->cseq;
+ }
+ else
+ {
+ /* We don't have the request */
+ return 0;
+ }
+
+
+ /**************************************************/
+ /* Is it a response to a request that we've seen? */
+ //if ((cseq_number == cseq_to_compare) &&
+ // (p_val->transaction_state == request_seen) &&
+ // (strcmp(cseq_method, p_val->method) == 0))
+ //{
+ // result = p_val->frame_number;
+ //}
+
+ result = p_val->frame_number;
+
+ /* Store return value with this packet */
+ sip_frame_result = p_get_proto_data(pinfo->fd, proto_sip);
+ if (sip_frame_result == NULL)
+ {
+ sip_frame_result = se_alloc(sizeof(sip_frame_result_value));
+ }
+
+ sip_frame_result->response_request_frame_num = result;
+
+ /* Work out response time */
+ seconds_between_packets = (gint)
+ (pinfo->fd->abs_ts.secs - p_val->request_time.secs);
+ nseconds_between_packets =
+ pinfo->fd->abs_ts.nsecs - p_val->request_time.nsecs;
+ sip_frame_result->response_time = (seconds_between_packets*1000) +
+ (nseconds_between_packets / 1000000);
+ *response_time = sip_frame_result->response_time;
+
+ p_add_proto_data(pinfo->fd, proto_sip, sip_frame_result);
+
+ return result;
+}
/* Register the protocol with Wireshark */
diff --git a/epan/dissectors/packet-sip.h b/epan/dissectors/packet-sip.h
index ffd36bc33d..892875641e 100644
--- a/epan/dissectors/packet-sip.h
+++ b/epan/dissectors/packet-sip.h
@@ -31,6 +31,7 @@ typedef struct _sip_info_value_t
gchar *request_method;
guint response_code;
guchar resend;
+ guint32 setup_time;
/* added for VoIP calls analysis, see gtk/voip_calls.c*/
gchar *tap_call_id;
gchar *tap_from_addr;
diff --git a/gtk/sip_stat.c b/gtk/sip_stat.c
index 056f09d2dc..aa28c60fc5 100644
--- a/gtk/sip_stat.c
+++ b/gtk/sip_stat.c
@@ -56,8 +56,10 @@ typedef struct _sip_stats_t {
GHashTable *hash_requests;
guint32 packets; /* number of sip packets, including continuations */
guint32 resent_packets;
+ guint32 avrage_setup_time;
GtkWidget *packets_label;
GtkWidget *resent_label;
+ GtkWidget *avrage_setup_time_label;
GtkWidget *request_box; /* container for INVITE, ... */
@@ -338,6 +340,7 @@ sipstat_reset(void *psp)
{
sp->packets = 0;
sp->resent_packets = 0;
+ sp->avrage_setup_time = 0;
g_hash_table_foreach(sp->hash_responses, (GHFunc)sip_reset_hash_responses, NULL);
g_hash_table_foreach(sp->hash_requests, (GHFunc)sip_reset_hash_requests, NULL);
}
@@ -359,6 +362,14 @@ sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const
sp->resent_packets++;
}
+ /* Calculate avrage setup time */
+ if (value->setup_time){
+ /* Check if it's the first value */
+ if ( sp->avrage_setup_time == 0 ){
+ sp->avrage_setup_time = value->setup_time;
+ }
+ sp->avrage_setup_time = (sp->avrage_setup_time + value->setup_time)/2;
+ }
/* Looking at both requests and responses */
if (value->response_code != 0)
@@ -471,7 +482,12 @@ sipstat_draw(void *psp)
g_hash_table_foreach(sp->hash_responses, (GHFunc)sip_draw_hash_responses, NULL);
g_hash_table_foreach(sp->hash_requests, (GHFunc)sip_draw_hash_requests, NULL);
- gtk_widget_show_all(sp->win);
+ /* Set resend count label */
+ g_snprintf(string_buff, sizeof(string_buff),
+ "(Avrage setup time %d ms)", sp->avrage_setup_time);
+ gtk_label_set(GTK_LABEL(sp->avrage_setup_time_label), string_buff);
+
+ gtk_widget_show_all(sp->win);
}
@@ -619,6 +635,11 @@ gtk_sipstat_init(const char *optarg, void *userdata _U_)
sp->request_box = gtk_vbox_new(FALSE, 10);
gtk_container_add(GTK_CONTAINER(request_fr), sp->request_box);
+ sp->avrage_setup_time = 0;
+ sp->avrage_setup_time_label = gtk_label_new("(Not calculated)");
+ gtk_container_add(GTK_CONTAINER(main_vb), sp->avrage_setup_time_label);
+ gtk_widget_show(sp->avrage_setup_time_label);
+
/* Register this tap listener now */
error_string = register_tap_listener("sip",
diff --git a/tap-sipstat.c b/tap-sipstat.c
index e96bd19926..4559f5a5b7 100644
--- a/tap-sipstat.c
+++ b/tap-sipstat.c
@@ -46,6 +46,7 @@ typedef struct _sip_stats_t {
char *filter;
guint32 packets; /* number of sip packets, including continuations */
guint32 resent_packets;
+ guint32 avrage_setup_time;
GHashTable *hash_responses;
GHashTable *hash_requests;
} sipstat_t;
@@ -214,6 +215,7 @@ sipstat_reset(void *psp )
if (sp) {
sp->packets = 0;
sp->resent_packets = 0;
+ sp->avrage_setup_time = 0;
g_hash_table_foreach( sp->hash_responses, (GHFunc)sip_reset_hash_responses, NULL);
g_hash_table_foreach( sp->hash_requests, (GHFunc)sip_reset_hash_requests, NULL);
}
@@ -229,6 +231,15 @@ sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const
/* Total number of packets, including continuation packets */
sp->packets++;
+
+ /* Calculate avrage setup time */
+ if (value->setup_time){
+ /* Check if it's the first value */
+ if ( sp->avrage_setup_time == 0 ){
+ sp->avrage_setup_time = value->setup_time;
+ }
+ sp->avrage_setup_time = (sp->avrage_setup_time + value->setup_time)/2;
+ }
/* Update resent count if flag set */
if (value->resend)
@@ -345,6 +356,7 @@ sipstat_draw(void *psp )
printf("\n* List of SIP Request methods\n");
g_hash_table_foreach( sp->hash_requests, (GHFunc)sip_draw_hash_requests,
" %-15s : %5d Packets\n");
+ printf( "\n* Avrage setuptime %d ms\n", sp->avrage_setup_time);
printf("===================================================================\n");
}