1 /*
2  * The Spread Toolkit.
3  *
4  * The contents of this file are subject to the Spread Open-Source
5  * License, Version 1.0 (the ``License''); you may not use
6  * this file except in compliance with the License.  You may obtain a
7  * copy of the License at:
8  *
9  * http://www.spread.org/license/
10  *
11  * or in the file ``license.txt'' found in this distribution.
12  *
13  * Software distributed under the License is distributed on an AS IS basis,
14  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15  * for the specific language governing rights and limitations under the
16  * License.
17  *
18  * The Creators of Spread are:
19  *  Yair Amir, Michal Miskin-Amir, Jonathan Stanton, John Schultz.
20  *
21  *  Copyright (C) 1993-2012 Spread Concepts LLC <info@spreadconcepts.com>
22  *
23  *  All Rights Reserved.
24  *
25  * Major Contributor(s):
26  * ---------------
27  *    Ryan Caudy           rcaudy@gmail.com - contributions to process groups.
28  *    Claudiu Danilov      claudiu@acm.org - scalable wide area support.
29  *    Cristina Nita-Rotaru crisn@cs.purdue.edu - group communication security.
30  *    Theo Schlossnagle    jesus@omniti.com - Perl, autoconf, old skiplist.
31  *    Dan Schoenblum       dansch@cnds.jhu.edu - Java interface.
32  *
33  */
34 
35 
36 #include "arch.h"
37 
38 #include <string.h>
39 
40 #include "spu_alarm.h"
41 #include "spu_events.h"
42 #include "spu_data_link.h"
43 
44 #ifdef	ARCH_PC_WIN95
45 
46 #include	<winsock.h>
47 
48 WSADATA		WSAData;
49 
50 #endif	/* ARCH_PC_WIN95 */
51 
52 static  int     Num_bytes;
53 static  int     Num_packets;
54 static	char	IP[16];
55 static	int16	Port;
56 static	sp_time	Delay;
57 static	int	Burst;
58 
59 static	void 	Usage( int argc, char *argv[] );
60 
main(int argc,char * argv[])61 int main( int argc, char *argv[] )
62 {
63 
64 	channel chan;
65 	sys_scatter scat;
66 	char	buf[100000];
67 	int	ret,i,i1,i2,i3,i4;
68 	int	address;
69 	int32	*type;
70 	int32	*count;
71 	int32	*size;
72 	sp_time	start, end, total_time;
73 	int	total_problems=0;
74 
75 	Usage( argc, argv );
76 
77 	Alarm_set_types( NONE );
78 
79 #ifdef	ARCH_PC_WIN95
80 
81 	ret = WSAStartup( MAKEWORD(1,1), &WSAData );
82 	if( ret != 0 )
83 		Alarm( EXIT, "s: winsock initialization error %d\n", ret );
84 
85 #endif	/* ARCH_PC_WIN95 */
86 
87 	chan = DL_init_channel( SEND_CHANNEL, Port, 0, 0 );
88 
89 	scat.num_elements = 1;
90 	scat.elements[0].buf = buf;
91 	scat.elements[0].len = Num_bytes;
92 
93 	sscanf( IP ,"%d.%d.%d.%d",&i1, &i2, &i3, &i4);
94 	address = ( (i1 << 24 ) | (i2 << 16) | (i3 << 8) | i4 );
95 
96 	printf("Checking (%d.%d.%d.%d, %d). Each burst has %d packets, %d bytes each with %ld msec delay in between, for a total of %d packets\n",i1,i2,i3,i4, Port, Burst, Num_bytes, Delay.usec/1000+Delay.sec*1000, Num_packets );
97 
98 	type  = (int32 *)buf;
99 	count = (int32 *)&buf[4];
100 	size  = (int32 *)&buf[8];
101 
102 	*type = Set_endian( 0 );
103 	*size = Num_bytes;
104 	start = E_get_time();
105 	for(i=1; i<= Num_packets; i++ )
106 	{
107 		*count = i;
108 		ret = DL_send( chan, address, Port, &scat );
109 		if( ret != Num_bytes)
110 		{
111 			total_problems++;
112 			i--;
113 		}
114 		if( i%Burst == 0 ) E_delay( Delay );
115 		if( i%1000  == 0) printf("sent %d packets of %d bytes\n",i, Num_bytes);
116 	}
117 	end = E_get_time();
118 	total_time = E_sub_time( end, start );
119 	Delay.usec = 10000;
120 	*type = Set_endian( 1 );
121 	E_delay( Delay );
122 	ret = DL_send( chan, address, Port, &scat );
123 	printf("total time is (%ld,%ld), with %d problems \n",total_time.sec, total_time.usec, total_problems );
124 
125         exit(0);
126 }
127 
Usage(int argc,char * argv[])128 static  void    Usage(int argc, char *argv[])
129 {
130         /* Setting defaults */
131 	Num_bytes = 1024;
132 	Num_packets = 10000;
133 	strcpy( IP, "127.0.0.1" );
134 	Port = 4444;
135 	Delay.sec = 0;
136 	Delay.usec = 10000;
137 	Burst	  = 100;
138 
139 	while( --argc > 0 )
140 	{
141 		argv++;
142 
143                 if( !strncmp( *argv, "-t", 2 ) )
144 		{
145 			sscanf(argv[1], "%ld", &Delay.usec );
146 			Delay.usec = Delay.usec*1000;
147 			Delay.sec = 0;
148 			if( Delay.usec > 1000000 )
149 			{
150 				Delay.sec  = Delay.usec / 1000000;
151 				Delay.usec = Delay.usec % 1000000;
152 			}
153 			argc--; argv++;
154 		}else if( !strncmp( *argv, "-p", 2 ) ){
155 			sscanf(argv[1], "%hd", &Port );
156 			argc--; argv++;
157 		}else if( !strncmp( *argv, "-b", 2 ) ){
158 			sscanf(argv[1], "%d", &Burst );
159 			argc--; argv++;
160 		}else if( !strncmp( *argv, "-n", 2 ) ){
161 			sscanf(argv[1], "%d", &Num_packets );
162 			argc--; argv++;
163 		}else if( !strncmp( *argv, "-s", 2 ) ){
164 			sscanf(argv[1], "%d", &Num_bytes );
165 			argc--; argv++;
166 		}else if( !strncmp( *argv, "-a", 2 ) ){
167 			sscanf(argv[1], "%s", IP );
168 			argc--; argv++;
169                 }else{
170 			printf( "Usage: \n%s\n%s\n%s\n%s\n%s\n%s\n",
171 				"\t[-p <port number>] : to send on, default is 4444",
172 				"\t[-b <burst>]       : number of packets in each burst, default is 100",
173 				"\t[-t <delay>]       : time (mili-secs) to wait between bursts, default 10",
174 				"\t[-n <num packets>] : total number of packets to send, default is 10000",
175 				"\t[-s <num bytes>]   : size of each packet, default is 1024",
176 				"\t[-a <IP address>]  : default is 127.0.0.1" );
177 			exit( 0 );
178 		}
179 	}
180 }
181 
182