Browse code

nasty stats added

Jiri Kuthan authored on 07/11/2001 18:41:08
Showing 6 changed files
... ...
@@ -28,7 +28,7 @@
28 28
 #define MAX_VIA_LINE_SIZE      240
29 29
 #define MAX_RECEIVED_SIZE  57
30 30
 
31
-
31
+#include "stats.h"
32 32
 
33 33
 /* checks if ip is in host(name) and ?host(ip)=name? 
34 34
  * ip must be in network byte order!
... ...
@@ -333,12 +333,14 @@ 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
+	stats.total_tx++;
337
+
336 338
 	if (udp_send(new_buf, new_len, (struct sockaddr*) to,
337 339
 				sizeof(struct sockaddr_in))==-1){
338 340
 			p->errors++;
339 341
 			p->ok=0;
340 342
 			goto error;
341
-	}
343
+	} else stats.ok_tx_rq++;
342 344
 
343 345
 	free(new_buf);
344 346
 	free(to);
... ...
@@ -435,10 +437,19 @@ int forward_reply(struct sip_msg* msg)
435 435
 	to->sin_family = AF_INET;
436 436
 	to->sin_port = (msg->via2.port)?htons(msg->via2.port):htons(SIP_PORT);
437 437
 	to->sin_addr.s_addr=*((long*)he->h_addr_list[0]);
438
+
439
+
440
+
441
+
442
+
443
+
444
+
438 445
 	
446
+	stats.total_tx++;
439 447
 	if (udp_send(new_buf,new_len, (struct sockaddr*) to, 
440 448
 					sizeof(struct sockaddr_in))==-1)
441 449
 		goto error;
450
+	else stats.ok_tx_rs++;
442 451
 	
443 452
 	free(new_buf);
444 453
 	free(to);
... ...
@@ -21,6 +21,7 @@
21 21
 #include "globals.h"
22 22
 
23 23
 #include <signal.h>
24
+#include "stats.h"
24 25
 
25 26
 
26 27
 
... ...
@@ -112,6 +113,9 @@ int process_no = 0;
112 112
 /* cfg parsing */
113 113
 int cfg_errors=0;
114 114
 
115
+/* jku: RX/TX statistics -- remember, they are process specific */
116
+struct stats_s stats;
117
+
115 118
 
116 119
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
117 120
 		    (normally it shouldn't  be bigger  than 3) */
... ...
@@ -222,6 +226,9 @@ int main_loop()
222 222
 static void sig_usr(int signo)
223 223
 {
224 224
 	DPrint("INT received, program terminates\n");
225
+	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",
226
+		stats.ok_rx_rq, stats.ok_rx_rs, stats.ok_tx_rq, stats.ok_tx_rs, stats.total_rx, stats.total_tx );
227
+	DPrint("Thank you for flying ser\n");
225 228
 	exit(0);
226 229
 }
227 230
 	
... ...
@@ -370,6 +377,9 @@ int main(int argc, char** argv)
370 370
 				strlen(myname.nodename)+1);
371 371
 		addresses_no++;
372 372
 	}
373
+
374
+	/* jku: initialize statistic */
375
+ 	memset(&stats,0,sizeof(struct stats_s));
373 376
 	
374 377
 	/* get ips */
375 378
 	printf("Listening on ");
... ...
@@ -9,9 +9,12 @@ MYFN="eat_line|eat_space|eat_token"
9 9
 # set to non-zero if only a report is to be generated
10 10
 #REPONLY=tru
11 11
 
12
+CONFIG=profile.cfg
13
+
12 14
 SRD=${HOME}/sip_router
13 15
 PRO=${SRD}/profile
14 16
 REP=$PRO/$PREF.txt
17
+EXEC=ser
15 18
 
16 19
 
17 20
 function usage()
... ...
@@ -48,15 +51,15 @@ j=`expr $j + 1`
48 48
 
49 49
 echo "*** Entering cycle $j"
50 50
 
51
-/usr/bin/time --output="$PRO/${PREF}-${i}-time.txt" ${SRD}/sip_router  -l 192.168.99.100 -D -E -d -f ${PRO}/profile.cfg  &
51
+/usr/bin/time --output="$PRO/${PREF}-${i}-time.txt" ${SRD}/$EXEC -l 192.168.99.100 -D -E -d -f ${PRO}/$CONFIG &
52 52
 
53 53
 #rsh -l jku benetnash.fokus.gmd.de 'nohup bin/sock -s -u 5060 '
54 54
 
55 55
 rsh -l jku alioth.fokus.gmd.de 'nohup tmp/sipp/start.sh '
56 56
 
57
-killall -INT sip_router
57
+killall -INT $EXEC
58 58
 
59
-gprof sip_router > $PRO/${PREF}-${i}.txt
59
+gprof $EXEC > $PRO/${PREF}-${i}.txt
60 60
 
61 61
 done
62 62
 }
... ...
@@ -2,67 +2,7 @@
2 2
 ####################################################################################
3 3
 
4 4
 route[0] {
5
-# request for iptel.org with IP address in it ... fix it and proceed
6
-# note: may result in troubles as authentication covers URI
7
-uri=~"^sip:.*195\.37\.77\.101" rewritehost("iptel.org"); route(1);
8 5
 
9
-# request for iptel.org ... proceed
10
-uri=~"iptel.org" route(1);
11
-
12
-# requests to somewhere else
13
-# - REGISTERs denied
14
-method=="REGISTER" log("attempt to relay REGISTERs"); drop;
15
-
16
-# - anything else relayed via our outbound proxy
17
-uri=~"."  forward("benetnash.fokus.gmd.de", 9);
18
-}
19
-
20
-
21
-# iptel.org traffic
22
-####################################################################################
23
-
24
-route [1] {
25
-
26
-# recognize traffic we want to authenticate -- handled first to make sure 
27
-# it will be captured before we proceed to non-authenticating routes;
28
-# authentication for registrations or calls via Telekom which start
29
-# with optional + and 0
30
-
31
-#PROFILE
32
-(method=='REGISTER' | uri=~"sip:+?0[0-9]*@iptel\.org") forward("benetnash.fokus.gmd.de", 9);
33
-
34
-# dealing with voicemail 
35
-# we need to switch traffic to voicemail directly before CSPS
36
-# would screw it up -- it cannot deal with port numbers
37
-
38
-(uri=~'mail.iptel.org' | uri=~'iptel.org:6060' ) forward("benetnash.fokus.gmd.de", 9);
39
-
40
-# default route: go to non-authenicating proxy
41
-#PROFILE
42
-(method=~".")					forward("benetnash.fokus.gmd.de", 9 );
6
+forward( uri:host, uri:port );
43 7
 
44 8
 }
45
-
46
-# We split traffic to authenticating and non-authenticating
47
-# SIP proxies here using sip_router. We only authenticate REGISTERs
48
-# and PSTN destinations, everything else is not authenticated.
49
-#
50
-# This is a work-around for CSPS's authenticate all-or-nothing
51
-# policy which would eliminate non-iptel.org users calling us.
52
-# Both proxies run at separate hosts (because they would otherwise
53
-# conflict with each other).
54
-#
55
-# I chose to put the non-authentication proxy on the public host
56
-# because we use it for outbound routing -- that would not work
57
-# if the proxy would be in non-routable realm. Drawback:
58
-# SQL and Cisco synchronization noise between dog and fox.
59
-# Note that this
60
-# leaves a non-authenticating port 5060 which could be misued
61
-# to steal REGISTERs. It would be perhaps a good idea to make
62
-# it available only for requests from sip_router.
63
-#
64
-#                        /--REGISTERs----dog:5061,w/auth
65
-#      iptel.org:5060---/                             ||   proprietary Cisco contact DB sharing
66
-#                        \                            ||   and MySQL
67
-#                        \---anything_else----iptel.org:5061,w/o/auth
68
-
... ...
@@ -12,14 +12,19 @@
12 12
 #include "forward.h"
13 13
 #include "action.h"
14 14
 
15
+
15 16
 #ifdef DEBUG_DMALLOC
16 17
 #include <dmalloc.h>
17 18
 #endif
18 19
 
20
+#include "stats.h"
21
+
19 22
 int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
20 23
 {
21 24
 	struct sip_msg msg;
22 25
 
26
+	stats.total_rx++;	
27
+
23 28
 	memset(&msg,0, sizeof(struct sip_msg)); /* init everything to 0 */
24 29
 	/* fill in msg */
25 30
 	msg.buf=buf;
... ...
@@ -52,6 +57,8 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
52 52
 					"error while trying script\n");
53 53
 			goto error;
54 54
 		}
55
+		/* jku -- update statistics  */
56
+		else stats.ok_rx_rq++;	
55 57
 	}else if (msg.first_line.type==SIP_REPLY){
56 58
 		/* sanity checks */
57 59
 		if (msg.via1.error!=VIA_PARSE_OK){
... ...
@@ -63,6 +70,9 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
63 63
 			goto skip;
64 64
 		}
65 65
 		/* check if via1 == us */
66
+
67
+		/* jku -- update statistics  */
68
+		stats.ok_rx_rs++;	
66 69
 		
67 70
 		/* send the msg */
68 71
 		if (forward_reply(&msg)==0){
69 72
new file mode 100644
... ...
@@ -0,0 +1,18 @@
0
+#ifndef stats_h
1
+#define stats_h
2
+
3
+struct stats_s {
4
+
5
+	/* total/valid, received/sent, request/response */
6
+	unsigned long 	ok_rx_rq,
7
+			ok_rx_rs,
8
+			ok_tx_rq,
9
+			ok_tx_rs,
10
+			total_rx,
11
+			total_tx;
12
+};
13
+
14
+
15
+extern struct stats_s stats;
16
+
17
+#endif