Browse code

- new test utility & configs

Andrei Pelinescu-Onciul authored on 15/02/2002 00:09:13
Showing 6 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,33 @@
0
+#
1
+# configuration for TurboSIP testing
2
+#
3
+# $ID: $
4
+#
5
+
6
+
7
+debug=3          # debug level (cmd line: -dddddddddd)
8
+#fork=yes          # (cmd. line: -D)
9
+fork=yes
10
+fork=no
11
+log_stderror=yes # (cmd line: -E)
12
+#log_stderror=no	# (cmd line: -E)
13
+
14
+
15
+children=4
16
+check_via=no     # (cmd. line: -v)
17
+dns=off           # (cmd. line: -r)
18
+rev_dns=off      # (cmd. line: -R)
19
+#port=5070
20
+listen=10.0.0.179
21
+#listen=127.0.0.1
22
+#listen=192.168.57.33
23
+loop_checks=0
24
+# for more info: sip_router -h
25
+
26
+#modules
27
+
28
+
29
+route{
30
+	#forward(uri:host, uri:port);
31
+	forward(127.0.0.1, 5090);
32
+}
0 33
new file mode 100644
... ...
@@ -0,0 +1,40 @@
0
+
1
+
2
+			nolock		flock		sysv		posix		pmutex		fastl
3
+
4
+Linux 2* Athlon 1200, 2.4.16:
5
+real		0.044/		 14.713		  9.330		  2.670		  1.730		 0.400
6
+user		0.040		  2.610		  2.950		  2.670		  1.720		 0.400
7
+sys			0.000		 12.110		  6.370		  0.000		  0.010		 0.000
8
+*			1			334.386		212.045		 60.681		 39.318		 9.090
9
+
10
+Linux 2*PIII, 2.4.17:
11
+real		0.056		 17.771		 14.476		  3.099		  1.902		 0.603
12
+user		0.050		  4.130		  5.120		  3.100		  1.900		 0.600
13
+sys			0.000		 13.650		  9.350		  0.000		  0.000		 0.000
14
+*			1			317.339		258.500		 55.339		 33.964		10.767
15
+
16
+Solaris 8:
17
+real		0.105		n/a			 48.490		 27.492		  3.602		 1.284
18
+user		0.090		n/a			 29.330		 27.410		  3.590		 1.270
19
+sys			0.010		n/a			 19.110		 0.010		  0.010		 0.020
20
+*			1			n/a			461.809		257.142		 34.304		12.228
21
+
22
+FreeBSD, PII 333:
23
+real:		0.147		 43.952		  54.428	 37.385		 15.706		 1.863
24
+user:		0.121		 12.761		  13.131	 31.958		 13.402		 1.606
25
+sys:		0.001		 25.149		  33.732	  0.017		  0.017		 0.001
26
+*			1  			299.061		 370.258	254.319		106.843		12.673
27
+
28
+
29
+nolock= no locking, just a loop
30
+flock= using flock
31
+sysv = using SYSV semaphores
32
+posix = using POSIX1003.1b semaphores (sem_wait, sem_post)
33
+pmutex = using pthread_mutex*
34
+fastl = using fastlock.h from ser (hand made assembler locks)
35
+
36
+Test: time ./locking_test* -c 10000000
37
+(sip_router/test/locking/*)
38
+
39
+
... ...
@@ -8,7 +8,7 @@
8 8
 debug=3          # debug level (cmd line: -dddddddddd)
9 9
 #fork=yes          # (cmd. line: -D)
10 10
 fork=yes
11
-#fork=no
11
+fork=no
12 12
 log_stderror=yes # (cmd line: -E)
13 13
 #log_stderror=no	# (cmd line: -E)
14 14
 
15 15
new file mode 100644
... ...
@@ -0,0 +1,56 @@
0
+#include <stdlib.h>
1
+#include <stdio.h>
2
+#include <string.h>
3
+#include <sys/types.h>
4
+#include <sys/socket.h>
5
+#include <netinet/in.h>
6
+#include <errno.h>
7
+#include <arpa/inet.h>
8
+
9
+
10
+#define LOOP_COUNT 100
11
+#define PORT 5060
12
+#define SEND_PORT 5090
13
+#define SEND_ADDR 0x0a000022 /*10.0.0.34*/   /*   0x7f000001 127.0.0.1*/
14
+#define BUF_SIZE 65535
15
+static char buf[BUF_SIZE];
16
+
17
+int main(char** argv, int argn)
18
+{
19
+	int sock;
20
+	struct sockaddr_in addr;
21
+	struct sockaddr_in to;
22
+	int r, len;
23
+
24
+	printf("starting\n");
25
+	
26
+	addr.sin_family=AF_INET;
27
+	addr.sin_port=htons(PORT);
28
+	addr.sin_addr.s_addr=INADDR_ANY;
29
+	to.sin_family=AF_INET;
30
+	to.sin_port=htons(SEND_PORT);
31
+	to.sin_addr.s_addr=htonl(SEND_ADDR);
32
+		
33
+
34
+	sock=socket(PF_INET, SOCK_DGRAM,0);
35
+	if (bind(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr_in))==-1){
36
+		fprintf(stderr, "ERROR: udp_init: bind: %s\n", strerror(errno));
37
+		exit(1);
38
+	}
39
+
40
+	//if (fork())
41
+		if (fork()){
42
+			close(sock);
43
+			for(;;) sleep(100);
44
+			exit(1);
45
+		}
46
+	/*children*/
47
+	printf("child\n");
48
+	for(;;){
49
+		len=read(sock, buf, BUF_SIZE);
50
+		/*for (r=0;r < LOOP_COUNT; r++);*/
51
+		/* send it back*/
52
+		sendto(sock, buf, len, 0, (struct sockaddr*) &to,
53
+				sizeof(struct sockaddr_in));
54
+	}
55
+}
0 56
new file mode 100644
... ...
@@ -0,0 +1,205 @@
0
+/* $Id */
1
+
2
+#include <stdlib.h>
3
+#include <stdio.h>
4
+#include <errno.h>
5
+#include <string.h>
6
+#include <ctype.h>
7
+#include <netdb.h>
8
+#include <unistd.h>
9
+#include <sys/types.h>
10
+#include <sys/socket.h>
11
+#include <netinet/in.h>
12
+#include <arpa/inet.h>
13
+
14
+
15
+
16
+static char *id="$Id$";
17
+static char *version="udp_test_proxy 0.1";
18
+static char* help_msg="\
19
+Usage: udp_test_proxy  -l address -s port -d address -p port [-n no] [-v]\n\
20
+Options:\n\
21
+    -l address    listen address\n\
22
+    -s port       listen(source) port\n\
23
+    -d address    destination address\n\
24
+    -p port       destination port\n\
25
+    -n no         number of processes\n\
26
+    -v            increase verbosity level\n\
27
+    -V            version number\n\
28
+    -h            this help message\n\
29
+";
30
+#define BUF_SIZE 65535
31
+static char buf[BUF_SIZE];
32
+
33
+int main(int argc, char** argv)
34
+{
35
+	int sock;
36
+	pid_t pid;
37
+	struct sockaddr_in addr;
38
+	struct sockaddr_in to;
39
+	int r, n, len;
40
+	char c;
41
+	struct hostent* he;
42
+	int verbose;
43
+	int sport, dport;
44
+	char *dst;
45
+	char *src;
46
+	char* tmp;
47
+
48
+
49
+	/* init */
50
+	verbose=0;
51
+	dst=0;
52
+	sport=dport=0;
53
+	src=dst=0;
54
+	n=0;
55
+	
56
+	opterr=0;
57
+	while ((c=getopt(argc,argv, "l:p:d:s:n:vhV"))!=-1){
58
+		switch(c){
59
+			case 'v':
60
+				verbose++;
61
+				break;
62
+			case 'd':
63
+				dst=optarg;
64
+				break;
65
+			case 'l':
66
+				src=optarg;
67
+				break;
68
+			case 'p':
69
+				dport=strtol(optarg, &tmp, 10);
70
+				if ((tmp==0)||(*tmp)){
71
+					fprintf(stderr, "bad port number: -p %s\n", optarg);
72
+					goto error;
73
+				}
74
+				break;
75
+			case 's':
76
+				sport=strtol(optarg, &tmp, 10);
77
+				if ((tmp==0)||(*tmp)){
78
+					fprintf(stderr, "bad port number: -s %s\n", optarg);
79
+					goto error;
80
+				}
81
+				break;
82
+			case 'n':
83
+				n=strtol(optarg, &tmp, 10);
84
+				if ((tmp==0)||(*tmp)){
85
+					fprintf(stderr, "bad process number: -n %s\n", optarg);
86
+					goto error;
87
+				}
88
+				break;
89
+			case 'V':
90
+				printf("version: %s\n", version);
91
+				printf("%s\n",id);
92
+				exit(0);
93
+				break;
94
+			case 'h':
95
+				printf("version: %s\n", version);
96
+				printf("%s", help_msg);
97
+				exit(0);
98
+				break;
99
+			case '?':
100
+				if (isprint(optopt))
101
+					fprintf(stderr, "Unknown option `-%c�\n", optopt);
102
+				else
103
+					fprintf(stderr, "Unknown character `\\x%x�\n", optopt);
104
+				goto error;
105
+			case ':':
106
+				fprintf(stderr, "Option `-%c� requires an argument.\n",
107
+						optopt);
108
+				goto error;
109
+				break;
110
+			default:
111
+					abort();
112
+		}
113
+	}
114
+
115
+	/* check if all the required params are present */
116
+	if (dst==0){
117
+		fprintf(stderr, "Missing destination (-d ...)\n");
118
+		exit(-1);
119
+	}
120
+	if (src==0){
121
+		fprintf(stderr, "Missing listen address (-l ...)\n");
122
+		exit(-1);
123
+	}
124
+	if(sport==0){
125
+		fprintf(stderr, "Missing source port number (-s port)\n");
126
+		exit(-1);
127
+	}else if(sport<0){
128
+		fprintf(stderr, "Invalid source port number (-s %d)\n", sport);
129
+		exit(-1);
130
+	}
131
+	if(dport==0){
132
+		fprintf(stderr, "Missing destination port number (-p port)\n");
133
+		exit(-1);
134
+	}else if(dport<0){
135
+		fprintf(stderr, "Invalid destination port number (-p %d)\n", dport);
136
+		exit(-1);
137
+	}
138
+	if(n<0){
139
+		fprintf(stderr, "Invalid process no (-n %d)\n", n);
140
+		exit(-1);
141
+	}
142
+
143
+
144
+	/* resolve destination */
145
+	he=gethostbyname(dst);
146
+	if (he==0){
147
+		fprintf(stderr, "ERROR: could not resolve %s\n", dst);
148
+		goto error;
149
+	}
150
+
151
+	/* set to*/
152
+	to.sin_family=he->h_addrtype;
153
+	to.sin_port=htons(dport);
154
+	memcpy(&to.sin_addr.s_addr, he->h_addr_list[0], he->h_length);
155
+
156
+	/* resolve source/listen */
157
+	he=gethostbyname(src);
158
+	if (he==0){
159
+		fprintf(stderr, "ERROR: could not resolve %s\n", dst);
160
+		goto error;
161
+	}
162
+	/* open socket*/
163
+	addr.sin_family=he->h_addrtype;
164
+	addr.sin_port=htons(sport);
165
+	memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length);
166
+
167
+	sock = socket(he->h_addrtype, SOCK_DGRAM, 0);
168
+	if (sock==-1){
169
+		fprintf(stderr, "ERROR: socket: %s\n", strerror(errno));
170
+		goto error;
171
+	}
172
+	if (bind(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr_in))==-1){
173
+		fprintf(stderr, "ERROR: bind: %s\n", strerror(errno));
174
+		goto error;
175
+	}
176
+
177
+	for(r=1; r<n; r++){
178
+		if ((pid=fork())==-1){
179
+			fprintf(stderr, "ERROR: fork: %s\n", strerror(errno));
180
+			goto error;
181
+		}
182
+		if (pid==0) break; /* child, skip */
183
+	}
184
+
185
+	if (verbose>3) printf("process starting\n");
186
+	for(;;){
187
+		len=read(sock, buf, BUF_SIZE);
188
+		if (len==-1){
189
+			fprintf(stderr, "ERROR: read: %s\n", strerror(errno));
190
+			continue;
191
+		}
192
+		if (verbose>2) putchar('r');
193
+		/* send it back*/
194
+		len=sendto(sock, buf, len, 0, (struct sockaddr*) &to,
195
+				sizeof(struct sockaddr_in));
196
+		if (len==-1){
197
+			fprintf(stderr, "ERROR: sendto: %s\n", strerror(errno));
198
+			continue;
199
+		}
200
+		if (verbose>1) putchar('.');
201
+	}
202
+error:
203
+	exit(-1);
204
+}
... ...
@@ -123,7 +123,7 @@ int udp_init(unsigned long ip, unsigned short port)
123 123
 	}
124 124
 	/* set sock opts? */
125 125
 	optval=1;
126
-	if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEADDR,
126
+	if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEADDR ,
127 127
 					(void*)&optval, sizeof(optval)) ==-1)
128 128
 	{
129 129
 		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));