Browse Source

- new test utility & configs

Andrei Pelinescu-Onciul 23 years ago
parent
commit
6665655c70
6 changed files with 336 additions and 2 deletions
  1. 33 0
      test/flood.cfg
  2. 40 0
      test/locking/test_results.txt
  3. 1 1
      test/stateless.cfg
  4. 56 0
      test/test.c
  5. 205 0
      test/udp_test_proxy.c
  6. 1 1
      udp_server.c

+ 33 - 0
test/flood.cfg

@@ -0,0 +1,33 @@
+#
+# configuration for TurboSIP testing
+#
+# $ID: $
+#
+
+
+debug=3          # debug level (cmd line: -dddddddddd)
+#fork=yes          # (cmd. line: -D)
+fork=yes
+fork=no
+log_stderror=yes # (cmd line: -E)
+#log_stderror=no	# (cmd line: -E)
+
+
+children=4
+check_via=no     # (cmd. line: -v)
+dns=off           # (cmd. line: -r)
+rev_dns=off      # (cmd. line: -R)
+#port=5070
+listen=10.0.0.179
+#listen=127.0.0.1
+#listen=192.168.57.33
+loop_checks=0
+# for more info: sip_router -h
+
+#modules
+
+
+route{
+	#forward(uri:host, uri:port);
+	forward(127.0.0.1, 5090);
+}

+ 40 - 0
test/locking/test_results.txt

@@ -0,0 +1,40 @@
+
+
+			nolock		flock		sysv		posix		pmutex		fastl
+
+Linux 2* Athlon 1200, 2.4.16:
+real		0.044/		 14.713		  9.330		  2.670		  1.730		 0.400
+user		0.040		  2.610		  2.950		  2.670		  1.720		 0.400
+sys			0.000		 12.110		  6.370		  0.000		  0.010		 0.000
+*			1			334.386		212.045		 60.681		 39.318		 9.090
+
+Linux 2*PIII, 2.4.17:
+real		0.056		 17.771		 14.476		  3.099		  1.902		 0.603
+user		0.050		  4.130		  5.120		  3.100		  1.900		 0.600
+sys			0.000		 13.650		  9.350		  0.000		  0.000		 0.000
+*			1			317.339		258.500		 55.339		 33.964		10.767
+
+Solaris 8:
+real		0.105		n/a			 48.490		 27.492		  3.602		 1.284
+user		0.090		n/a			 29.330		 27.410		  3.590		 1.270
+sys			0.010		n/a			 19.110		 0.010		  0.010		 0.020
+*			1			n/a			461.809		257.142		 34.304		12.228
+
+FreeBSD, PII 333:
+real:		0.147		 43.952		  54.428	 37.385		 15.706		 1.863
+user:		0.121		 12.761		  13.131	 31.958		 13.402		 1.606
+sys:		0.001		 25.149		  33.732	  0.017		  0.017		 0.001
+*			1  			299.061		 370.258	254.319		106.843		12.673
+
+
+nolock= no locking, just a loop
+flock= using flock
+sysv = using SYSV semaphores
+posix = using POSIX1003.1b semaphores (sem_wait, sem_post)
+pmutex = using pthread_mutex*
+fastl = using fastlock.h from ser (hand made assembler locks)
+
+Test: time ./locking_test* -c 10000000
+(sip_router/test/locking/*)
+
+

+ 1 - 1
test/stateless.cfg

@@ -8,7 +8,7 @@
 debug=3          # debug level (cmd line: -dddddddddd)
 #fork=yes          # (cmd. line: -D)
 fork=yes
-#fork=no
+fork=no
 log_stderror=yes # (cmd line: -E)
 #log_stderror=no	# (cmd line: -E)
 

+ 56 - 0
test/test.c

@@ -0,0 +1,56 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <errno.h>
+#include <arpa/inet.h>
+
+
+#define LOOP_COUNT 100
+#define PORT 5060
+#define SEND_PORT 5090
+#define SEND_ADDR 0x0a000022 /*10.0.0.34*/   /*   0x7f000001 127.0.0.1*/
+#define BUF_SIZE 65535
+static char buf[BUF_SIZE];
+
+int main(char** argv, int argn)
+{
+	int sock;
+	struct sockaddr_in addr;
+	struct sockaddr_in to;
+	int r, len;
+
+	printf("starting\n");
+	
+	addr.sin_family=AF_INET;
+	addr.sin_port=htons(PORT);
+	addr.sin_addr.s_addr=INADDR_ANY;
+	to.sin_family=AF_INET;
+	to.sin_port=htons(SEND_PORT);
+	to.sin_addr.s_addr=htonl(SEND_ADDR);
+		
+
+	sock=socket(PF_INET, SOCK_DGRAM,0);
+	if (bind(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr_in))==-1){
+		fprintf(stderr, "ERROR: udp_init: bind: %s\n", strerror(errno));
+		exit(1);
+	}
+
+	//if (fork())
+		if (fork()){
+			close(sock);
+			for(;;) sleep(100);
+			exit(1);
+		}
+	/*children*/
+	printf("child\n");
+	for(;;){
+		len=read(sock, buf, BUF_SIZE);
+		/*for (r=0;r < LOOP_COUNT; r++);*/
+		/* send it back*/
+		sendto(sock, buf, len, 0, (struct sockaddr*) &to,
+				sizeof(struct sockaddr_in));
+	}
+}

+ 205 - 0
test/udp_test_proxy.c

@@ -0,0 +1,205 @@
+/* $Id */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <ctype.h>
+#include <netdb.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+
+
+static char *id="$Id$";
+static char *version="udp_test_proxy 0.1";
+static char* help_msg="\
+Usage: udp_test_proxy  -l address -s port -d address -p port [-n no] [-v]\n\
+Options:\n\
+    -l address    listen address\n\
+    -s port       listen(source) port\n\
+    -d address    destination address\n\
+    -p port       destination port\n\
+    -n no         number of processes\n\
+    -v            increase verbosity level\n\
+    -V            version number\n\
+    -h            this help message\n\
+";
+#define BUF_SIZE 65535
+static char buf[BUF_SIZE];
+
+int main(int argc, char** argv)
+{
+	int sock;
+	pid_t pid;
+	struct sockaddr_in addr;
+	struct sockaddr_in to;
+	int r, n, len;
+	char c;
+	struct hostent* he;
+	int verbose;
+	int sport, dport;
+	char *dst;
+	char *src;
+	char* tmp;
+
+
+	/* init */
+	verbose=0;
+	dst=0;
+	sport=dport=0;
+	src=dst=0;
+	n=0;
+	
+	opterr=0;
+	while ((c=getopt(argc,argv, "l:p:d:s:n:vhV"))!=-1){
+		switch(c){
+			case 'v':
+				verbose++;
+				break;
+			case 'd':
+				dst=optarg;
+				break;
+			case 'l':
+				src=optarg;
+				break;
+			case 'p':
+				dport=strtol(optarg, &tmp, 10);
+				if ((tmp==0)||(*tmp)){
+					fprintf(stderr, "bad port number: -p %s\n", optarg);
+					goto error;
+				}
+				break;
+			case 's':
+				sport=strtol(optarg, &tmp, 10);
+				if ((tmp==0)||(*tmp)){
+					fprintf(stderr, "bad port number: -s %s\n", optarg);
+					goto error;
+				}
+				break;
+			case 'n':
+				n=strtol(optarg, &tmp, 10);
+				if ((tmp==0)||(*tmp)){
+					fprintf(stderr, "bad process number: -n %s\n", optarg);
+					goto error;
+				}
+				break;
+			case 'V':
+				printf("version: %s\n", version);
+				printf("%s\n",id);
+				exit(0);
+				break;
+			case 'h':
+				printf("version: %s\n", version);
+				printf("%s", help_msg);
+				exit(0);
+				break;
+			case '?':
+				if (isprint(optopt))
+					fprintf(stderr, "Unknown option `-%c´\n", optopt);
+				else
+					fprintf(stderr, "Unknown character `\\x%x´\n", optopt);
+				goto error;
+			case ':':
+				fprintf(stderr, "Option `-%c´ requires an argument.\n",
+						optopt);
+				goto error;
+				break;
+			default:
+					abort();
+		}
+	}
+
+	/* check if all the required params are present */
+	if (dst==0){
+		fprintf(stderr, "Missing destination (-d ...)\n");
+		exit(-1);
+	}
+	if (src==0){
+		fprintf(stderr, "Missing listen address (-l ...)\n");
+		exit(-1);
+	}
+	if(sport==0){
+		fprintf(stderr, "Missing source port number (-s port)\n");
+		exit(-1);
+	}else if(sport<0){
+		fprintf(stderr, "Invalid source port number (-s %d)\n", sport);
+		exit(-1);
+	}
+	if(dport==0){
+		fprintf(stderr, "Missing destination port number (-p port)\n");
+		exit(-1);
+	}else if(dport<0){
+		fprintf(stderr, "Invalid destination port number (-p %d)\n", dport);
+		exit(-1);
+	}
+	if(n<0){
+		fprintf(stderr, "Invalid process no (-n %d)\n", n);
+		exit(-1);
+	}
+
+
+	/* resolve destination */
+	he=gethostbyname(dst);
+	if (he==0){
+		fprintf(stderr, "ERROR: could not resolve %s\n", dst);
+		goto error;
+	}
+
+	/* set to*/
+	to.sin_family=he->h_addrtype;
+	to.sin_port=htons(dport);
+	memcpy(&to.sin_addr.s_addr, he->h_addr_list[0], he->h_length);
+
+	/* resolve source/listen */
+	he=gethostbyname(src);
+	if (he==0){
+		fprintf(stderr, "ERROR: could not resolve %s\n", dst);
+		goto error;
+	}
+	/* open socket*/
+	addr.sin_family=he->h_addrtype;
+	addr.sin_port=htons(sport);
+	memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length);
+
+	sock = socket(he->h_addrtype, SOCK_DGRAM, 0);
+	if (sock==-1){
+		fprintf(stderr, "ERROR: socket: %s\n", strerror(errno));
+		goto error;
+	}
+	if (bind(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr_in))==-1){
+		fprintf(stderr, "ERROR: bind: %s\n", strerror(errno));
+		goto error;
+	}
+
+	for(r=1; r<n; r++){
+		if ((pid=fork())==-1){
+			fprintf(stderr, "ERROR: fork: %s\n", strerror(errno));
+			goto error;
+		}
+		if (pid==0) break; /* child, skip */
+	}
+
+	if (verbose>3) printf("process starting\n");
+	for(;;){
+		len=read(sock, buf, BUF_SIZE);
+		if (len==-1){
+			fprintf(stderr, "ERROR: read: %s\n", strerror(errno));
+			continue;
+		}
+		if (verbose>2) putchar('r');
+		/* send it back*/
+		len=sendto(sock, buf, len, 0, (struct sockaddr*) &to,
+				sizeof(struct sockaddr_in));
+		if (len==-1){
+			fprintf(stderr, "ERROR: sendto: %s\n", strerror(errno));
+			continue;
+		}
+		if (verbose>1) putchar('.');
+	}
+error:
+	exit(-1);
+}

+ 1 - 1
udp_server.c

@@ -123,7 +123,7 @@ int udp_init(unsigned long ip, unsigned short port)
 	}
 	/* set sock opts? */
 	optval=1;
-	if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEADDR,
+	if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEADDR ,
 					(void*)&optval, sizeof(optval)) ==-1)
 	{
 		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));