1 /*---------------------------------------------------------------
2 * Copyright (c) 1999,2000,2001,2002,2003
3 * The Board of Trustees of the University of Illinois
5 *---------------------------------------------------------------
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software (Iperf) and associated
8 * documentation files (the "Software"), to deal in the Software
9 * without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute,
11 * sublicense, and/or sell copies of the Software, and to permit
12 * persons to whom the Software is furnished to do
13 * so, subject to the following conditions:
16 * Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and
18 * the following disclaimers.
21 * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimers in the documentation and/or other materials
24 * provided with the distribution.
27 * Neither the names of the University of Illinois, NCSA,
28 * nor the names of its contributors may be used to endorse
29 * or promote products derived from this Software without
30 * specific prior written permission.
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
34 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35 * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
36 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
37 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
38 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE
39 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 * ________________________________________________________________
41 * National Laboratory for Applied Network Research
42 * National Center for Supercomputing Applications
43 * University of Illinois at Urbana-Champaign
44 * http://www.ncsa.uiuc.edu
45 * ________________________________________________________________
48 * by Mark Gates <mgates@nlanr.net>
49 * & Ajay Tirumala <tirumala@ncsa.uiuc.edu>
50 * -------------------------------------------------------------------
51 * Stores and parses the initial values for all the global variables.
52 * -------------------------------------------------------------------
57 * ------------------------------------------------------------------- */
65 /* -------------------------------------------------------------------
67 * ------------------------------------------------------------------- */
73 typedef enum ThreadMode {
82 typedef enum ReportMode {
90 typedef enum TestMode {
99 * The thread_Settings is a structure that holds all
100 * options for a given execution of either a client
101 * or server. By using this structure rather than
102 * a global structure or class we can have multiple
103 * clients or servers running with different settings.
104 * In version 2.0 and above this structure contains
105 * all the information needed for a thread to execute
106 * and contains only C elements so it can be manipulated
107 * by either C or C++.
109 typedef struct thread_Settings {
111 char* mFileName; // -F
113 char* mLocalhost; // -B
114 char* mOutputFileName; // -o
115 FILE* Extractor_file;
116 ReportHeader* reporthdr;
117 MultiHeader* multihdr;
118 struct thread_Settings *runNow;
119 struct thread_Settings *runNext;
128 /* flags is a BitMask of old bools
129 bool mBufLenSet; // -l
133 bool mFileInput; // -F or -I
135 bool mPrintMSS; // -m
136 bool mRemoveService; // -R
139 bool mSuggestWin; // -W
142 bool mReportSettings;
144 bool mNoSettingsReport; // -x s
145 bool mNoConnectionReport; // -x c
146 bool mNoDataReport; // -x d
147 bool mNoServerReport; // -x
148 bool mNoMultReport; // -x m
149 bool mSinlgeClient; // -1 */
151 // enums (which should be special int's)
152 ThreadMode mThreadMode; // -s or -c
153 ReportMode mReportMode;
154 TestMode mMode; // -r or -d
155 // Hopefully int64_t's
156 max_size_t mUDPRate; // -b or -u
157 max_size_t mAmount; // -n or -t
159 double mInterval; // -i
161 unsigned short mListenPort; // -L
162 unsigned short mPort; // -p
167 // structs or miscellaneous
170 iperf_sockaddr local;
171 Socklen_t size_local;
173 #if defined( HAVE_WIN32_THREAD )
179 * Due to the use of thread_Settings in C and C++
180 * we are unable to use bool values. To provide
181 * the functionality of bools we use the following
182 * bitmask over an assumed 32 bit int. This will
183 * work fine on 64bit machines we will just be ignoring
186 * To add a flag simply define it as the next bit then
187 * add the 3 support functions below.
189 #define FLAG_BUFLENSET 0x00000001
190 #define FLAG_COMPAT 0x00000002
191 #define FLAG_DAEMON 0x00000004
192 #define FLAG_DOMAIN 0x00000008
193 #define FLAG_FILEINPUT 0x00000010
194 #define FLAG_NODELAY 0x00000020
195 #define FLAG_PRINTMSS 0x00000040
196 #define FLAG_REMOVESERVICE 0x00000080
197 #define FLAG_STDIN 0x00000100
198 #define FLAG_STDOUT 0x00000200
199 #define FLAG_SUGGESTWIN 0x00000400
200 #define FLAG_UDP 0x00000800
201 #define FLAG_MODETIME 0x00001000
202 #define FLAG_REPORTSETTINGS 0x00002000
203 #define FLAG_MULTICAST 0x00004000
204 #define FLAG_NOSETTREPORT 0x00008000
205 #define FLAG_NOCONNREPORT 0x00010000
206 #define FLAG_NODATAREPORT 0x00020000
207 #define FLAG_NOSERVREPORT 0x00040000
208 #define FLAG_NOMULTREPORT 0x00080000
209 #define FLAG_SINGLECLIENT 0x00100000
210 #define FLAG_SINGLEUDP 0x00200000
212 #define isBuflenSet(settings) ((settings->flags & FLAG_BUFLENSET) != 0)
213 #define isCompat(settings) ((settings->flags & FLAG_COMPAT) != 0)
214 #define isDaemon(settings) ((settings->flags & FLAG_DAEMON) != 0)
215 #define isIPV6(settings) ((settings->flags & FLAG_DOMAIN) != 0)
216 #define isFileInput(settings) ((settings->flags & FLAG_FILEINPUT) != 0)
217 #define isNoDelay(settings) ((settings->flags & FLAG_NODELAY) != 0)
218 #define isPrintMSS(settings) ((settings->flags & FLAG_PRINTMSS) != 0)
219 #define isRemoveService(settings) ((settings->flags & FLAG_REMOVESERVICE) != 0)
220 #define isSTDIN(settings) ((settings->flags & FLAG_STDIN) != 0)
221 #define isSTDOUT(settings) ((settings->flags & FLAG_STDOUT) != 0)
222 #define isSuggestWin(settings) ((settings->flags & FLAG_SUGGESTWIN) != 0)
223 #define isUDP(settings) ((settings->flags & FLAG_UDP) != 0)
224 #define isModeTime(settings) ((settings->flags & FLAG_MODETIME) != 0)
225 #define isReport(settings) ((settings->flags & FLAG_REPORTSETTINGS) != 0)
226 #define isMulticast(settings) ((settings->flags & FLAG_MULTICAST) != 0)
227 // Active Low for Reports
228 #define isSettingsReport(settings) ((settings->flags & FLAG_NOSETTREPORT) == 0)
229 #define isConnectionReport(settings) ((settings->flags & FLAG_NOCONNREPORT) == 0)
230 #define isDataReport(settings) ((settings->flags & FLAG_NODATAREPORT) == 0)
231 #define isServerReport(settings) ((settings->flags & FLAG_NOSERVREPORT) == 0)
232 #define isMultipleReport(settings) ((settings->flags & FLAG_NOMULTREPORT) == 0)
234 #define isSingleClient(settings) ((settings->flags & FLAG_SINGLECLIENT) != 0)
235 #define isSingleUDP(settings) ((settings->flags & FLAG_SINGLEUDP) != 0)
237 #define setBuflenSet(settings) settings->flags |= FLAG_BUFLENSET
238 #define setCompat(settings) settings->flags |= FLAG_COMPAT
239 #define setDaemon(settings) settings->flags |= FLAG_DAEMON
240 #define setIPV6(settings) settings->flags |= FLAG_DOMAIN
241 #define setFileInput(settings) settings->flags |= FLAG_FILEINPUT
242 #define setNoDelay(settings) settings->flags |= FLAG_NODELAY
243 #define setPrintMSS(settings) settings->flags |= FLAG_PRINTMSS
244 #define setRemoveService(settings) settings->flags |= FLAG_REMOVESERVICE
245 #define setSTDIN(settings) settings->flags |= FLAG_STDIN
246 #define setSTDOUT(settings) settings->flags |= FLAG_STDOUT
247 #define setSuggestWin(settings) settings->flags |= FLAG_SUGGESTWIN
248 #define setUDP(settings) settings->flags |= FLAG_UDP
249 #define setModeTime(settings) settings->flags |= FLAG_MODETIME
250 #define setReport(settings) settings->flags |= FLAG_REPORTSETTINGS
251 #define setMulticast(settings) settings->flags |= FLAG_MULTICAST
252 #define setNoSettReport(settings) settings->flags |= FLAG_NOSETTREPORT
253 #define setNoConnReport(settings) settings->flags |= FLAG_NOCONNREPORT
254 #define setNoDataReport(settings) settings->flags |= FLAG_NODATAREPORT
255 #define setNoServReport(settings) settings->flags |= FLAG_NOSERVREPORT
256 #define setNoMultReport(settings) settings->flags |= FLAG_NOMULTREPORT
257 #define setSingleClient(settings) settings->flags |= FLAG_SINGLECLIENT
258 #define setSingleUDP(settings) settings->flags |= FLAG_SINGLEUDP
260 #define unsetBuflenSet(settings) settings->flags &= ~FLAG_BUFLENSET
261 #define unsetCompat(settings) settings->flags &= ~FLAG_COMPAT
262 #define unsetDaemon(settings) settings->flags &= ~FLAG_DAEMON
263 #define unsetIPV6(settings) settings->flags &= ~FLAG_DOMAIN
264 #define unsetFileInput(settings) settings->flags &= ~FLAG_FILEINPUT
265 #define unsetNoDelay(settings) settings->flags &= ~FLAG_NODELAY
266 #define unsetPrintMSS(settings) settings->flags &= ~FLAG_PRINTMSS
267 #define unsetRemoveService(settings) settings->flags &= ~FLAG_REMOVESERVICE
268 #define unsetSTDIN(settings) settings->flags &= ~FLAG_STDIN
269 #define unsetSTDOUT(settings) settings->flags &= ~FLAG_STDOUT
270 #define unsetSuggestWin(settings) settings->flags &= ~FLAG_SUGGESTWIN
271 #define unsetUDP(settings) settings->flags &= ~FLAG_UDP
272 #define unsetModeTime(settings) settings->flags &= ~FLAG_MODETIME
273 #define unsetReport(settings) settings->flags &= ~FLAG_REPORTSETTINGS
274 #define unsetMulticast(settings) settings->flags &= ~FLAG_MULTICAST
275 #define unsetNoSettReport(settings) settings->flags &= ~FLAG_NOSETTREPORT
276 #define unsetNoConnReport(settings) settings->flags &= ~FLAG_NOCONNREPORT
277 #define unsetNoDataReport(settings) settings->flags &= ~FLAG_NODATAREPORT
278 #define unsetNoServReport(settings) settings->flags &= ~FLAG_NOSERVREPORT
279 #define unsetNoMultReport(settings) settings->flags &= ~FLAG_NOMULTREPORT
280 #define unsetSingleClient(settings) settings->flags &= ~FLAG_SINGLECLIENT
281 #define unsetSingleUDP(settings) settings->flags &= ~FLAG_SINGLEUDP
284 #define HEADER_VERSION1 0x80000000
285 #define RUN_NOW 0x00000001
287 // used to reference the 4 byte ID number we place in UDP datagrams
288 // use int32_t if possible, otherwise a 32 bit bitfield (e.g. on J90)
289 typedef struct UDP_datagram {
296 unsigned int tv_sec : 32;
297 unsigned int tv_usec : 32;
302 * The client_hdr structure is sent from clients
303 * to servers to alert them of things that need
304 * to happen. Order must be perserved in all
305 * future releases for backward compatibility.
306 * 1.7 has flags, numThreads, mPort, and bufferlen
308 typedef struct client_hdr {
313 * flags is a bitmap for different options
314 * the most significant bits are for determining
315 * which information is available. So 1.7 uses
316 * 0x80000000 and the next time information is added
317 * the 1.7 bit will be set and 0x40000000 will be
318 * set signifying additional information. If no
319 * information bits are set then the header is ignored.
320 * The lowest order diferentiates between dualtest and
321 * tradeoff modes, wheither the speaker needs to start
322 * immediately or after the audience finishes.
331 signed int flags : 32;
332 signed int numThreads : 32;
333 signed int mPort : 32;
334 signed int bufferlen : 32;
335 signed int mWinBand : 32;
336 signed int mAmount : 32;
341 * The server_hdr structure facilitates the server
342 * report of jitter and loss on the client side.
343 * It piggy_backs on the existing clear to close
346 typedef struct server_hdr {
351 * flags is a bitmap for different options
352 * the most significant bits are for determining
353 * which information is available. So 1.7 uses
354 * 0x80000000 and the next time information is added
355 * the 1.7 bit will be set and 0x40000000 will be
356 * set signifying additional information. If no
357 * information bits are set then the header is ignored.
365 int32_t outorder_cnt;
370 signed int flags : 32;
371 signed int total_len1 : 32;
372 signed int total_len2 : 32;
373 signed int stop_sec : 32;
374 signed int stop_usec : 32;
375 signed int error_cnt : 32;
376 signed int outorder_cnt : 32;
377 signed int datagrams : 32;
378 signed int jitter1 : 32;
379 signed int jitter2 : 32;
385 void Settings_Initialize( thread_Settings* main );
388 void Settings_Copy( thread_Settings* from, thread_Settings** into );
390 // free associated memory
391 void Settings_Destroy( thread_Settings *mSettings );
393 // parse settings from user's environment variables
394 void Settings_ParseEnvironment( thread_Settings *mSettings );
396 // parse settings from app's command line
397 void Settings_ParseCommandLine( int argc, char **argv, thread_Settings *mSettings );
399 // convert to lower case for [KMG]bits/sec
400 void Settings_GetLowerCaseArg(const char *,char *);
402 // convert to upper case for [KMG]bytes/sec
403 void Settings_GetUpperCaseArg(const char *,char *);
405 // generate settings for listener instance
406 void Settings_GenerateListenerSettings( thread_Settings *client, thread_Settings **listener);
408 // generate settings for speaker instance
409 void Settings_GenerateClientSettings( thread_Settings *server,
410 thread_Settings **client,
413 // generate client header for server
414 void Settings_GenerateClientHdr( thread_Settings *client, client_hdr *hdr );
417 } /* end extern "C" */