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.
20 *
21 * Copyright (C) 1993-2004 Spread Concepts LLC <spread@spreadconcepts.com>
22 *
23 * All Rights Reserved.
24 *
25 * Major Contributor(s):
26 * ---------------
27 * Cristina Nita-Rotaru crisn@cs.purdue.edu - group communication security.
28 * Theo Schlossnagle jesus@omniti.com - Perl, skiplists, autoconf.
29 * Dan Schoenblum dansch@cnds.jhu.edu - Java interface.
30 * John Schultz jschultz@cnds.jhu.edu - contribution to process group membership.
31 *
32 */
33
34
35 #include "arch.h"
36
37 #include <string.h>
38
39 #include "alarm.h"
40 #include "sp_events.h"
41 #include "data_link.h"
42
43 #ifdef ARCH_PC_WIN95
44
45 #include <winsock.h>
46
47 WSADATA WSAData;
48
49 #endif /* ARCH_PC_WIN95 */
50
51 static int Num_bytes;
52 static int Num_packets;
53 static char IP[16];
54 static int16 Port;
55 static sp_time Delay;
56 static int Burst;
57
58 static void Usage( int argc, char *argv[] );
59
main(int argc,char * argv[])60 int main( int argc, char *argv[] )
61 {
62
63 channel chan;
64 sys_scatter scat;
65 char buf[100000];
66 int ret,i,i1,i2,i3,i4;
67 int address;
68 int32 *type;
69 int32 *count;
70 int32 *size;
71 sp_time start, end, total_time;
72 int total_problems=0;
73
74 Usage( argc, argv );
75
76 Alarm_set_types( NONE );
77
78 #ifdef ARCH_PC_WIN95
79
80 ret = WSAStartup( MAKEWORD(1,1), &WSAData );
81 if( ret != 0 )
82 Alarm( EXIT, "s: winsock initialization error %d\n", ret );
83
84 #endif /* ARCH_PC_WIN95 */
85
86 chan = DL_init_channel( SEND_CHANNEL, Port, 0, 0 );
87
88 scat.num_elements = 1;
89 scat.elements[0].buf = buf;
90 scat.elements[0].len = Num_bytes;
91
92 sscanf( IP ,"%d.%d.%d.%d",&i1, &i2, &i3, &i4);
93 address = ( (i1 << 24 ) | (i2 << 16) | (i3 << 8) | i4 );
94
95 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 );
96
97 type = (int32 *)buf;
98 count = (int32 *)&buf[4];
99 size = (int32 *)&buf[8];
100
101 *type = Set_endian( 0 );
102 *size = Num_bytes;
103 start = E_get_time();
104 for(i=1; i<= Num_packets; i++ )
105 {
106 *count = i;
107 ret = DL_send( chan, address, Port, &scat );
108 if( ret != Num_bytes)
109 {
110 total_problems++;
111 i--;
112 }
113 if( i%Burst == 0 ) E_delay( Delay );
114 if( i%1000 == 0) printf("sent %d packets of %d bytes\n",i, Num_bytes);
115 }
116 end = E_get_time();
117 total_time = E_sub_time( end, start );
118 Delay.usec = 10000;
119 *type = Set_endian( 1 );
120 E_delay( Delay );
121 ret = DL_send( chan, address, Port, &scat );
122 printf("total time is (%ld,%ld), with %d problems \n",total_time.sec, total_time.usec, total_problems );
123
124 exit(0);
125 }
126
Usage(int argc,char * argv[])127 static void Usage(int argc, char *argv[])
128 {
129 /* Setting defaults */
130 Num_bytes = 1024;
131 Num_packets = 10000;
132 strcpy( IP, "127.0.0.1" );
133 Port = 4444;
134 Delay.sec = 0;
135 Delay.usec = 10000;
136 Burst = 100;
137
138 while( --argc > 0 )
139 {
140 argv++;
141
142 if( !strncmp( *argv, "-t", 2 ) )
143 {
144 sscanf(argv[1], "%ld", &Delay.usec );
145 Delay.usec = Delay.usec*1000;
146 Delay.sec = 0;
147 if( Delay.usec > 1000000 )
148 {
149 Delay.sec = Delay.usec / 1000000;
150 Delay.usec = Delay.usec % 1000000;
151 }
152 argc--; argv++;
153 }else if( !strncmp( *argv, "-p", 2 ) ){
154 sscanf(argv[1], "%hd", &Port );
155 argc--; argv++;
156 }else if( !strncmp( *argv, "-b", 2 ) ){
157 sscanf(argv[1], "%d", &Burst );
158 argc--; argv++;
159 }else if( !strncmp( *argv, "-n", 2 ) ){
160 sscanf(argv[1], "%d", &Num_packets );
161 argc--; argv++;
162 }else if( !strncmp( *argv, "-s", 2 ) ){
163 sscanf(argv[1], "%d", &Num_bytes );
164 argc--; argv++;
165 }else if( !strncmp( *argv, "-a", 2 ) ){
166 sscanf(argv[1], "%s", IP );
167 argc--; argv++;
168 }else{
169 printf( "Usage: \n%s\n%s\n%s\n%s\n%s\n%s\n",
170 "\t[-p <port number>] : to send on, default is 4444",
171 "\t[-b <burst>] : number of packets in each burst, default is 100",
172 "\t[-t <delay>] : time (mili-secs) to wait between bursts, default 10",
173 "\t[-n <num packets>] : total number of packets to send, default is 10000",
174 "\t[-s <num bytes>] : size of each packet, default is 1024",
175 "\t[-a <IP address>] : default is 127.0.0.1" );
176 exit( 0 );
177 }
178 }
179 }
180
181