Browse code

bug fixes, latency stats

Jiri Kuthan authored on 07/01/2002 17:52:26
Showing 7 changed files
... ...
@@ -147,10 +147,6 @@ struct cell*  build_cell( struct sip_msg* p_msg )
147 147
    new_cell->wait_tl.payload = new_cell;
148 148
    new_cell->dele_tl.payload = new_cell;
149 149
 
150
-   /* inbound request */
151
-   /* force parsing all the needed headers*/
152
-   if (parse_headers(p_msg, HDR_EOH )==-1)
153
-	goto error;
154 150
    new_cell->inbound_request =  sip_msg_cloner(p_msg) ;
155 151
    DBG("DEBUG: build_cell : clone done\n");
156 152
    if (!new_cell->inbound_request)
... ...
@@ -152,7 +152,7 @@ int t_add_transaction( struct sip_msg* p_msg, char* foo, char* bar )
152 152
    }
153 153
 
154 154
    /* it's about the same transaction or not?*/
155
-   t_check( p_msg , 0 );
155
+	if (t_check( p_msg , 0 )==-1) return -1;
156 156
 
157 157
    /* if the lookup's result is not 0 means that it's a retransmission */
158 158
    if ( T )
... ...
@@ -198,7 +198,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
198 198
 	branch = 0;	/* we don't do any forking right now */
199 199
 
200 200
 	/* it's about the same transaction or not? */
201
-	t_check( p_msg  , 0 );
201
+	if (t_check( p_msg , 0 )==-1) return -1;
202 202
 
203 203
 	/*if T hasn't been found after all -> return not found (error) */
204 204
 	if ( !T )
... ...
@@ -355,7 +355,7 @@ int t_forward_uri( struct sip_msg* p_msg, char* foo, char* bar  )
355 355
    int                      err;
356 356
 
357 357
    /* it's about the same transaction or not? */
358
-   t_check( p_msg , 0);
358
+	if (t_check( p_msg  , 0 )==-1) return -1;
359 359
 
360 360
    /*if T hasn't been found after all -> return not found (error) */
361 361
    if ( !T )
... ...
@@ -428,12 +428,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
428 428
 	   a chance for minimum routing; parse only what's needed
429 429
 	   for MPLS-ize reply matching
430 430
 	*/
431
-	if ( parse_headers(p_msg, HDR_VIA1|HDR_VIA2|HDR_TO|HDR_CSEQ )==-1 ||
432
-		!p_msg->via1 || !p_msg->via2 || !p_msg->to || !p_msg->cseq )
433
-	return 1;
434
-
435
-	/* we use label-matching to lookup for T */
436
-	t_check( p_msg , &branch );
431
+	if (t_check( p_msg  , &branch )==-1) return 1;
437 432
 
438 433
 	/* if no T found ->tell the core router to forward statelessly */
439 434
 	if ( T<=0 )
... ...
@@ -536,7 +531,7 @@ error:
536 536
   */
537 537
 int t_release_transaction( struct sip_msg* p_msg)
538 538
 {
539
-   t_check( p_msg , 0 );
539
+	if (t_check( p_msg  , 0 )==-1) return 1;
540 540
 
541 541
    if ( T && T!=T_UNDEFINED )
542 542
       return t_put_on_wait( T );
... ...
@@ -556,7 +551,7 @@ int t_release_transaction( struct sip_msg* p_msg)
556 556
   */
557 557
 int t_retransmit_reply( struct sip_msg* p_msg, char* foo, char* bar  )
558 558
 {
559
-   t_check( p_msg , 0 );
559
+	if (t_check( p_msg  , 0 )==-1) return 1;
560 560
 
561 561
    /* if no transaction exists or no reply to be resend -> out */
562 562
    if ( T )
... ...
@@ -592,7 +587,7 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
592 592
 	char *b;
593 593
 
594 594
 	DBG("DEBUG: t_send_reply: entered\n");
595
-	t_check( p_msg , 0 );
595
+	if (t_check( p_msg , 0 )==-1) return -1;
596 596
 
597 597
 	if (!T)
598 598
 	{
... ...
@@ -312,6 +312,7 @@ nomatch2:
312 312
 
313 313
 /* Functions update T (T gets either a valid pointer in it or it equals zero) if no transaction
314 314
   * for current message exists;
315
+  * it returns 1 if found, 0 if not found, -1 on error
315 316
   */
316 317
 int t_check( struct sip_msg* p_msg , int *param_branch)
317 318
 {
... ...
@@ -326,10 +327,19 @@ int t_check( struct sip_msg* p_msg , int *param_branch)
326 326
          unref_T(T);
327 327
       T = T_UNDEFINED;
328 328
       /* transaction lookup */
329
-     if ( p_msg->first_line.type==SIP_REQUEST )
329
+     if ( p_msg->first_line.type==SIP_REQUEST ) {
330
+
331
+   		/* force parsing all the needed headers*/
332
+   		if (parse_headers(p_msg, HDR_EOH )==-1)
333
+    		return -1;
330 334
          t_lookup_request( p_msg );
331
-     else
335
+	 } else {
336
+		 if ( parse_headers(p_msg, HDR_VIA1|HDR_VIA2|HDR_TO|HDR_CSEQ )==-1 ||
337
+        		!p_msg->via1 || !p_msg->via2 || !p_msg->to || !p_msg->cseq )
338
+    		return -1;
339
+
332 340
          t_reply_matching( p_msg , ((param_branch!=0)?(param_branch):(&local_branch)) );
341
+	 }
333 342
 #ifdef EXTRA_DEBUG
334 343
 	if ( T && T!=T_UNDEFINED && T->damocles) {
335 344
 		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)
346 346
           DBG("DEBUG: t_check: T previously sought and not found\n");
347 347
    }
348 348
 
349
-   return ((T)?1:-1) ;
349
+   return ((T)?1:0) ;
350 350
 }
351 351
 
352 352
 
... ...
@@ -4,6 +4,7 @@
4 4
 
5 5
 #include <string.h>
6 6
 #include <stdlib.h>
7
+#include <sys/time.h>
7 8
 
8 9
 #include "receive.h"
9 10
 #include "dprint.h"
... ...
@@ -26,6 +27,9 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
26 26
 	struct sip_msg* msg;
27 27
 #ifdef STATS
28 28
 	int skipped = 1;
29
+	struct timeval tvb, tve;	
30
+	struct timezone tz;
31
+	unsigned int diff;
29 32
 #endif
30 33
 
31 34
 	msg=pkg_malloc(sizeof(struct sip_msg));
... ...
@@ -69,13 +73,22 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
69 69
 		
70 70
 		/* exec routing script */
71 71
 		DBG("preparing to run routing scripts...\n");
72
+#ifdef  STATS
73
+		gettimeofday( & tvb, &tz );
74
+#endif
72 75
 		if (run_actions(rlist[0], msg)<0){
73 76
 			LOG(L_WARN, "WARNING: receive_msg: "
74 77
 					"error while trying script\n");
75 78
 			goto error;
76 79
 		}
77
-		DBG("succesfully ran routing scripts...\n");
80
+#ifdef STATS
81
+		gettimeofday( & tve, &tz );
82
+		diff = (tve.tv_sec-tvb.tv_sec)*1000000+(tve.tv_usec-tvb.tv_usec);
83
+		stats->processed_requests++;
84
+		stats->acc_req_time += diff;
85
+		DBG("succesfully ran routing scripts...(%d usec)\n", diff);
78 86
 		STATS_RX_REQUEST( msg->first_line.u.request.method_value );
87
+#endif
79 88
 	}else if (msg->first_line.type==SIP_REPLY){
80 89
 		DBG("msg= reply\n");
81 90
 		/* sanity checks */
... ...
@@ -91,7 +104,10 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
91 91
 		}
92 92
 		/* check if via1 == us */
93 93
 
94
+#ifdef STATS
95
+		gettimeofday( & tvb, &tz );
94 96
 		STATS_RX_RESPONSE ( msg->first_line.u.reply.statusclass );
97
+#endif
95 98
 		
96 99
 		/* send the msg */
97 100
 		if (forward_reply(msg)==0){
... ...
@@ -99,6 +115,13 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
99 99
 						msg->via2->host.s,
100 100
 						(unsigned short) msg->via2->port);
101 101
 		}
102
+#ifdef STATS
103
+		gettimeofday( & tve, &tz );
104
+		diff = (tve.tv_sec-tvb.tv_sec)*1000000+(tve.tv_usec-tvb.tv_usec);
105
+		stats->processed_responses++;
106
+		stats->acc_res_time+=diff;
107
+		DBG("succesfully ran reply processing...(%d usec)\n", diff);
108
+#endif
102 109
 	}
103 110
 #ifdef STATS
104 111
 	skipped = 0;
... ...
@@ -116,6 +116,11 @@ struct stats_s {
116 116
 	sent_responses_5,
117 117
 	sent_responses_6,
118 118
 
119
+	processed_requests,
120
+	processed_responses,
121
+	acc_req_time,
122
+	acc_res_time,
123
+
119 124
 	failed_on_send;			
120 125
 			  
121 126
 };
... ...
@@ -8,9 +8,10 @@ debug=1          # debug level (cmd line: -dddddddddd)
8 8
 check_via=yes     # (cmd. line: -v)
9 9
 dns=on           # (cmd. line: -r)
10 10
 rev_dns=yes      # (cmd. line: -R)
11
-fork=yes          # (cmd. line: -D)
11
+#fork=yes          # (cmd. line: -D)
12
+fork=no
12 13
 children=16
13
-#log_stderror=yes # (cmd line: -E)
14
+log_stderror=yes # (cmd line: -E)
14 15
 log_stderror=no	# (cmd line: -E)
15 16
 port=5080
16 17
 #listen=127.0.0.1
... ...
@@ -4,7 +4,7 @@
4 4
 #
5 5
 
6 6
 
7
-debug=9          # debug level (cmd line: -dddddddddd)
7
+debug=3          # debug level (cmd line: -dddddddddd)
8 8
 log_stderror=yes # (cmd line: -E)
9 9
 check_via=yes     # (cmd. line: -v)
10 10
 dns=on           # (cmd. line: -r)
... ...
@@ -20,7 +20,12 @@ loop_checks=1
20 20
 loadmodule "modules/print/print.so"
21 21
 #loadmodule "modules/tm/tm.so"
22 22
 
23
-route{
23
+route[0] {
24
+	forward(195.37.78.146, 5060);
25
+	drop;
26
+}
27
+
28
+route[1]{
24 29
 	if ( t_lookup_request()) {
25 30
 		if ( method=="ACK" )	{
26 31
 			t_release();