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 335
 
334 336
 	p->tx++;
335 337
 	p->tx_bytes+=new_len;
338
+#ifdef STATS
336 339
 	stats.total_tx++;
340
+#endif
337 341
 
338 342
 	if (udp_send(new_buf, new_len, (struct sockaddr*) to,
339 343
 				sizeof(struct sockaddr_in))==-1){
340 344
 			p->errors++;
341 345
 			p->ok=0;
342 346
 			goto error;
343
-	} else stats.ok_tx_rq++;
347
+	} 
348
+#ifdef STATS
349
+	else stats.ok_tx_rq++;
350
+#endif
344 351
 
345 352
 	free(new_buf);
346 353
 	free(to);
... ...
@@ -445,11 +452,15 @@ int forward_reply(struct sip_msg* msg)
445 452
 
446 453
 
447 454
 	
455
+#ifdef STATS
448 456
 	stats.total_tx++;
457
+#endif
449 458
 	if (udp_send(new_buf,new_len, (struct sockaddr*) to, 
450 459
 					sizeof(struct sockaddr_in))==-1)
451 460
 		goto error;
461
+#ifdef STATS
452 462
 	else stats.ok_tx_rs++;
463
+#endif
453 464
 	
454 465
 	free(new_buf);
455 466
 	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 116
 /* cfg parsing */
114 117
 int cfg_errors=0;
115 118
 
119
+#ifdef STATS
116 120
 /* jku: RX/TX statistics -- remember, they are process specific */
117 121
 struct stats_s stats;
122
+#endif
118 123
 
119 124
 
120 125
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
... ...
@@ -226,9 +231,11 @@ int main_loop()
226 231
 static void sig_usr(int signo)
227 232
 {
228 233
 	DPrint("INT received, program terminates\n");
234
+#ifdef STATS
229 235
 	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 236
 		stats.ok_rx_rq, stats.ok_rx_rs, stats.ok_tx_rq, stats.ok_tx_rs, stats.total_rx, stats.total_tx );
231 237
 	DPrint("Thank you for flying ser\n");
238
+#endif
232 239
 	exit(0);
233 240
 }
234 241
 	
... ...
@@ -378,8 +385,10 @@ int main(int argc, char** argv)
378 385
 		addresses_no++;
379 386
 	}
380 387
 
388
+#ifdef STATS
381 389
 	/* jku: initialize statistic */
382 390
  	memset(&stats,0,sizeof(struct stats_s));
391
+#endif
383 392
 	
384 393
 	/* get ips */
385 394
 	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 61
 					"error while trying script\n");
58 62
 			goto error;
59 63
 		}
64
+#ifdef STATS
60 65
 		/* jku -- update statistics  */
61 66
 		else stats.ok_rx_rq++;	
67
+#endif
62 68
 	}else if (msg.first_line.type==SIP_REPLY){
63 69
 		/* sanity checks */
64 70
 		if (msg.via1.error!=VIA_PARSE_OK){
... ...
@@ -71,8 +77,10 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
71 77
 		}
72 78
 		/* check if via1 == us */
73 79
 
80
+#ifdef STATS
74 81
 		/* jku -- update statistics  */
75 82
 		stats.ok_rx_rs++;	
83
+#endif
76 84
 		
77 85
 		/* send the msg */
78 86
 		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 18
 extern struct stats_s stats;
17 19
 
18 20
 #endif
21
+
22
+#endif