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 * -------------------------------------------------------------------
60 * ------------------------------------------------------------------- */
66 #include "Settings.hpp"
68 #include "SocketAddr.h"
72 #include "gnu_getopt.h"
74 void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtSettings );
76 /* -------------------------------------------------------------------
77 * command line options
79 * The option struct essentially maps a long option name (--foobar)
80 * or environment variable ($FOOBAR) to its short option char (f).
81 * ------------------------------------------------------------------- */
82 #define LONG_OPTIONS()
84 const struct option long_options[] =
86 {"singleclient", no_argument, NULL, '1'},
87 {"dualtest", no_argument, NULL, '2'},
88 {"bandwidth", required_argument, NULL, 'b'},
89 {"client", required_argument, NULL, 'c'},
90 {"dccp", no_argument, NULL, 'd'},
91 {"format", required_argument, NULL, 'f'},
92 {"help", no_argument, NULL, 'h'},
93 {"interval", required_argument, NULL, 'i'},
94 {"mcast_iface",required_argument, NULL, 'j'},
95 {"len", required_argument, NULL, 'l'},
96 {"print_mss", no_argument, NULL, 'm'},
97 {"num", required_argument, NULL, 'n'},
98 {"output", required_argument, NULL, 'o'},
99 {"port", required_argument, NULL, 'p'},
100 {"tradeoff", no_argument, NULL, 'r'},
101 {"server", no_argument, NULL, 's'},
102 {"time", required_argument, NULL, 't'},
103 {"udp", no_argument, NULL, 'u'},
104 {"udplite", required_argument, NULL, 'u'},
105 {"version", no_argument, NULL, 'v'},
106 {"window", required_argument, NULL, 'w'},
107 {"reportexclude", required_argument, NULL, 'x'},
108 {"reportstyle",required_argument, NULL, 'y'},
110 // more esoteric options
111 {"algorithm", required_argument, NULL, 'A'},
112 {"bind", required_argument, NULL, 'B'},
113 {"compatibility", no_argument, NULL, 'C'},
114 {"daemon", no_argument, NULL, 'D'},
115 {"file_input", required_argument, NULL, 'F'},
116 {"stdin_input", no_argument, NULL, 'I'},
117 {"mss", required_argument, NULL, 'M'},
118 {"nodelay", no_argument, NULL, 'N'},
119 {"listenport", required_argument, NULL, 'L'},
120 {"parallel", required_argument, NULL, 'P'},
121 {"remove", no_argument, NULL, 'R'},
122 {"dscp", required_argument, NULL, 'S'},
123 {"ttl", required_argument, NULL, 'T'},
124 {"single_udp", no_argument, NULL, 'U'},
125 {"ipv6_domian", no_argument, NULL, 'V'},
126 {"suggest_win_size", no_argument, NULL, 'W'},
127 {"ccid", required_argument, NULL, 'Z'},
131 #define ENV_OPTIONS()
133 const struct option env_options[] =
135 {"IPERF_SINGLECLIENT", no_argument, NULL, '1'},
136 {"IPERF_DUALTEST", no_argument, NULL, '2'},
137 {"IPERF_BANDWIDTH", required_argument, NULL, 'b'},
138 {"IPERF_CLIENT", required_argument, NULL, 'c'},
139 {"IPERF_DCCP", no_argument, NULL, 'd'},
140 {"IPERF_FORMAT", required_argument, NULL, 'f'},
142 {"IPERF_INTERVAL", required_argument, NULL, 'i'},
143 {"IPERF_MCASTIFACE", required_argument, NULL, 'j'},
144 {"IPERF_LEN", required_argument, NULL, 'l'},
145 {"IPERF_PRINT_MSS", no_argument, NULL, 'm'},
146 {"IPERF_NUM", required_argument, NULL, 'n'},
147 {"IPERF_PORT", required_argument, NULL, 'p'},
148 {"IPERF_TRADEOFF", no_argument, NULL, 'r'},
149 {"IPERF_SERVER", no_argument, NULL, 's'},
150 {"IPERF_TIME", required_argument, NULL, 't'},
151 {"IPERF_UDP", no_argument, NULL, 'u'},
153 {"TCP_WINDOW_SIZE", required_argument, NULL, 'w'},
154 {"IPERF_REPORTEXCLUDE", required_argument, NULL, 'x'},
155 {"IPERF_REPORTSTYLE",required_argument, NULL, 'y'},
157 // more esoteric options
158 {"IPERF_CC", required_argument, NULL, 'A'},
159 {"IPERF_BIND", required_argument, NULL, 'B'},
160 {"IPERF_COMPAT", no_argument, NULL, 'C'},
161 {"IPERF_DAEMON", no_argument, NULL, 'D'},
162 {"IPERF_FILE_INPUT", required_argument, NULL, 'F'},
163 {"IPERF_STDIN_INPUT", no_argument, NULL, 'I'},
164 {"IPERF_MSS", required_argument, NULL, 'M'},
165 {"IPERF_NODELAY", no_argument, NULL, 'N'},
166 {"IPERF_LISTENPORT", required_argument, NULL, 'L'},
167 {"IPERF_PARALLEL", required_argument, NULL, 'P'},
168 {"IPERF_DSCP", required_argument, NULL, 'S'},
169 {"IPERF_TTL", required_argument, NULL, 'T'},
170 {"IPERF_SINGLE_UDP", no_argument, NULL, 'U'},
171 {"IPERF_IPV6_DOMAIN", no_argument, NULL, 'V'},
172 {"IPERF_SUGGEST_WIN_SIZE", required_argument, NULL, 'W'},
173 {"IPERF_CCID", required_argument, NULL, 'Z'},
177 #define SHORT_OPTIONS()
179 const char short_options[] =
180 "12b::c:df:hi:j:l:mn:o:p:rst:uvw:x:y:A:B:CDF:IJ:L:M:NP:RS:T:UV:WZ:";
182 /* -------------------------------------------------------------------
184 * ------------------------------------------------------------------- */
187 const long kDefault_DgramRate = 1024 * 1024; // -u if set, 1 Mbit/sec
188 const int kDefault_UDPBufLen = 1470; // -u if set, read/write 1470 bytes
189 // 1470 bytes is small enough to be sending one packet per datagram on ethernet
191 // 1450 bytes is small enough to be sending one packet per datagram on ethernet
192 // **** with IPv6 ****
193 const int kDefault_DCCPBufLen = 1420; // -d
194 // old DCCPv4: MPS=1424; new DCCPv4: MPS=1440; new DCCPv6: MPS=1420 (above)
196 /* -------------------------------------------------------------------
197 * Initialize all settings to defaults.
198 * ------------------------------------------------------------------- */
200 void Settings_Initialize( thread_Settings *main ) {
201 // Everything defaults to zero or NULL with
202 // this memset. Only need to set non-zero values
204 memset( main, 0, sizeof(thread_Settings) );
205 main->mSock = INVALID_SOCKET;
206 //main->mSockAF = AF_UNSPEC
207 main->mReportMode = kReport_Default;
209 main->flags = FLAG_MODETIME | FLAG_STDOUT; // Default time and stdout
210 //main->mDgramRate = 0; // -b, ie. TCP mode
211 main->mProtocol = kProto_TCP; // -u / -d
212 //main->mHost = NULL; // -c, none, required for client
213 main->mMode = kTest_Normal; // -2, mMode == kTest_DualTest
214 main->mFormat = 'a'; // -f, adaptive bits
216 //main->mBufLenSet = false; // -l,
217 main->mBufLen = 8 * 1024; // -l, 8 Kbyte
218 //main->mInterval = 0; // -i, ie. no periodic bw reports
219 //main->mPrintMSS = false; // -m, don't print MSS
220 // mAmount is time also // -n, N/A
221 //main->mOutputFileName = NULL; // -o, filename
222 main->mPort = 5001; // -p, ttcp port
223 // mMode = kTest_Normal; // -r, mMode == kTest_TradeOff
224 main->mThreadMode = kMode_Unknown; // -s, or -c, none
225 main->mAmount = 1000; // -t, 10 seconds
226 // mDgramRate // -u, N/A, see kDefault_DgramRate
227 // skip version // -v,
228 //main->mWinSize = 0; // -w, ie. don't set window
230 // more esoteric options
231 //main->mLocalhost = NULL; // -B, bind address - none
232 //main->mCompat = false; // -C, run in Compatibility mode
233 //main->mDaemon = false; // -D, run as a daemon
234 //main->mFileInput = false; // -F,
235 //main->mFileName = NULL; // -F, filename
236 //main->mStdin = false; // -I, default not stdin
237 //main->mMcastIface = 0; // -J, default: host chooses interface
238 //main->mListenPort = 0; // -L, listen port
239 //main->mMSS = 0; // -M, ie. don't set MSS
240 //main->mNodelay = false; // -N, don't set nodelay
241 //main->mThreads = 0; // -P,
242 //main->mRemoveService = false; // -R,
243 //main->mTOS = 0; // -S, ie. don't set type of service
244 main->mTTL = 1; // -T, link-local TTL
245 //main->mDomain = kMode_IPv4; // -V,
246 //main->mSuggestWin = false; // -W, Suggest the window size.
250 void Settings_Copy( thread_Settings *from, thread_Settings **into ) {
251 *into = new thread_Settings;
252 memcpy( *into, from, sizeof(thread_Settings) );
253 if ( from->mHost != NULL ) {
254 (*into)->mHost = new char[ strlen(from->mHost) + 1];
255 strcpy( (*into)->mHost, from->mHost );
257 if ( from->mOutputFileName != NULL ) {
258 (*into)->mOutputFileName = new char[ strlen(from->mOutputFileName) + 1];
259 strcpy( (*into)->mOutputFileName, from->mOutputFileName );
261 if ( from->mLocalhost != NULL ) {
262 (*into)->mLocalhost = new char[ strlen(from->mLocalhost) + 1];
263 strcpy( (*into)->mLocalhost, from->mLocalhost );
265 if ( from->mFileName != NULL ) {
266 (*into)->mFileName = new char[ strlen(from->mFileName) + 1];
267 strcpy( (*into)->mFileName, from->mFileName );
269 // Zero out certain entries
270 (*into)->mTID = thread_zeroid();
271 (*into)->runNext = NULL;
272 (*into)->runNow = NULL;
275 /* -------------------------------------------------------------------
276 * Delete memory: Does not clean up open file pointers or ptr_parents
277 * ------------------------------------------------------------------- */
279 void Settings_Destroy( thread_Settings *mSettings) {
280 DELETE_ARRAY( mSettings->mHost );
281 DELETE_ARRAY( mSettings->mLocalhost );
282 DELETE_ARRAY( mSettings->mFileName );
283 DELETE_ARRAY( mSettings->mOutputFileName );
284 DELETE_PTR( mSettings );
287 /* -------------------------------------------------------------------
288 * Parses settings from user's environment variables.
289 * ------------------------------------------------------------------- */
290 void Settings_ParseEnvironment( thread_Settings *mSettings ) {
294 while ( env_options[i].name != NULL ) {
295 theVariable = getenv( env_options[i].name );
296 if ( theVariable != NULL ) {
297 Settings_Interpret( env_options[i].val, theVariable, mSettings );
301 } // end ParseEnvironment
303 /* -------------------------------------------------------------------
304 * Parse settings from app's command line.
305 * ------------------------------------------------------------------- */
307 void Settings_ParseCommandLine( int argc, char **argv, thread_Settings *mSettings ) {
310 gnu_getopt_long( argc, argv, short_options,
311 long_options, NULL )) != EOF ) {
312 Settings_Interpret( option, gnu_optarg, mSettings );
315 for ( int i = gnu_optind; i < argc; i++ ) {
316 fprintf( stderr, "%s: ignoring extra argument -- %s\n", argv[0], argv[i] );
318 } // end ParseCommandLine
320 /* -------------------------------------------------------------------
321 * Interpret individual options, either from the command line
322 * or from environment variables.
323 * ------------------------------------------------------------------- */
325 void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtSettings ) {
329 case '1': // Single Client
330 setSingleClient( mExtSettings );
333 case '2': // Dual-test Mode
334 if ( mExtSettings->mThreadMode != kMode_Client ) {
335 fprintf( stderr, warn_invalid_server_option, option );
338 if ( isCompat( mExtSettings ) ) {
339 fprintf( stderr, warn_invalid_compatibility_option, option );
342 mExtSettings->mMode = kTest_DualTest;
344 fprintf( stderr, warn_invalid_single_threaded, option );
345 mExtSettings->mMode = kTest_TradeOff;
350 // This sets packet-oriented mode. The optional
351 // argument sets datagram bandwidth (as before).
352 // If not given, a default bandwith is used.
353 setPacketOriented(mExtSettings);
356 Settings_GetLowerCaseArg(optarg, outarg);
357 mExtSettings->mDgramRate = byte_atoi(outarg);
359 mExtSettings->mDgramRate = kDefault_DgramRate;
362 case 'c': // client mode w/ server host to connect to
363 mExtSettings->mHost = new char[ strlen( optarg ) + 1 ];
364 strcpy( mExtSettings->mHost, optarg );
366 if ( mExtSettings->mThreadMode == kMode_Unknown ) {
367 mExtSettings->mThreadMode = kMode_Client;
368 mExtSettings->mThreads = 1;
372 case 'd': // DCCP as transport
373 mExtSettings->mProtocol = kProto_DCCP;
375 // if -l has already been processed, mBufLenSet is true
376 // so don't overwrite that value.
377 if ( !isBuflenSet( mExtSettings ) )
378 mExtSettings->mBufLen = kDefault_DCCPBufLen;
382 case 'f': // format to print in
383 mExtSettings->mFormat = (*optarg);
386 case 'h': // print help and exit
389 case 'i': // specify interval between periodic bw reports
390 mExtSettings->mInterval = atof( optarg );
391 if ( mExtSettings->mInterval < 0.5 ) {
392 fprintf (stderr, report_interval_small, mExtSettings->mInterval);
393 mExtSettings->mInterval = 0.5;
398 case 'J': // multicast interface to join multicast address on
399 mExtSettings->mMcastIface = if_nametoindex(optarg);
400 if (!mExtSettings->mMcastIface)
401 die("Interface \"%s\" does not work for -j/-J.", optarg);
404 case 'l': // length of each buffer
405 Settings_GetUpperCaseArg(optarg,outarg);
406 mExtSettings->mBufLen = byte_atoi( outarg );
407 setBuflenSet( mExtSettings );
409 if ( !isPacketOriented( mExtSettings ) ) {
410 if ( mExtSettings->mBufLen < (int) sizeof( client_hdr ) &&
411 !isCompat( mExtSettings ) ) {
412 setCompat( mExtSettings );
413 fprintf( stderr, warn_implied_compatibility, option );
416 if ( mExtSettings->mBufLen < (int) sizeof( dgram_record ) ) {
417 mExtSettings->mBufLen = sizeof( dgram_record );
418 fprintf( stderr, warn_buffer_too_small, mExtSettings->mBufLen );
420 if ( !isCompat( mExtSettings ) &&
421 mExtSettings->mBufLen < (int) ( sizeof( dgram_record )
422 + sizeof( client_hdr ) ) ) {
423 setCompat( mExtSettings );
424 fprintf( stderr, warn_implied_compatibility, option );
430 case 'm': // print TCP MSS
431 setPrintMSS( mExtSettings );
434 case 'n': // bytes of data
435 // amount mode (instead of time mode)
436 unsetModeTime( mExtSettings );
437 Settings_GetUpperCaseArg(optarg,outarg);
438 mExtSettings->mAmount = byte_atoi( outarg );
441 case 'o' : // output the report and other messages into the file
442 unsetSTDOUT( mExtSettings );
443 mExtSettings->mOutputFileName = new char[strlen(optarg)+1];
444 strcpy( mExtSettings->mOutputFileName, optarg);
447 case 'p': // server port
448 mExtSettings->mPort = atoi( optarg );
451 case 'r': // test mode tradeoff
452 if ( mExtSettings->mThreadMode != kMode_Client ) {
453 fprintf( stderr, warn_invalid_server_option, option );
456 if ( isCompat( mExtSettings ) ) {
457 fprintf( stderr, warn_invalid_compatibility_option, option );
460 mExtSettings->mMode = kTest_TradeOff;
463 case 's': // server mode
464 if ( mExtSettings->mThreadMode != kMode_Unknown ) {
465 fprintf( stderr, warn_invalid_client_option, option );
469 mExtSettings->mThreadMode = kMode_Listener;
472 case 't': // seconds to write for
473 // time mode (instead of amount mode)
474 setModeTime( mExtSettings );
475 mExtSettings->mAmount = (int) (atof( optarg ) * 100.0);
478 case 'u': // UDP(-Lite) instead of TCP
480 mExtSettings->mProtocol = kProto_UDPLITE;
481 // Set partial checksum coverage:
482 // - 0 means entire datagram,
483 // - 1..7 is illegal and will be rounded up to 8;
484 // - 8 and greater mean genuine partial coverage.
485 mExtSettings->cscov = atoi(optarg);
487 mExtSettings->mProtocol = kProto_UDP;
489 setPacketOriented(mExtSettings);
490 // if -b has already been processed, UDP rate will
491 // already be non-zero, so don't overwrite that value
492 if ( mExtSettings->mDgramRate == 0 )
493 mExtSettings->mDgramRate = kDefault_DgramRate;
495 // if -l has already been processed, mBufLenSet is true
496 // so don't overwrite that value.
497 if ( !isBuflenSet( mExtSettings ) ) {
498 mExtSettings->mBufLen = kDefault_UDPBufLen;
499 } else if ( mExtSettings->mBufLen < (int) ( sizeof( dgram_record )
500 + sizeof( client_hdr ) ) &&
501 !isCompat( mExtSettings ) ) {
502 setCompat( mExtSettings );
503 fprintf( stderr, warn_implied_compatibility, option );
507 case 'v': // print version and exit
510 case 'w': // TCP window size or socket send-buffer size (UDP/DCCP)
511 Settings_GetUpperCaseArg(optarg,outarg);
512 mExtSettings->mWinSize = byte_atoi(outarg);
515 case 'x': // Limit Reports
516 while ( *optarg != '\0' ) {
520 setNoSettReport( mExtSettings );
524 setNoConnReport( mExtSettings );
528 setNoDataReport( mExtSettings );
532 setNoServReport( mExtSettings );
536 setNoMultReport( mExtSettings );
539 fprintf(stderr, warn_invalid_report, *optarg);
545 case 'y': // Reporting Style
549 mExtSettings->mReportMode = kReport_CSV;
552 fprintf( stderr, warn_invalid_report_style, optarg );
557 // more esoteric options
558 case 'A': // set TCP congestion control algorithm
559 mExtSettings->congAlgo = new char[ strlen( optarg ) + 1 ];
560 strcpy( mExtSettings->congAlgo, optarg );
563 case 'B': // specify bind address
564 mExtSettings->mLocalhost = new char[ strlen( optarg ) + 1 ];
565 strcpy( mExtSettings->mLocalhost, optarg );
568 case 'C': // Run in Compatibility Mode
569 setCompat( mExtSettings );
570 if ( mExtSettings->mMode != kTest_Normal ) {
571 fprintf( stderr, warn_invalid_compatibility_option,
572 ( mExtSettings->mMode == kTest_DualTest ?
574 mExtSettings->mMode = kTest_Normal;
578 case 'D': // Run as a daemon
579 setDaemon( mExtSettings );
582 case 'F' : // Get the input for the data stream from a file
583 if ( mExtSettings->mThreadMode != kMode_Client ) {
584 fprintf( stderr, warn_invalid_server_option, option );
588 setFileInput( mExtSettings );
589 mExtSettings->mFileName = new char[strlen(optarg)+1];
590 strcpy( mExtSettings->mFileName, optarg);
593 case 'I' : // Set the stdin as the input source
594 if ( mExtSettings->mThreadMode != kMode_Client ) {
595 fprintf( stderr, warn_invalid_server_option, option );
599 setFileInput( mExtSettings );
600 setSTDIN( mExtSettings );
601 mExtSettings->mFileName = new char[strlen("<stdin>")+1];
602 strcpy( mExtSettings->mFileName,"<stdin>");
605 case 'L': // Listen Port (bidirectional testing client-side)
606 if ( mExtSettings->mThreadMode != kMode_Client ) {
607 fprintf( stderr, warn_invalid_server_option, option );
611 mExtSettings->mListenPort = atoi( optarg );
614 case 'M': // specify TCP MSS (maximum segment size)
615 Settings_GetUpperCaseArg(optarg,outarg);
617 mExtSettings->mMSS = byte_atoi( outarg );
620 case 'N': // specify TCP nodelay option (disable Jacobson's Algorithm)
621 setNoDelay( mExtSettings );
624 case 'P': // number of client threads
626 mExtSettings->mThreads = atoi( optarg );
628 if ( mExtSettings->mThreadMode != kMode_Server ) {
629 fprintf( stderr, warn_invalid_single_threaded, option );
631 mExtSettings->mThreads = atoi( optarg );
637 setRemoveService( mExtSettings );
641 // Convert into IPv4/v6 6-bit DiffServ codepoint. If string
642 // - consists of six 0/1 digits, it is seen as binary number;
643 // - is preceded by `0x', it is interpreted as hex number;
644 // - is preceded by `0', it is interpreted as octal number;
645 // - otherwise it is interpreted as decimal number.
646 // The maximum possible 6-bit value is 252 (0xfc).
647 if ( strspn(optarg, "01") == 6 )
648 mExtSettings->mTOS = strtol(optarg, NULL, 2);
650 mExtSettings->mTOS = strtol(optarg, NULL, 0);
651 if ( mExtSettings->mTOS < 0 || mExtSettings->mTOS > 0xfc )
652 die("Invalid DiffServ codepoint %s", optarg);
653 mExtSettings->mTOS <<= 2;
656 case 'T': // time-to-live for multicast
657 mExtSettings->mTTL = atoi( optarg );
660 case 'V': // IP Domain: the optional ar
661 mExtSettings->mSockAF = AF_INET6;
662 if ( optarg && optarg[0] == '4' )
663 mExtSettings->mSockAF = AF_INET;
665 case 'U': // single threaded UDP server
666 setSingleUDP( mExtSettings );
670 setSuggestWin( mExtSettings );
671 fprintf( stderr, "The -W option is not available in this release\n");
674 case 'Z': //DCCP CCID
675 mExtSettings->mCCID=atoi(optarg);
676 if(mExtSettings->mCCID > 255 || mExtSettings->mCCID<=0){
677 fprintf( stderr, "CCID %s is invalid\n", optarg);
681 default: // ignore unknown
686 void Settings_GetUpperCaseArg(const char *inarg, char *outarg) {
688 int len = strlen(inarg);
689 strcpy(outarg,inarg);
691 if ( (len > 0) && (inarg[len-1] >='a')
692 && (inarg[len-1] <= 'z') )
693 outarg[len-1]= outarg[len-1]+'A'-'a';
696 void Settings_GetLowerCaseArg(const char *inarg, char *outarg) {
698 int len = strlen(inarg);
699 strcpy(outarg,inarg);
701 if ( (len > 0) && (inarg[len-1] >='A')
702 && (inarg[len-1] <= 'Z') )
703 outarg[len-1]= outarg[len-1]-'A'+'a';
707 * Settings_GenerateListenerSettings
708 * Called to generate the settings to be passed to the Listener
709 * instance that will handle dual testings from the client side
710 * this should only return an instance if it was called on
711 * the thread_Settings instance generated from the command line
712 * for client side execution
714 void Settings_GenerateListenerSettings( thread_Settings *client, thread_Settings **listener ) {
715 if ( !isCompat( client ) &&
716 (client->mMode == kTest_DualTest || client->mMode == kTest_TradeOff) ) {
717 *listener = new thread_Settings;
718 memcpy(*listener, client, sizeof( thread_Settings ));
719 setCompat( (*listener) );
720 unsetDaemon( (*listener) );
721 if ( client->mListenPort != 0 ) {
722 (*listener)->mPort = client->mListenPort;
724 (*listener)->mPort = client->mPort;
726 (*listener)->mFileName = NULL;
727 (*listener)->mHost = NULL;
728 (*listener)->mLocalhost = NULL;
729 (*listener)->mOutputFileName = NULL;
730 (*listener)->mMode = kTest_Normal;
731 (*listener)->mThreadMode = kMode_Listener;
732 if ( client->mHost != NULL ) {
733 (*listener)->mHost = new char[strlen( client->mHost ) + 1];
734 strcpy( (*listener)->mHost, client->mHost );
736 if ( client->mLocalhost != NULL ) {
737 (*listener)->mLocalhost = new char[strlen( client->mLocalhost ) + 1];
738 strcpy( (*listener)->mLocalhost, client->mLocalhost );
746 * Settings_GenerateSpeakerSettings
747 * Called to generate the settings to be passed to the Speaker
748 * instance that will handle dual testings from the server side
749 * this should only return an instance if it was called on
750 * the thread_Settings instance generated from the command line
751 * for server side execution. This should be an inverse operation
752 * of GenerateClientHdr.
754 void Settings_GenerateClientSettings( thread_Settings *server,
755 thread_Settings **client,
757 int flags = ntohl(hdr->flags);
758 if ( (flags & HEADER_VERSION1) != 0 ) {
759 *client = new thread_Settings;
760 memcpy(*client, server, sizeof( thread_Settings ));
761 setCompat( (*client) );
762 (*client)->mTID = thread_zeroid();
763 (*client)->mPort = (unsigned short) ntohl(hdr->mPort);
764 (*client)->mThreads = ntohl(hdr->numThreads);
765 if ( hdr->bufferlen != 0 ) {
766 (*client)->mBufLen = ntohl(hdr->bufferlen);
768 if ( hdr->mWinBand != 0 ) {
769 if ( isPacketOriented( server ) ) {
770 (*client)->mDgramRate = ntohl(hdr->mWinBand);
772 (*client)->mWinSize = ntohl(hdr->mWinBand);
775 (*client)->mAmount = ntohl(hdr->mAmount);
776 if ( ((*client)->mAmount & 0x80000000) > 0 ) {
777 setModeTime( (*client) );
778 (*client)->mAmount |= 0xFFFFFFFF00000000LL;
779 (*client)->mAmount = -(*client)->mAmount;
781 (*client)->mFileName = NULL;
782 (*client)->mHost = NULL;
783 (*client)->mLocalhost = NULL;
784 (*client)->mOutputFileName = NULL;
785 (*client)->mMode = ((flags & RUN_NOW) == 0 ?
786 kTest_TradeOff : kTest_DualTest);
787 (*client)->mThreadMode = kMode_Client;
788 if ( server->mLocalhost != NULL ) {
789 (*client)->mLocalhost = new char[strlen( server->mLocalhost ) + 1];
790 strcpy( (*client)->mLocalhost, server->mLocalhost );
792 (*client)->mHost = new char[REPORT_ADDRLEN];
793 SockAddr_name(&server->peer, (*client)->mHost, REPORT_ADDRLEN);
800 * Settings_GenerateClientHdr
801 * Called to generate the client header to be passed to the
802 * server that will handle dual testings from the server side
803 * This should be an inverse operation of GenerateSpeakerSettings
805 void Settings_GenerateClientHdr( thread_Settings *client, client_hdr *hdr ) {
806 if ( client->mMode != kTest_Normal ) {
807 hdr->flags = htonl(HEADER_VERSION1);
811 if ( isBuflenSet( client ) ) {
812 hdr->bufferlen = htonl(client->mBufLen);
816 if ( isPacketOriented( client ) ) {
817 hdr->mWinBand = htonl(client->mDgramRate);
819 hdr->mWinBand = htonl(client->mWinSize);
821 if ( client->mListenPort != 0 ) {
822 hdr->mPort = htonl(client->mListenPort);
824 hdr->mPort = htonl(client->mPort);
826 hdr->numThreads = htonl(client->mThreads);
827 if ( isModeTime( client ) ) {
828 hdr->mAmount = htonl(-(long)client->mAmount);
830 hdr->mAmount = htonl((long)client->mAmount);
831 hdr->mAmount &= htonl( 0x7FFFFFFF );
833 if ( client->mMode == kTest_DualTest ) {
834 hdr->flags |= htonl(RUN_NOW);