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 {"version", no_argument, NULL, 'v'},
105 {"window", required_argument, NULL, 'w'},
106 {"reportexclude", required_argument, NULL, 'x'},
107 {"reportstyle",required_argument, NULL, 'y'},
109 // more esoteric options
110 {"algorithm", required_argument, NULL, 'A'},
111 {"bind", required_argument, NULL, 'B'},
112 {"compatibility", no_argument, NULL, 'C'},
113 {"daemon", no_argument, NULL, 'D'},
114 {"file_input", required_argument, NULL, 'F'},
115 {"stdin_input", no_argument, NULL, 'I'},
116 {"mss", required_argument, NULL, 'M'},
117 {"nodelay", no_argument, NULL, 'N'},
118 {"listenport", required_argument, NULL, 'L'},
119 {"parallel", required_argument, NULL, 'P'},
120 {"remove", no_argument, NULL, 'R'},
121 {"dscp", required_argument, NULL, 'S'},
122 {"ttl", required_argument, NULL, 'T'},
123 {"single_udp", no_argument, NULL, 'U'},
124 {"ipv6_domian", no_argument, NULL, 'V'},
125 {"suggest_win_size", no_argument, NULL, 'W'},
129 #define ENV_OPTIONS()
131 const struct option env_options[] =
133 {"IPERF_SINGLECLIENT", no_argument, NULL, '1'},
134 {"IPERF_DUALTEST", no_argument, NULL, '2'},
135 {"IPERF_BANDWIDTH", required_argument, NULL, 'b'},
136 {"IPERF_CLIENT", required_argument, NULL, 'c'},
137 {"IPERF_DCCP", no_argument, NULL, 'd'},
138 {"IPERF_FORMAT", required_argument, NULL, 'f'},
140 {"IPERF_INTERVAL", required_argument, NULL, 'i'},
141 {"IPERF_MCASTIFACE", required_argument, NULL, 'j'},
142 {"IPERF_LEN", required_argument, NULL, 'l'},
143 {"IPERF_PRINT_MSS", no_argument, NULL, 'm'},
144 {"IPERF_NUM", required_argument, NULL, 'n'},
145 {"IPERF_PORT", required_argument, NULL, 'p'},
146 {"IPERF_TRADEOFF", no_argument, NULL, 'r'},
147 {"IPERF_SERVER", no_argument, NULL, 's'},
148 {"IPERF_TIME", required_argument, NULL, 't'},
149 {"IPERF_UDP", no_argument, NULL, 'u'},
151 {"TCP_WINDOW_SIZE", required_argument, NULL, 'w'},
152 {"IPERF_REPORTEXCLUDE", required_argument, NULL, 'x'},
153 {"IPERF_REPORTSTYLE",required_argument, NULL, 'y'},
155 // more esoteric options
156 {"IPERF_CC", required_argument, NULL, 'A'},
157 {"IPERF_BIND", required_argument, NULL, 'B'},
158 {"IPERF_COMPAT", no_argument, NULL, 'C'},
159 {"IPERF_DAEMON", no_argument, NULL, 'D'},
160 {"IPERF_FILE_INPUT", required_argument, NULL, 'F'},
161 {"IPERF_STDIN_INPUT", no_argument, NULL, 'I'},
162 {"IPERF_MSS", required_argument, NULL, 'M'},
163 {"IPERF_NODELAY", no_argument, NULL, 'N'},
164 {"IPERF_LISTENPORT", required_argument, NULL, 'L'},
165 {"IPERF_PARALLEL", required_argument, NULL, 'P'},
166 {"IPERF_DSCP", required_argument, NULL, 'S'},
167 {"IPERF_TTL", required_argument, NULL, 'T'},
168 {"IPERF_SINGLE_UDP", no_argument, NULL, 'U'},
169 {"IPERF_IPV6_DOMAIN", no_argument, NULL, 'V'},
170 {"IPERF_SUGGEST_WIN_SIZE", required_argument, NULL, 'W'},
174 #define SHORT_OPTIONS()
176 const char short_options[] =
177 "12b::c:df:hi:j:l:mn:o:p:rst:uvw:x:y:A:B:CDF:IJ:L:M:NP:RS:T:UV:W";
179 /* -------------------------------------------------------------------
181 * ------------------------------------------------------------------- */
184 const long kDefault_DgramRate = 1024 * 1024; // -u if set, 1 Mbit/sec
185 const int kDefault_UDPBufLen = 1470; // -u if set, read/write 1470 bytes
186 // 1470 bytes is small enough to be sending one packet per datagram on ethernet
188 // 1450 bytes is small enough to be sending one packet per datagram on ethernet
189 // **** with IPv6 ****
190 const int kDefault_DCCPBufLen = 1420; // -d
191 // old DCCPv4: MPS=1424; new DCCPv4: MPS=1440; new DCCPv6: MPS=1420 (above)
193 /* -------------------------------------------------------------------
194 * Initialize all settings to defaults.
195 * ------------------------------------------------------------------- */
197 void Settings_Initialize( thread_Settings *main ) {
198 // Everything defaults to zero or NULL with
199 // this memset. Only need to set non-zero values
201 memset( main, 0, sizeof(thread_Settings) );
202 main->mSock = INVALID_SOCKET;
203 //main->mSockAF = AF_UNSPEC
204 main->mReportMode = kReport_Default;
206 main->flags = FLAG_MODETIME | FLAG_STDOUT; // Default time and stdout
207 //main->mDgramRate = 0; // -b, ie. TCP mode
208 main->mProtocol = kProto_TCP; // -u / -d
209 //main->mHost = NULL; // -c, none, required for client
210 main->mMode = kTest_Normal; // -2, mMode == kTest_DualTest
211 main->mFormat = 'a'; // -f, adaptive bits
213 //main->mBufLenSet = false; // -l,
214 main->mBufLen = 8 * 1024; // -l, 8 Kbyte
215 //main->mInterval = 0; // -i, ie. no periodic bw reports
216 //main->mPrintMSS = false; // -m, don't print MSS
217 // mAmount is time also // -n, N/A
218 //main->mOutputFileName = NULL; // -o, filename
219 main->mPort = 5001; // -p, ttcp port
220 // mMode = kTest_Normal; // -r, mMode == kTest_TradeOff
221 main->mThreadMode = kMode_Unknown; // -s, or -c, none
222 main->mAmount = 1000; // -t, 10 seconds
223 // mDgramRate // -u, N/A, see kDefault_DgramRate
224 // skip version // -v,
225 //main->mWinSize = 0; // -w, ie. don't set window
227 // more esoteric options
228 //main->mLocalhost = NULL; // -B, bind address - none
229 //main->mCompat = false; // -C, run in Compatibility mode
230 //main->mDaemon = false; // -D, run as a daemon
231 //main->mFileInput = false; // -F,
232 //main->mFileName = NULL; // -F, filename
233 //main->mStdin = false; // -I, default not stdin
234 //main->mMcastIface = 0; // -J, default: host chooses interface
235 //main->mListenPort = 0; // -L, listen port
236 //main->mMSS = 0; // -M, ie. don't set MSS
237 //main->mNodelay = false; // -N, don't set nodelay
238 //main->mThreads = 0; // -P,
239 //main->mRemoveService = false; // -R,
240 //main->mTOS = 0; // -S, ie. don't set type of service
241 main->mTTL = 1; // -T, link-local TTL
242 //main->mDomain = kMode_IPv4; // -V,
243 //main->mSuggestWin = false; // -W, Suggest the window size.
247 void Settings_Copy( thread_Settings *from, thread_Settings **into ) {
248 *into = new thread_Settings;
249 memcpy( *into, from, sizeof(thread_Settings) );
250 if ( from->mHost != NULL ) {
251 (*into)->mHost = new char[ strlen(from->mHost) + 1];
252 strcpy( (*into)->mHost, from->mHost );
254 if ( from->mOutputFileName != NULL ) {
255 (*into)->mOutputFileName = new char[ strlen(from->mOutputFileName) + 1];
256 strcpy( (*into)->mOutputFileName, from->mOutputFileName );
258 if ( from->mLocalhost != NULL ) {
259 (*into)->mLocalhost = new char[ strlen(from->mLocalhost) + 1];
260 strcpy( (*into)->mLocalhost, from->mLocalhost );
262 if ( from->mFileName != NULL ) {
263 (*into)->mFileName = new char[ strlen(from->mFileName) + 1];
264 strcpy( (*into)->mFileName, from->mFileName );
266 // Zero out certain entries
267 (*into)->mTID = thread_zeroid();
268 (*into)->runNext = NULL;
269 (*into)->runNow = NULL;
272 /* -------------------------------------------------------------------
273 * Delete memory: Does not clean up open file pointers or ptr_parents
274 * ------------------------------------------------------------------- */
276 void Settings_Destroy( thread_Settings *mSettings) {
277 DELETE_ARRAY( mSettings->mHost );
278 DELETE_ARRAY( mSettings->mLocalhost );
279 DELETE_ARRAY( mSettings->mFileName );
280 DELETE_ARRAY( mSettings->mOutputFileName );
281 DELETE_PTR( mSettings );
284 /* -------------------------------------------------------------------
285 * Parses settings from user's environment variables.
286 * ------------------------------------------------------------------- */
287 void Settings_ParseEnvironment( thread_Settings *mSettings ) {
291 while ( env_options[i].name != NULL ) {
292 theVariable = getenv( env_options[i].name );
293 if ( theVariable != NULL ) {
294 Settings_Interpret( env_options[i].val, theVariable, mSettings );
298 } // end ParseEnvironment
300 /* -------------------------------------------------------------------
301 * Parse settings from app's command line.
302 * ------------------------------------------------------------------- */
304 void Settings_ParseCommandLine( int argc, char **argv, thread_Settings *mSettings ) {
307 gnu_getopt_long( argc, argv, short_options,
308 long_options, NULL )) != EOF ) {
309 Settings_Interpret( option, gnu_optarg, mSettings );
312 for ( int i = gnu_optind; i < argc; i++ ) {
313 fprintf( stderr, "%s: ignoring extra argument -- %s\n", argv[0], argv[i] );
315 } // end ParseCommandLine
317 /* -------------------------------------------------------------------
318 * Interpret individual options, either from the command line
319 * or from environment variables.
320 * ------------------------------------------------------------------- */
322 void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtSettings ) {
326 case '1': // Single Client
327 setSingleClient( mExtSettings );
330 case '2': // Dual-test Mode
331 if ( mExtSettings->mThreadMode != kMode_Client ) {
332 fprintf( stderr, warn_invalid_server_option, option );
335 if ( isCompat( mExtSettings ) ) {
336 fprintf( stderr, warn_invalid_compatibility_option, option );
339 mExtSettings->mMode = kTest_DualTest;
341 fprintf( stderr, warn_invalid_single_threaded, option );
342 mExtSettings->mMode = kTest_TradeOff;
347 // This sets packet-oriented mode. The optional
348 // argument sets datagram bandwidth (as before).
349 // If not given, a default bandwith is used.
350 setPacketOriented(mExtSettings);
353 Settings_GetLowerCaseArg(optarg, outarg);
354 mExtSettings->mDgramRate = byte_atoi(outarg);
356 mExtSettings->mDgramRate = kDefault_DgramRate;
359 case 'c': // client mode w/ server host to connect to
360 mExtSettings->mHost = new char[ strlen( optarg ) + 1 ];
361 strcpy( mExtSettings->mHost, optarg );
363 if ( mExtSettings->mThreadMode == kMode_Unknown ) {
364 mExtSettings->mThreadMode = kMode_Client;
365 mExtSettings->mThreads = 1;
369 case 'd': // DCCP as transport
370 mExtSettings->mProtocol = kProto_DCCP;
372 // if -l has already been processed, mBufLenSet is true
373 // so don't overwrite that value.
374 if ( !isBuflenSet( mExtSettings ) )
375 mExtSettings->mBufLen = kDefault_DCCPBufLen;
379 case 'f': // format to print in
380 mExtSettings->mFormat = (*optarg);
383 case 'h': // print help and exit
386 case 'i': // specify interval between periodic bw reports
387 mExtSettings->mInterval = atof( optarg );
388 if ( mExtSettings->mInterval < 0.5 ) {
389 fprintf (stderr, report_interval_small, mExtSettings->mInterval);
390 mExtSettings->mInterval = 0.5;
395 case 'J': // multicast interface to join multicast address on
396 mExtSettings->mMcastIface = if_nametoindex(optarg);
397 if (!mExtSettings->mMcastIface)
398 die("Interface \"%s\" does not work for -j/-J.", optarg);
401 case 'l': // length of each buffer
402 Settings_GetUpperCaseArg(optarg,outarg);
403 mExtSettings->mBufLen = byte_atoi( outarg );
404 setBuflenSet( mExtSettings );
406 if ( !isPacketOriented( mExtSettings ) ) {
407 if ( mExtSettings->mBufLen < (int) sizeof( client_hdr ) &&
408 !isCompat( mExtSettings ) ) {
409 setCompat( mExtSettings );
410 fprintf( stderr, warn_implied_compatibility, option );
413 if ( mExtSettings->mBufLen < (int) sizeof( dgram_record ) ) {
414 mExtSettings->mBufLen = sizeof( dgram_record );
415 fprintf( stderr, warn_buffer_too_small, mExtSettings->mBufLen );
417 if ( !isCompat( mExtSettings ) &&
418 mExtSettings->mBufLen < (int) ( sizeof( dgram_record )
419 + sizeof( client_hdr ) ) ) {
420 setCompat( mExtSettings );
421 fprintf( stderr, warn_implied_compatibility, option );
427 case 'm': // print TCP MSS
428 setPrintMSS( mExtSettings );
431 case 'n': // bytes of data
432 // amount mode (instead of time mode)
433 unsetModeTime( mExtSettings );
434 Settings_GetUpperCaseArg(optarg,outarg);
435 mExtSettings->mAmount = byte_atoi( outarg );
438 case 'o' : // output the report and other messages into the file
439 unsetSTDOUT( mExtSettings );
440 mExtSettings->mOutputFileName = new char[strlen(optarg)+1];
441 strcpy( mExtSettings->mOutputFileName, optarg);
444 case 'p': // server port
445 mExtSettings->mPort = atoi( optarg );
448 case 'r': // test mode tradeoff
449 if ( mExtSettings->mThreadMode != kMode_Client ) {
450 fprintf( stderr, warn_invalid_server_option, option );
453 if ( isCompat( mExtSettings ) ) {
454 fprintf( stderr, warn_invalid_compatibility_option, option );
457 mExtSettings->mMode = kTest_TradeOff;
460 case 's': // server mode
461 if ( mExtSettings->mThreadMode != kMode_Unknown ) {
462 fprintf( stderr, warn_invalid_client_option, option );
466 mExtSettings->mThreadMode = kMode_Listener;
469 case 't': // seconds to write for
470 // time mode (instead of amount mode)
471 setModeTime( mExtSettings );
472 mExtSettings->mAmount = (int) (atof( optarg ) * 100.0);
475 case 'u': // UDP instead of TCP
476 mExtSettings->mProtocol = kProto_UDP;
478 setPacketOriented(mExtSettings);
479 // if -b has already been processed, UDP rate will
480 // already be non-zero, so don't overwrite that value
481 if ( mExtSettings->mDgramRate == 0 )
482 mExtSettings->mDgramRate = kDefault_DgramRate;
484 // if -l has already been processed, mBufLenSet is true
485 // so don't overwrite that value.
486 if ( !isBuflenSet( mExtSettings ) ) {
487 mExtSettings->mBufLen = kDefault_UDPBufLen;
488 } else if ( mExtSettings->mBufLen < (int) ( sizeof( dgram_record )
489 + sizeof( client_hdr ) ) &&
490 !isCompat( mExtSettings ) ) {
491 setCompat( mExtSettings );
492 fprintf( stderr, warn_implied_compatibility, option );
496 case 'v': // print version and exit
499 case 'w': // TCP window size or socket send-buffer size (UDP/DCCP)
500 Settings_GetUpperCaseArg(optarg,outarg);
501 mExtSettings->mWinSize = byte_atoi(outarg);
504 case 'x': // Limit Reports
505 while ( *optarg != '\0' ) {
509 setNoSettReport( mExtSettings );
513 setNoConnReport( mExtSettings );
517 setNoDataReport( mExtSettings );
521 setNoServReport( mExtSettings );
525 setNoMultReport( mExtSettings );
528 fprintf(stderr, warn_invalid_report, *optarg);
534 case 'y': // Reporting Style
538 mExtSettings->mReportMode = kReport_CSV;
541 fprintf( stderr, warn_invalid_report_style, optarg );
546 // more esoteric options
547 case 'A': // set TCP congestion control algorithm
548 mExtSettings->congAlgo = new char[ strlen( optarg ) + 1 ];
549 strcpy( mExtSettings->congAlgo, optarg );
552 case 'B': // specify bind address
553 mExtSettings->mLocalhost = new char[ strlen( optarg ) + 1 ];
554 strcpy( mExtSettings->mLocalhost, optarg );
557 case 'C': // Run in Compatibility Mode
558 setCompat( mExtSettings );
559 if ( mExtSettings->mMode != kTest_Normal ) {
560 fprintf( stderr, warn_invalid_compatibility_option,
561 ( mExtSettings->mMode == kTest_DualTest ?
563 mExtSettings->mMode = kTest_Normal;
567 case 'D': // Run as a daemon
568 setDaemon( mExtSettings );
571 case 'F' : // Get the input for the data stream from a file
572 if ( mExtSettings->mThreadMode != kMode_Client ) {
573 fprintf( stderr, warn_invalid_server_option, option );
577 setFileInput( mExtSettings );
578 mExtSettings->mFileName = new char[strlen(optarg)+1];
579 strcpy( mExtSettings->mFileName, optarg);
582 case 'I' : // Set the stdin as the input source
583 if ( mExtSettings->mThreadMode != kMode_Client ) {
584 fprintf( stderr, warn_invalid_server_option, option );
588 setFileInput( mExtSettings );
589 setSTDIN( mExtSettings );
590 mExtSettings->mFileName = new char[strlen("<stdin>")+1];
591 strcpy( mExtSettings->mFileName,"<stdin>");
594 case 'L': // Listen Port (bidirectional testing client-side)
595 if ( mExtSettings->mThreadMode != kMode_Client ) {
596 fprintf( stderr, warn_invalid_server_option, option );
600 mExtSettings->mListenPort = atoi( optarg );
603 case 'M': // specify TCP MSS (maximum segment size)
604 Settings_GetUpperCaseArg(optarg,outarg);
606 mExtSettings->mMSS = byte_atoi( outarg );
609 case 'N': // specify TCP nodelay option (disable Jacobson's Algorithm)
610 setNoDelay( mExtSettings );
613 case 'P': // number of client threads
615 mExtSettings->mThreads = atoi( optarg );
617 if ( mExtSettings->mThreadMode != kMode_Server ) {
618 fprintf( stderr, warn_invalid_single_threaded, option );
620 mExtSettings->mThreads = atoi( optarg );
626 setRemoveService( mExtSettings );
630 // Convert into IPv4/v6 6-bit DiffServ codepoint. If string
631 // - consists of six 0/1 digits, it is seen as binary number;
632 // - is preceded by `0x', it is interpreted as hex number;
633 // - is preceded by `0', it is interpreted as octal number;
634 // - otherwise it is interpreted as decimal number.
635 // The maximum possible 6-bit value is 252 (0xfc).
636 if ( strspn(optarg, "01") == 6 )
637 mExtSettings->mTOS = strtol(optarg, NULL, 2);
639 mExtSettings->mTOS = strtol(optarg, NULL, 0);
640 if ( mExtSettings->mTOS < 0 || mExtSettings->mTOS > 0xfc )
641 die("Invalid DiffServ codepoint %s", optarg);
642 mExtSettings->mTOS <<= 2;
645 case 'T': // time-to-live for multicast
646 mExtSettings->mTTL = atoi( optarg );
649 case 'V': // IP Domain: the optional ar
650 mExtSettings->mSockAF = AF_INET6;
651 if ( optarg && optarg[0] == '4' )
652 mExtSettings->mSockAF = AF_INET;
654 case 'U': // single threaded UDP server
655 setSingleUDP( mExtSettings );
659 setSuggestWin( mExtSettings );
660 fprintf( stderr, "The -W option is not available in this release\n");
663 default: // ignore unknown
668 void Settings_GetUpperCaseArg(const char *inarg, char *outarg) {
670 int len = strlen(inarg);
671 strcpy(outarg,inarg);
673 if ( (len > 0) && (inarg[len-1] >='a')
674 && (inarg[len-1] <= 'z') )
675 outarg[len-1]= outarg[len-1]+'A'-'a';
678 void Settings_GetLowerCaseArg(const char *inarg, char *outarg) {
680 int len = strlen(inarg);
681 strcpy(outarg,inarg);
683 if ( (len > 0) && (inarg[len-1] >='A')
684 && (inarg[len-1] <= 'Z') )
685 outarg[len-1]= outarg[len-1]-'A'+'a';
689 * Settings_GenerateListenerSettings
690 * Called to generate the settings to be passed to the Listener
691 * instance that will handle dual testings from the client side
692 * this should only return an instance if it was called on
693 * the thread_Settings instance generated from the command line
694 * for client side execution
696 void Settings_GenerateListenerSettings( thread_Settings *client, thread_Settings **listener ) {
697 if ( !isCompat( client ) &&
698 (client->mMode == kTest_DualTest || client->mMode == kTest_TradeOff) ) {
699 *listener = new thread_Settings;
700 memcpy(*listener, client, sizeof( thread_Settings ));
701 setCompat( (*listener) );
702 unsetDaemon( (*listener) );
703 if ( client->mListenPort != 0 ) {
704 (*listener)->mPort = client->mListenPort;
706 (*listener)->mPort = client->mPort;
708 (*listener)->mFileName = NULL;
709 (*listener)->mHost = NULL;
710 (*listener)->mLocalhost = NULL;
711 (*listener)->mOutputFileName = NULL;
712 (*listener)->mMode = kTest_Normal;
713 (*listener)->mThreadMode = kMode_Listener;
714 if ( client->mHost != NULL ) {
715 (*listener)->mHost = new char[strlen( client->mHost ) + 1];
716 strcpy( (*listener)->mHost, client->mHost );
718 if ( client->mLocalhost != NULL ) {
719 (*listener)->mLocalhost = new char[strlen( client->mLocalhost ) + 1];
720 strcpy( (*listener)->mLocalhost, client->mLocalhost );
728 * Settings_GenerateSpeakerSettings
729 * Called to generate the settings to be passed to the Speaker
730 * instance that will handle dual testings from the server side
731 * this should only return an instance if it was called on
732 * the thread_Settings instance generated from the command line
733 * for server side execution. This should be an inverse operation
734 * of GenerateClientHdr.
736 void Settings_GenerateClientSettings( thread_Settings *server,
737 thread_Settings **client,
739 int flags = ntohl(hdr->flags);
740 if ( (flags & HEADER_VERSION1) != 0 ) {
741 *client = new thread_Settings;
742 memcpy(*client, server, sizeof( thread_Settings ));
743 setCompat( (*client) );
744 (*client)->mTID = thread_zeroid();
745 (*client)->mPort = (unsigned short) ntohl(hdr->mPort);
746 (*client)->mThreads = ntohl(hdr->numThreads);
747 if ( hdr->bufferlen != 0 ) {
748 (*client)->mBufLen = ntohl(hdr->bufferlen);
750 if ( hdr->mWinBand != 0 ) {
751 if ( isPacketOriented( server ) ) {
752 (*client)->mDgramRate = ntohl(hdr->mWinBand);
754 (*client)->mWinSize = ntohl(hdr->mWinBand);
757 (*client)->mAmount = ntohl(hdr->mAmount);
758 if ( ((*client)->mAmount & 0x80000000) > 0 ) {
759 setModeTime( (*client) );
760 (*client)->mAmount |= 0xFFFFFFFF00000000LL;
761 (*client)->mAmount = -(*client)->mAmount;
763 (*client)->mFileName = NULL;
764 (*client)->mHost = NULL;
765 (*client)->mLocalhost = NULL;
766 (*client)->mOutputFileName = NULL;
767 (*client)->mMode = ((flags & RUN_NOW) == 0 ?
768 kTest_TradeOff : kTest_DualTest);
769 (*client)->mThreadMode = kMode_Client;
770 if ( server->mLocalhost != NULL ) {
771 (*client)->mLocalhost = new char[strlen( server->mLocalhost ) + 1];
772 strcpy( (*client)->mLocalhost, server->mLocalhost );
774 (*client)->mHost = new char[REPORT_ADDRLEN];
775 SockAddr_name(&server->peer, (*client)->mHost, REPORT_ADDRLEN);
782 * Settings_GenerateClientHdr
783 * Called to generate the client header to be passed to the
784 * server that will handle dual testings from the server side
785 * This should be an inverse operation of GenerateSpeakerSettings
787 void Settings_GenerateClientHdr( thread_Settings *client, client_hdr *hdr ) {
788 if ( client->mMode != kTest_Normal ) {
789 hdr->flags = htonl(HEADER_VERSION1);
793 if ( isBuflenSet( client ) ) {
794 hdr->bufferlen = htonl(client->mBufLen);
798 if ( isPacketOriented( client ) ) {
799 hdr->mWinBand = htonl(client->mDgramRate);
801 hdr->mWinBand = htonl(client->mWinSize);
803 if ( client->mListenPort != 0 ) {
804 hdr->mPort = htonl(client->mListenPort);
806 hdr->mPort = htonl(client->mPort);
808 hdr->numThreads = htonl(client->mThreads);
809 if ( isModeTime( client ) ) {
810 hdr->mAmount = htonl(-(long)client->mAmount);
812 hdr->mAmount = htonl((long)client->mAmount);
813 hdr->mAmount &= htonl( 0x7FFFFFFF );
815 if ( client->mMode == kTest_DualTest ) {
816 hdr->flags |= htonl(RUN_NOW);