Răsfoiți Sursa

bug fixes, latency stats

Jiri Kuthan 24 ani în urmă
părinte
comite
4f3faaaf17
7 a modificat fișierele cu 59 adăugiri și 24 ștergeri
  1. 0 4
      modules/tm/h_table.c
  2. 7 12
      modules/tm/t_funcs.c
  3. 13 3
      modules/tm/t_lookup.c
  4. 24 1
      receive.c
  5. 5 0
      stats.h
  6. 3 2
      test/tx.cfg
  7. 7 2
      test/xx.cfg

+ 0 - 4
modules/tm/h_table.c

@@ -147,10 +147,6 @@ struct cell*  build_cell( struct sip_msg* p_msg )
    new_cell->wait_tl.payload = new_cell;
    new_cell->dele_tl.payload = new_cell;
 
-   /* inbound request */
-   /* force parsing all the needed headers*/
-   if (parse_headers(p_msg, HDR_EOH )==-1)
-	goto error;
    new_cell->inbound_request =  sip_msg_cloner(p_msg) ;
    DBG("DEBUG: build_cell : clone done\n");
    if (!new_cell->inbound_request)

+ 7 - 12
modules/tm/t_funcs.c

@@ -152,7 +152,7 @@ int t_add_transaction( struct sip_msg* p_msg, char* foo, char* bar )
    }
 
    /* it's about the same transaction or not?*/
-   t_check( p_msg , 0 );
+	if (t_check( p_msg , 0 )==-1) return -1;
 
    /* if the lookup's result is not 0 means that it's a retransmission */
    if ( T )
@@ -198,7 +198,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
 	branch = 0;	/* we don't do any forking right now */
 
 	/* it's about the same transaction or not? */
-	t_check( p_msg  , 0 );
+	if (t_check( p_msg , 0 )==-1) return -1;
 
 	/*if T hasn't been found after all -> return not found (error) */
 	if ( !T )
@@ -355,7 +355,7 @@ int t_forward_uri( struct sip_msg* p_msg, char* foo, char* bar  )
    int                      err;
 
    /* it's about the same transaction or not? */
-   t_check( p_msg , 0);
+	if (t_check( p_msg  , 0 )==-1) return -1;
 
    /*if T hasn't been found after all -> return not found (error) */
    if ( !T )
@@ -428,12 +428,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
 	   a chance for minimum routing; parse only what's needed
 	   for MPLS-ize reply matching
 	*/
-	if ( parse_headers(p_msg, HDR_VIA1|HDR_VIA2|HDR_TO|HDR_CSEQ )==-1 ||
-		!p_msg->via1 || !p_msg->via2 || !p_msg->to || !p_msg->cseq )
-	return 1;
-
-	/* we use label-matching to lookup for T */
-	t_check( p_msg , &branch );
+	if (t_check( p_msg  , &branch )==-1) return 1;
 
 	/* if no T found ->tell the core router to forward statelessly */
 	if ( T<=0 )
@@ -536,7 +531,7 @@ error:
   */
 int t_release_transaction( struct sip_msg* p_msg)
 {
-   t_check( p_msg , 0 );
+	if (t_check( p_msg  , 0 )==-1) return 1;
 
    if ( T && T!=T_UNDEFINED )
       return t_put_on_wait( T );
@@ -556,7 +551,7 @@ int t_release_transaction( struct sip_msg* p_msg)
   */
 int t_retransmit_reply( struct sip_msg* p_msg, char* foo, char* bar  )
 {
-   t_check( p_msg , 0 );
+	if (t_check( p_msg  , 0 )==-1) return 1;
 
    /* if no transaction exists or no reply to be resend -> out */
    if ( T )
@@ -592,7 +587,7 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
 	char *b;
 
 	DBG("DEBUG: t_send_reply: entered\n");
-	t_check( p_msg , 0 );
+	if (t_check( p_msg , 0 )==-1) return -1;
 
 	if (!T)
 	{

+ 13 - 3
modules/tm/t_lookup.c

@@ -312,6 +312,7 @@ nomatch2:
 
 /* Functions update T (T gets either a valid pointer in it or it equals zero) if no transaction
   * for current message exists;
+  * it returns 1 if found, 0 if not found, -1 on error
   */
 int t_check( struct sip_msg* p_msg , int *param_branch)
 {
@@ -326,10 +327,19 @@ int t_check( struct sip_msg* p_msg , int *param_branch)
          unref_T(T);
       T = T_UNDEFINED;
       /* transaction lookup */
-     if ( p_msg->first_line.type==SIP_REQUEST )
+     if ( p_msg->first_line.type==SIP_REQUEST ) {
+
+   		/* force parsing all the needed headers*/
+   		if (parse_headers(p_msg, HDR_EOH )==-1)
+    		return -1;
          t_lookup_request( p_msg );
-     else
+	 } else {
+		 if ( parse_headers(p_msg, HDR_VIA1|HDR_VIA2|HDR_TO|HDR_CSEQ )==-1 ||
+        		!p_msg->via1 || !p_msg->via2 || !p_msg->to || !p_msg->cseq )
+    		return -1;
+
          t_reply_matching( p_msg , ((param_branch!=0)?(param_branch):(&local_branch)) );
+	 }
 #ifdef EXTRA_DEBUG
 	if ( T && T!=T_UNDEFINED && T->damocles) {
 		LOG( L_ERR, "ERROR: transaction %p scheduled for deletion and called from t_check\n", T);
@@ -346,7 +356,7 @@ int t_check( struct sip_msg* p_msg , int *param_branch)
           DBG("DEBUG: t_check: T previously sought and not found\n");
    }
 
-   return ((T)?1:-1) ;
+   return ((T)?1:0) ;
 }
 
 

+ 24 - 1
receive.c

@@ -4,6 +4,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <sys/time.h>
 
 #include "receive.h"
 #include "dprint.h"
@@ -26,6 +27,9 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 	struct sip_msg* msg;
 #ifdef STATS
 	int skipped = 1;
+	struct timeval tvb, tve;	
+	struct timezone tz;
+	unsigned int diff;
 #endif
 
 	msg=pkg_malloc(sizeof(struct sip_msg));
@@ -69,13 +73,22 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 		
 		/* exec routing script */
 		DBG("preparing to run routing scripts...\n");
+#ifdef  STATS
+		gettimeofday( & tvb, &tz );
+#endif
 		if (run_actions(rlist[0], msg)<0){
 			LOG(L_WARN, "WARNING: receive_msg: "
 					"error while trying script\n");
 			goto error;
 		}
-		DBG("succesfully ran routing scripts...\n");
+#ifdef STATS
+		gettimeofday( & tve, &tz );
+		diff = (tve.tv_sec-tvb.tv_sec)*1000000+(tve.tv_usec-tvb.tv_usec);
+		stats->processed_requests++;
+		stats->acc_req_time += diff;
+		DBG("succesfully ran routing scripts...(%d usec)\n", diff);
 		STATS_RX_REQUEST( msg->first_line.u.request.method_value );
+#endif
 	}else if (msg->first_line.type==SIP_REPLY){
 		DBG("msg= reply\n");
 		/* sanity checks */
@@ -91,7 +104,10 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 		}
 		/* check if via1 == us */
 
+#ifdef STATS
+		gettimeofday( & tvb, &tz );
 		STATS_RX_RESPONSE ( msg->first_line.u.reply.statusclass );
+#endif
 		
 		/* send the msg */
 		if (forward_reply(msg)==0){
@@ -99,6 +115,13 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 						msg->via2->host.s,
 						(unsigned short) msg->via2->port);
 		}
+#ifdef STATS
+		gettimeofday( & tve, &tz );
+		diff = (tve.tv_sec-tvb.tv_sec)*1000000+(tve.tv_usec-tvb.tv_usec);
+		stats->processed_responses++;
+		stats->acc_res_time+=diff;
+		DBG("succesfully ran reply processing...(%d usec)\n", diff);
+#endif
 	}
 #ifdef STATS
 	skipped = 0;

+ 5 - 0
stats.h

@@ -116,6 +116,11 @@ struct stats_s {
 	sent_responses_5,
 	sent_responses_6,
 
+	processed_requests,
+	processed_responses,
+	acc_req_time,
+	acc_res_time,
+
 	failed_on_send;			
 			  
 };

+ 3 - 2
test/tx.cfg

@@ -8,9 +8,10 @@ debug=1          # debug level (cmd line: -dddddddddd)
 check_via=yes     # (cmd. line: -v)
 dns=on           # (cmd. line: -r)
 rev_dns=yes      # (cmd. line: -R)
-fork=yes          # (cmd. line: -D)
+#fork=yes          # (cmd. line: -D)
+fork=no
 children=16
-#log_stderror=yes # (cmd line: -E)
+log_stderror=yes # (cmd line: -E)
 log_stderror=no	# (cmd line: -E)
 port=5080
 #listen=127.0.0.1

+ 7 - 2
test/xx.cfg

@@ -4,7 +4,7 @@
 #
 
 
-debug=9          # debug level (cmd line: -dddddddddd)
+debug=3          # debug level (cmd line: -dddddddddd)
 log_stderror=yes # (cmd line: -E)
 check_via=yes     # (cmd. line: -v)
 dns=on           # (cmd. line: -r)
@@ -20,7 +20,12 @@ loop_checks=1
 loadmodule "modules/print/print.so"
 #loadmodule "modules/tm/tm.so"
 
-route{
+route[0] {
+	forward(195.37.78.146, 5060);
+	drop;
+}
+
+route[1]{
 	if ( t_lookup_request()) {
 		if ( method=="ACK" )	{
 			t_release();