Browse Source

nasty stats added

Jiri Kuthan 24 years ago
parent
commit
5b253cc661
6 changed files with 58 additions and 66 deletions
  1. 13 2
      forward.c
  2. 10 0
      main.c
  3. 6 3
      profile/launch.sh
  4. 1 61
      profile/profile.cfg
  5. 10 0
      receive.c
  6. 18 0
      stats.h

+ 13 - 2
forward.c

@@ -28,7 +28,7 @@
 #define MAX_VIA_LINE_SIZE      240
 #define MAX_VIA_LINE_SIZE      240
 #define MAX_RECEIVED_SIZE  57
 #define MAX_RECEIVED_SIZE  57
 
 
-
+#include "stats.h"
 
 
 /* checks if ip is in host(name) and ?host(ip)=name? 
 /* checks if ip is in host(name) and ?host(ip)=name? 
  * ip must be in network byte order!
  * ip must be in network byte order!
@@ -333,12 +333,14 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
 
 
 	p->tx++;
 	p->tx++;
 	p->tx_bytes+=new_len;
 	p->tx_bytes+=new_len;
+	stats.total_tx++;
+
 	if (udp_send(new_buf, new_len, (struct sockaddr*) to,
 	if (udp_send(new_buf, new_len, (struct sockaddr*) to,
 				sizeof(struct sockaddr_in))==-1){
 				sizeof(struct sockaddr_in))==-1){
 			p->errors++;
 			p->errors++;
 			p->ok=0;
 			p->ok=0;
 			goto error;
 			goto error;
-	}
+	} else stats.ok_tx_rq++;
 
 
 	free(new_buf);
 	free(new_buf);
 	free(to);
 	free(to);
@@ -435,10 +437,19 @@ int forward_reply(struct sip_msg* msg)
 	to->sin_family = AF_INET;
 	to->sin_family = AF_INET;
 	to->sin_port = (msg->via2.port)?htons(msg->via2.port):htons(SIP_PORT);
 	to->sin_port = (msg->via2.port)?htons(msg->via2.port):htons(SIP_PORT);
 	to->sin_addr.s_addr=*((long*)he->h_addr_list[0]);
 	to->sin_addr.s_addr=*((long*)he->h_addr_list[0]);
+
+
+
+
+
+
+
 	
 	
+	stats.total_tx++;
 	if (udp_send(new_buf,new_len, (struct sockaddr*) to, 
 	if (udp_send(new_buf,new_len, (struct sockaddr*) to, 
 					sizeof(struct sockaddr_in))==-1)
 					sizeof(struct sockaddr_in))==-1)
 		goto error;
 		goto error;
+	else stats.ok_tx_rs++;
 	
 	
 	free(new_buf);
 	free(new_buf);
 	free(to);
 	free(to);

+ 10 - 0
main.c

@@ -21,6 +21,7 @@
 #include "globals.h"
 #include "globals.h"
 
 
 #include <signal.h>
 #include <signal.h>
+#include "stats.h"
 
 
 
 
 
 
@@ -112,6 +113,9 @@ int process_no = 0;
 /* cfg parsing */
 /* cfg parsing */
 int cfg_errors=0;
 int cfg_errors=0;
 
 
+/* jku: RX/TX statistics -- remember, they are process specific */
+struct stats_s stats;
+
 
 
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
 		    (normally it shouldn't  be bigger  than 3) */
 		    (normally it shouldn't  be bigger  than 3) */
@@ -222,6 +226,9 @@ int main_loop()
 static void sig_usr(int signo)
 static void sig_usr(int signo)
 {
 {
 	DPrint("INT received, program terminates\n");
 	DPrint("INT received, program terminates\n");
+	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",
+		stats.ok_rx_rq, stats.ok_rx_rs, stats.ok_tx_rq, stats.ok_tx_rs, stats.total_rx, stats.total_tx );
+	DPrint("Thank you for flying ser\n");
 	exit(0);
 	exit(0);
 }
 }
 	
 	
@@ -370,6 +377,9 @@ int main(int argc, char** argv)
 				strlen(myname.nodename)+1);
 				strlen(myname.nodename)+1);
 		addresses_no++;
 		addresses_no++;
 	}
 	}
+
+	/* jku: initialize statistic */
+ 	memset(&stats,0,sizeof(struct stats_s));
 	
 	
 	/* get ips */
 	/* get ips */
 	printf("Listening on ");
 	printf("Listening on ");

+ 6 - 3
profile/launch.sh

@@ -9,9 +9,12 @@ MYFN="eat_line|eat_space|eat_token"
 # set to non-zero if only a report is to be generated
 # set to non-zero if only a report is to be generated
 #REPONLY=tru
 #REPONLY=tru
 
 
+CONFIG=profile.cfg
+
 SRD=${HOME}/sip_router
 SRD=${HOME}/sip_router
 PRO=${SRD}/profile
 PRO=${SRD}/profile
 REP=$PRO/$PREF.txt
 REP=$PRO/$PREF.txt
+EXEC=ser
 
 
 
 
 function usage()
 function usage()
@@ -48,15 +51,15 @@ j=`expr $j + 1`
 
 
 echo "*** Entering cycle $j"
 echo "*** Entering cycle $j"
 
 
-/usr/bin/time --output="$PRO/${PREF}-${i}-time.txt" ${SRD}/sip_router  -l 192.168.99.100 -D -E -d -f ${PRO}/profile.cfg  &
+/usr/bin/time --output="$PRO/${PREF}-${i}-time.txt" ${SRD}/$EXEC -l 192.168.99.100 -D -E -d -f ${PRO}/$CONFIG &
 
 
 #rsh -l jku benetnash.fokus.gmd.de 'nohup bin/sock -s -u 5060 '
 #rsh -l jku benetnash.fokus.gmd.de 'nohup bin/sock -s -u 5060 '
 
 
 rsh -l jku alioth.fokus.gmd.de 'nohup tmp/sipp/start.sh '
 rsh -l jku alioth.fokus.gmd.de 'nohup tmp/sipp/start.sh '
 
 
-killall -INT sip_router
+killall -INT $EXEC
 
 
-gprof sip_router > $PRO/${PREF}-${i}.txt
+gprof $EXEC > $PRO/${PREF}-${i}.txt
 
 
 done
 done
 }
 }

+ 1 - 61
profile/profile.cfg

@@ -2,67 +2,7 @@
 ####################################################################################
 ####################################################################################
 
 
 route[0] {
 route[0] {
-# request for iptel.org with IP address in it ... fix it and proceed
-# note: may result in troubles as authentication covers URI
-uri=~"^sip:.*195\.37\.77\.101" rewritehost("iptel.org"); route(1);
 
 
-# request for iptel.org ... proceed
-uri=~"iptel.org" route(1);
-
-# requests to somewhere else
-# - REGISTERs denied
-method=="REGISTER" log("attempt to relay REGISTERs"); drop;
-
-# - anything else relayed via our outbound proxy
-uri=~"."  forward("benetnash.fokus.gmd.de", 9);
-}
-
-
-# iptel.org traffic
-####################################################################################
-
-route [1] {
-
-# recognize traffic we want to authenticate -- handled first to make sure 
-# it will be captured before we proceed to non-authenticating routes;
-# authentication for registrations or calls via Telekom which start
-# with optional + and 0
-
-#PROFILE
-(method=='REGISTER' | uri=~"sip:+?0[0-9]*@iptel\.org") forward("benetnash.fokus.gmd.de", 9);
-
-# dealing with voicemail 
-# we need to switch traffic to voicemail directly before CSPS
-# would screw it up -- it cannot deal with port numbers
-
-(uri=~'mail.iptel.org' | uri=~'iptel.org:6060' ) forward("benetnash.fokus.gmd.de", 9);
-
-# default route: go to non-authenicating proxy
-#PROFILE
-(method=~".")					forward("benetnash.fokus.gmd.de", 9 );
+forward( uri:host, uri:port );
 
 
 }
 }
-
-# We split traffic to authenticating and non-authenticating
-# SIP proxies here using sip_router. We only authenticate REGISTERs
-# and PSTN destinations, everything else is not authenticated.
-#
-# This is a work-around for CSPS's authenticate all-or-nothing
-# policy which would eliminate non-iptel.org users calling us.
-# Both proxies run at separate hosts (because they would otherwise
-# conflict with each other).
-#
-# I chose to put the non-authentication proxy on the public host
-# because we use it for outbound routing -- that would not work
-# if the proxy would be in non-routable realm. Drawback:
-# SQL and Cisco synchronization noise between dog and fox.
-# Note that this
-# leaves a non-authenticating port 5060 which could be misued
-# to steal REGISTERs. It would be perhaps a good idea to make
-# it available only for requests from sip_router.
-#
-#                        /--REGISTERs----dog:5061,w/auth
-#      iptel.org:5060---/                             ||   proprietary Cisco contact DB sharing
-#                        \                            ||   and MySQL
-#                        \---anything_else----iptel.org:5061,w/o/auth
-

+ 10 - 0
receive.c

@@ -12,14 +12,19 @@
 #include "forward.h"
 #include "forward.h"
 #include "action.h"
 #include "action.h"
 
 
+
 #ifdef DEBUG_DMALLOC
 #ifdef DEBUG_DMALLOC
 #include <dmalloc.h>
 #include <dmalloc.h>
 #endif
 #endif
 
 
+#include "stats.h"
+
 int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 {
 {
 	struct sip_msg msg;
 	struct sip_msg msg;
 
 
+	stats.total_rx++;	
+
 	memset(&msg,0, sizeof(struct sip_msg)); /* init everything to 0 */
 	memset(&msg,0, sizeof(struct sip_msg)); /* init everything to 0 */
 	/* fill in msg */
 	/* fill in msg */
 	msg.buf=buf;
 	msg.buf=buf;
@@ -52,6 +57,8 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 					"error while trying script\n");
 					"error while trying script\n");
 			goto error;
 			goto error;
 		}
 		}
+		/* jku -- update statistics  */
+		else stats.ok_rx_rq++;	
 	}else if (msg.first_line.type==SIP_REPLY){
 	}else if (msg.first_line.type==SIP_REPLY){
 		/* sanity checks */
 		/* sanity checks */
 		if (msg.via1.error!=VIA_PARSE_OK){
 		if (msg.via1.error!=VIA_PARSE_OK){
@@ -63,6 +70,9 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 			goto skip;
 			goto skip;
 		}
 		}
 		/* check if via1 == us */
 		/* check if via1 == us */
+
+		/* jku -- update statistics  */
+		stats.ok_rx_rs++;	
 		
 		
 		/* send the msg */
 		/* send the msg */
 		if (forward_reply(&msg)==0){
 		if (forward_reply(&msg)==0){

+ 18 - 0
stats.h

@@ -0,0 +1,18 @@
+#ifndef stats_h
+#define stats_h
+
+struct stats_s {
+
+	/* total/valid, received/sent, request/response */
+	unsigned long 	ok_rx_rq,
+			ok_rx_rs,
+			ok_tx_rq,
+			ok_tx_rs,
+			total_rx,
+			total_tx;
+};
+
+
+extern struct stats_s stats;
+
+#endif