/*--------------------------------------------------------------- * Copyright (c) 1999,2000,2001,2002,2003 * The Board of Trustees of the University of Illinois * All Rights Reserved. *--------------------------------------------------------------- * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software (Iperf) and associated * documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do * so, subject to the following conditions: * * * Redistributions of source code must retain the above * copyright notice, this list of conditions and * the following disclaimers. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimers in the documentation and/or other materials * provided with the distribution. * * * Neither the names of the University of Illinois, NCSA, * nor the names of its contributors may be used to endorse * or promote products derived from this Software without * specific prior written permission. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ________________________________________________________________ * National Laboratory for Applied Network Research * National Center for Supercomputing Applications * University of Illinois at Urbana-Champaign * http://www.ncsa.uiuc.edu * ________________________________________________________________ * * Settings.cpp * by Mark Gates <mgates@nlanr.net> * & Ajay Tirumala <tirumala@ncsa.uiuc.edu> * ------------------------------------------------------------------- * Stores and parses the initial values for all the global variables. * ------------------------------------------------------------------- * headers * uses * <stdlib.h> * <stdio.h> * <string.h> * * <unistd.h>
* ------------------------------------------------------------------- */
/* ------------------------------------------------------------------- * command line options * * The option struct essentially maps a long option name (--foobar) * or environment variable ($FOOBAR) to its short option char (f).
* ------------------------------------------------------------------- */ #define LONG_OPTIONS()
constlong kDefault_UDPRate = 1024 * 1024; // -u if set, 1 Mbit/sec constint kDefault_UDPBufLen = 1470; // -u if set, read/write 1470 bytes // 1470 bytes is small enough to be sending one packet per datagram on ethernet
// 1450 bytes is small enough to be sending one packet per datagram on ethernet // **** with IPv6 ****
/* ------------------------------------------------------------------- * Initialize all settings to defaults.
* ------------------------------------------------------------------- */
void Settings_Initialize( thread_Settings *main ) { // Everything defaults to zero or NULL with // this memset. Only need to set non-zero values // below.
memset( main, 0, sizeof(thread_Settings) );
main->mSock = INVALID_SOCKET;
main->mReportMode = kReport_Default; // option, defaults
main->flags = FLAG_MODETIME | FLAG_STDOUT; // Default time and stdout //main->mUDPRate = 0; // -b, ie. TCP mode //main->mHost = NULL; // -c, none, required for client
main->mMode = kTest_Normal; // -d, mMode == kTest_DualTest
main->mFormat = 'a'; // -f, adaptive bits // skip help // -h, //main->mBufLenSet = false; // -l,
main->mBufLen = 128 * 1024; // -l, 8 Kbyte //main->mInterval = 0; // -i, ie. no periodic bw reports //main->mPrintMSS = false; // -m, don't print MSS // mAmount is time also // -n, N/A //main->mOutputFileName = NULL; // -o, filename
main->mPort = 5001; // -p, ttcp port // mMode = kTest_Normal; // -r, mMode == kTest_TradeOff
main->mThreadMode = kMode_Unknown; // -s, or -c, none
main->mAmount = 1000; // -t, 10 seconds // mUDPRate > 0 means UDP // -u, N/A, see kDefault_UDPRate // skip version // -v, //main->mTCPWin = 0; // -w, ie. don't set window
// more esoteric options //main->mLocalhost = NULL; // -B, none //main->mCompat = false; // -C, run in Compatibility mode //main->mDaemon = false; // -D, run as a daemon //main->mFileInput = false; // -F, //main->mFileName = NULL; // -F, filename //main->mStdin = false; // -I, default not stdin //main->mListenPort = 0; // -L, listen port //main->mMSS = 0; // -M, ie. don't set MSS //main->mNodelay = false; // -N, don't set nodelay //main->mThreads = 0; // -P, //main->mRemoveService = false; // -R, //main->mTOS = 0; // -S, ie. don't set type of service
main->mTTL = 1; // -T, link-local TTL //main->mDomain = kMode_IPv4; // -V, //main->mSuggestWin = false; // -W, Suggest the window size.
/* ------------------------------------------------------------------- * Delete memory: Does not clean up open file pointers or ptr_parents
* ------------------------------------------------------------------- */
for ( int i = gnu_optind; i < argc; i++ ) {
fprintf( stderr, "%s: ignoring extra argument -- %s\n", argv[0], argv[i] );
}
} // end ParseCommandLine
/* ------------------------------------------------------------------- * Interpret individual options, either from the command line * or from environment variables.
* ------------------------------------------------------------------- */
// if -l has already been processed, mBufLenSet is true // so don't overwrite that value. if ( !isBuflenSet( mExtSettings ) ) {
mExtSettings->mBufLen = kDefault_UDPBufLen;
} break;
case'c': // client mode w/ server host to connect to
mExtSettings->mHost = newchar[ strlen( optarg ) + 1 ];
strcpy( mExtSettings->mHost, optarg );
case'n': // bytes of data // amount mode (instead of time mode)
unsetModeTime( mExtSettings );
Settings_GetUpperCaseArg(optarg,outarg);
mExtSettings->mAmount = byte_atoi( outarg ); break;
case'o' : // output the report and other messages into the file
unsetSTDOUT( mExtSettings );
mExtSettings->mOutputFileName = newchar[strlen(optarg)+1];
strcpy( mExtSettings->mOutputFileName, optarg); break;
case'p': // server port
mExtSettings->mPort = atoi( optarg ); break;
case't': // seconds to write for // time mode (instead of amount mode)
setModeTime( mExtSettings );
mExtSettings->mAmount = (int) (atof( optarg ) * 100.0); break;
case'u': // UDP instead of TCP // if -b has already been processed, UDP rate will // already be non-zero, so don't overwrite that value if ( !isUDP( mExtSettings ) ) {
setUDP( mExtSettings );
mExtSettings->mUDPRate = kDefault_UDPRate;
}
// if -l has already been processed, mBufLenSet is true // so don't overwrite that value. if ( !isBuflenSet( mExtSettings ) ) {
mExtSettings->mBufLen = kDefault_UDPBufLen;
} elseif ( mExtSettings->mBufLen < (int) ( sizeof( UDP_datagram )
+ sizeof( client_hdr ) ) &&
!isCompat( mExtSettings ) ) {
setCompat( mExtSettings );
fprintf( stderr, warn_implied_compatibility, option );
} break;
case'v': // print version and exit
fprintf( stderr, version ); exit(1); break;
case'D': // Run as a daemon
setDaemon( mExtSettings ); break;
case'F' : // Get the input for the data stream from a file if ( mExtSettings->mThreadMode != kMode_Client ) {
fprintf( stderr, warn_invalid_server_option, option ); break;
}
case'I' : // Set the stdin as the input source if ( mExtSettings->mThreadMode != kMode_Client ) {
fprintf( stderr, warn_invalid_server_option, option ); break;
}
case'S': // IP type-of-service // TODO use a function that understands base-2 // the zero base here allows the user to specify // "0x#" hex, "0#" octal, and "#" decimal numbers
mExtSettings->mTOS = strtol( optarg, NULL, 0 ); break;
case'W' :
setSuggestWin( mExtSettings );
fprintf( stderr, "The -W option is not available in this release\n"); break;
case'Z': #ifdef TCP_CONGESTION
setCongestionControl( mExtSettings );
mExtSettings->mCongestion = newchar[strlen(optarg)+1];
strcpy( mExtSettings->mCongestion, optarg); #else
fprintf( stderr, "The -Z option is not available on this operating system\n"); #endif break;
default: // ignore unknown break;
}
} // end Interpret
/* * Settings_GenerateListenerSettings * Called to generate the settings to be passed to the Listener * instance that will handle dual testings from the client side * this should only return an instance if it was called on * the thread_Settings instance generated from the command line * for client side execution
*/ void Settings_GenerateListenerSettings( thread_Settings *client, thread_Settings **listener ) { if ( !isCompat( client ) &&
(client->mMode == kTest_DualTest || client->mMode == kTest_TradeOff) ) {
*listener = new thread_Settings;
memcpy(*listener, client, sizeof( thread_Settings ));
setCompat( (*listener) );
unsetDaemon( (*listener) ); if ( client->mListenPort != 0 ) {
(*listener)->mPort = client->mListenPort;
} else {
(*listener)->mPort = client->mPort;
}
(*listener)->mFileName = NULL;
(*listener)->mHost = NULL;
(*listener)->mLocalhost = NULL;
(*listener)->mOutputFileName = NULL;
(*listener)->mMode = kTest_Normal;
(*listener)->mThreadMode = kMode_Listener; if ( client->mHost != NULL ) {
(*listener)->mHost = newchar[strlen( client->mHost ) + 1];
strcpy( (*listener)->mHost, client->mHost );
} if ( client->mLocalhost != NULL ) {
(*listener)->mLocalhost = newchar[strlen( client->mLocalhost ) + 1];
strcpy( (*listener)->mLocalhost, client->mLocalhost );
}
} else {
*listener = NULL;
}
}
/* * Settings_GenerateSpeakerSettings * Called to generate the settings to be passed to the Speaker * instance that will handle dual testings from the server side * this should only return an instance if it was called on * the thread_Settings instance generated from the command line * for server side execution. This should be an inverse operation * of GenerateClientHdr.
*/ void Settings_GenerateClientSettings( thread_Settings *server,
thread_Settings **client,
client_hdr *hdr ) { int flags = ntohl(hdr->flags); if ( (flags & HEADER_VERSION1) != 0 ) {
*client = new thread_Settings;
memcpy(*client, server, sizeof( thread_Settings ));
setCompat( (*client) );
(*client)->mTID = thread_zeroid();
(*client)->mPort = (unsignedshort) ntohl(hdr->mPort);
(*client)->mThreads = ntohl(hdr->numThreads); if ( hdr->bufferlen != 0 ) {
(*client)->mBufLen = ntohl(hdr->bufferlen);
} if ( hdr->mWinBand != 0 ) { if ( isUDP( server ) ) {
(*client)->mUDPRate = ntohl(hdr->mWinBand);
} else {
(*client)->mTCPWin = ntohl(hdr->mWinBand);
}
}
(*client)->mAmount = ntohl(hdr->mAmount); if ( ((*client)->mAmount & 0x80000000) > 0 ) {
setModeTime( (*client) ); #ifndef WIN32
(*client)->mAmount |= 0xFFFFFFFF00000000LL; #else
(*client)->mAmount |= 0xFFFFFFFF00000000; #endif
(*client)->mAmount = -(*client)->mAmount;
}
(*client)->mFileName = NULL;
(*client)->mHost = NULL;
(*client)->mLocalhost = NULL;
(*client)->mOutputFileName = NULL;
(*client)->mMode = ((flags & RUN_NOW) == 0 ?
kTest_TradeOff : kTest_DualTest);
(*client)->mThreadMode = kMode_Client; if ( server->mLocalhost != NULL ) {
(*client)->mLocalhost = newchar[strlen( server->mLocalhost ) + 1];
strcpy( (*client)->mLocalhost, server->mLocalhost );
}
(*client)->mHost = newchar[REPORT_ADDRLEN]; if ( ((sockaddr*)&server->peer)->sa_family == AF_INET ) {
inet_ntop( AF_INET, &((sockaddr_in*)&server->peer)->sin_addr,
(*client)->mHost, REPORT_ADDRLEN);
} #ifdef HAVE_IPV6 else {
inet_ntop( AF_INET6, &((sockaddr_in6*)&server->peer)->sin6_addr,
(*client)->mHost, REPORT_ADDRLEN);
} #endif
} else {
*client = NULL;
}
}
/* * Settings_GenerateClientHdr * Called to generate the client header to be passed to the * server that will handle dual testings from the server side * This should be an inverse operation of GenerateSpeakerSettings
*/ void Settings_GenerateClientHdr( thread_Settings *client, client_hdr *hdr ) { if ( client->mMode != kTest_Normal ) {
hdr->flags = htonl(HEADER_VERSION1);
} else {
hdr->flags = 0;
} if ( isBuflenSet( client ) ) {
hdr->bufferlen = htonl(client->mBufLen);
} else {
hdr->bufferlen = 0;
} if ( isUDP( client ) ) {
hdr->mWinBand = htonl(client->mUDPRate);
} else {
hdr->mWinBand = htonl(client->mTCPWin);
} if ( client->mListenPort != 0 ) {
hdr->mPort = htonl(client->mListenPort);
} else {
hdr->mPort = htonl(client->mPort);
}
hdr->numThreads = htonl(client->mThreads); if ( isModeTime( client ) ) {
hdr->mAmount = htonl(-(long)client->mAmount);
} else {
hdr->mAmount = htonl((long)client->mAmount);
hdr->mAmount &= htonl( 0x7FFFFFFF );
} if ( client->mMode == kTest_DualTest ) {
hdr->flags |= htonl(RUN_NOW);
}
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.15Bemerkung:
(vorverarbeitet am 2026-06-06)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.