Browse code

tested and ifdef-ed the Stats hack; to be done:L put it in shmem

Jiri Kuthan authored on 07/11/2001 19:52:42
Showing 6 changed files
... ...
@@ -21,7 +21,9 @@ NAME=ser
21 21
 # MACROEATER replaces frequently called parser helper functions
22 22
 # with macros
23 23
 # recommanded: on (speed-up)
24
-DEFS=-DNOCR -DMACROEATER
24
+# STATS allows to print out number of packets processed on CTRL-C; implementation
25
+#  still nasty and reports per-process
26
+DEFS=-DNOCR -DMACROEATER -DSTATS
25 27
 
26 28
 # platform dependent settings
27 29
 
... ...
@@ -28,7 +28,9 @@
28 28
 #define MAX_VIA_LINE_SIZE      240
29 29
 #define MAX_RECEIVED_SIZE  57
30 30
 
31
+#ifdef STATS
31 32
 #include "stats.h"
33
+#endif
32 34
 
33 35
 /* checks if ip is in host(name) and ?host(ip)=name? 
34 36
  * ip must be in network byte order!
... ...
@@ -333,14 +335,19 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
333 333
 
334 334
 	p->tx++;
335 335
 	p->tx_bytes+=new_len;
336
+#ifdef STATS
336 337
 	stats.total_tx++;
338
+#endif
337 339
 
338 340
 	if (udp_send(new_buf, new_len, (struct sockaddr*) to,
339 341
 				sizeof(struct sockaddr_in))==-1){
340 342
 			p->errors++;
341 343
 			p->ok=0;
342 344
 			goto error;
343
-	} else stats.ok_tx_rq++;
345
+	} 
346
+#ifdef STATS
347
+	else stats.ok_tx_rq++;
348
+#endif
344 349
 
345 350
 	free(new_buf);
346 351
 	free(to);
... ...
@@ -445,11 +452,15 @@ int forward_reply(struct sip_msg* msg)
445 445
 
446 446
 
447 447
 	
448
+#ifdef STATS
448 449
 	stats.total_tx++;
450
+#endif
449 451
 	if (udp_send(new_buf,new_len, (struct sockaddr*) to, 
450 452
 					sizeof(struct sockaddr_in))==-1)
451 453
 		goto error;
454
+#ifdef STATS
452 455
 	else stats.ok_tx_rs++;
456
+#endif
453 457
 	
454 458
 	free(new_buf);
455 459
 	free(to);
... ...
@@ -21,7 +21,10 @@
21 21
 #include "globals.h"
22 22
 
23 23
 #include <signal.h>
24
+
25
+#ifdef STATS
24 26
 #include "stats.h"
27
+#endif
25 28
 
26 29
 
27 30
 
... ...
@@ -113,8 +116,10 @@ int process_no = 0;
113 113
 /* cfg parsing */
114 114
 int cfg_errors=0;
115 115
 
116
+#ifdef STATS
116 117
 /* jku: RX/TX statistics -- remember, they are process specific */
117 118
 struct stats_s stats;
119
+#endif
118 120
 
119 121
 
120 122
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
... ...
@@ -226,9 +231,11 @@ int main_loop()
226 226
 static void sig_usr(int signo)
227 227
 {
228 228
 	DPrint("INT received, program terminates\n");
229
+#ifdef STATS
229 230
 	DPrint("ok_rx_rq\t%d\nok_rx_rs\t%d\nok_tx_rq\t%d\nok_tx_rs\t%d\ntotal_rx\t%d\ntotal_tx\t%d\n\n",
230 231
 		stats.ok_rx_rq, stats.ok_rx_rs, stats.ok_tx_rq, stats.ok_tx_rs, stats.total_rx, stats.total_tx );
231 232
 	DPrint("Thank you for flying ser\n");
233
+#endif
232 234
 	exit(0);
233 235
 }
234 236
 	
... ...
@@ -378,8 +385,10 @@ int main(int argc, char** argv)
378 378
 		addresses_no++;
379 379
 	}
380 380
 
381
+#ifdef STATS
381 382
 	/* jku: initialize statistic */
382 383
  	memset(&stats,0,sizeof(struct stats_s));
384
+#endif
383 385
 	
384 386
 	/* get ips */
385 387
 	printf("Listening on ");
... ...
@@ -1,8 +1,10 @@
1 1
 # first sort out iptel.org requests from those destined somewhere else
2 2
 ####################################################################################
3 3
 
4
+port=5080
5
+
4 6
 route[0] {
5 7
 
6
-forward( uri:host, uri:port );
8
+forward( 127.0.0.1, 9 );
7 9
 
8 10
 }
... ...
@@ -17,13 +17,17 @@
17 17
 #include <dmalloc.h>
18 18
 #endif
19 19
 
20
+#ifdef STATS
20 21
 #include "stats.h"
22
+#endif
21 23
 
22 24
 int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
23 25
 {
24 26
 	struct sip_msg msg;
25 27
 
28
+#ifdef STATS
26 29
 	stats.total_rx++;	
30
+#endif
27 31
 
28 32
 	memset(&msg,0, sizeof(struct sip_msg)); /* init everything to 0 */
29 33
 	/* fill in msg */
... ...
@@ -57,8 +61,10 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
57 57
 					"error while trying script\n");
58 58
 			goto error;
59 59
 		}
60
+#ifdef STATS
60 61
 		/* jku -- update statistics  */
61 62
 		else stats.ok_rx_rq++;	
63
+#endif
62 64
 	}else if (msg.first_line.type==SIP_REPLY){
63 65
 		/* sanity checks */
64 66
 		if (msg.via1.error!=VIA_PARSE_OK){
... ...
@@ -71,8 +77,10 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
71 71
 		}
72 72
 		/* check if via1 == us */
73 73
 
74
+#ifdef STATS
74 75
 		/* jku -- update statistics  */
75 76
 		stats.ok_rx_rs++;	
77
+#endif
76 78
 		
77 79
 		/* send the msg */
78 80
 		if (forward_reply(&msg)==0){
... ...
@@ -1,6 +1,8 @@
1 1
 #ifndef stats_h
2 2
 #define stats_h
3 3
 
4
+#ifdef STATS
5
+
4 6
 struct stats_s {
5 7
 
6 8
 	/* total/valid, received/sent, request/response */
... ...
@@ -16,3 +18,5 @@ struct stats_s {
16 16
 extern struct stats_s stats;
17 17
 
18 18
 #endif
19
+
20
+#endif