]> sjero.net Git - iperf/blobdiff - src/Settings.cpp
DCCP support for iperf
[iperf] / src / Settings.cpp
index 2b71693c70c132b6fd49554908107a00ab069d4c..4cde826405af41db1b7fb6ef7021d1f85adc7044 100644 (file)
@@ -84,9 +84,10 @@ void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtS
 const struct option long_options[] =
 {
 {"singleclient",     no_argument, NULL, '1'},
+{"dualtest",         no_argument, NULL, '2'},
 {"bandwidth",  required_argument, NULL, 'b'},
 {"client",     required_argument, NULL, 'c'},
-{"dualtest",         no_argument, NULL, 'd'},
+{"dccp",            no_argument, NULL, 'd'},
 {"format",     required_argument, NULL, 'f'},
 {"help",             no_argument, NULL, 'h'},
 {"interval",   required_argument, NULL, 'i'},
@@ -128,9 +129,10 @@ const struct option long_options[] =
 const struct option env_options[] =
 {
 {"IPERF_SINGLECLIENT",     no_argument, NULL, '1'},
+{"IPERF_DUALTEST",         no_argument, NULL, '2'},
 {"IPERF_BANDWIDTH",  required_argument, NULL, 'b'},
 {"IPERF_CLIENT",     required_argument, NULL, 'c'},
-{"IPERF_DUALTEST",         no_argument, NULL, 'd'},
+{"IPERF_DCCP",             no_argument, NULL, 'd'},
 {"IPERF_FORMAT",     required_argument, NULL, 'f'},
 // skip help
 {"IPERF_INTERVAL",   required_argument, NULL, 'i'},
@@ -167,19 +169,22 @@ const struct option env_options[] =
 
 #define SHORT_OPTIONS()
 
-const char short_options[] = "1b:c:df:hi:l:mn:o:p:rst:uvw:x:y:B:CDF:IL:M:NP:RS:T:UVW";
+const char short_options[] =
+      "12b::c:df:hi:l:mn:o:p:rst:uvw:x:y:B:CDF:IL:M:NP:RS:T:UVW";
 
 /* -------------------------------------------------------------------
  * defaults
  * ------------------------------------------------------------------- */
 #define DEFAULTS()
 
-const long kDefault_UDPRate = 1024 * 1024; // -u  if set, 1 Mbit/sec
-const int  kDefault_UDPBufLen = 1470;      // -u  if set, read/write 1470 bytes
+const long kDefault_DgramRate = 1024 * 1024; // -u  if set, 1 Mbit/sec
+const int  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 ****
+const int  kDefault_DCCPBufLen = 1420;       // -d
+// old DCCPv4: MPS=1424; new DCCPv4: MPS=1440; new DCCPv6: MPS=1420 (above)
 
 /* -------------------------------------------------------------------
  * Initialize all settings to defaults.
@@ -190,42 +195,43 @@ void Settings_Initialize( thread_Settings *main ) {
     // this memset. Only need to set non-zero values
     // below.
     memset( main, 0, sizeof(thread_Settings) );
-    main->mSock = INVALID_SOCKET;
-    main->mReportMode = kReport_Default;
+    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->mDgramRate  = 0;             // -b,  ie. TCP mode
+    main->mProtocol     = kProto_TCP;   // -u / -d
+    //main->mHost       = NULL;          // -c,  none, required for client
+    main->mMode         = kTest_Normal;  // -2,  mMode == kTest_DualTest
     main->mFormat       = 'a';           // -f,  adaptive bits
     // skip help                         // -h,
     //main->mBufLenSet  = false;         // -l,        
     main->mBufLen       = 8 * 1024;      // -l,  8 Kbyte
-    //main->mInterval     = 0;           // -i,  ie. no periodic bw reports
+    //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
+    // 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
+    // mDgramRate                        // -u,  N/A, see kDefault_DgramRate
     // skip version                      // -v,
-    //main->mTCPWin       = 0;           // -w,  ie. don't set window
+    //main->mWinSize       = 0;          // -w,  ie. don't set window
 
     // more esoteric options
-    //main->mLocalhost    = NULL;        // -B,  none
+    //main->mLocalhost  = NULL;          // -B,  bind address - 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->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->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->mThreads    = 0;             // -P,
     //main->mRemoveService = false;      // -R,
-    //main->mTOS          = 0;           // -S,  ie. don't set type of service
+    //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.
@@ -314,25 +320,34 @@ void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtS
         case '1': // Single Client
             setSingleClient( mExtSettings );
             break;
-        case 'b': // UDP bandwidth
-            if ( !isUDP( mExtSettings ) ) {
-                fprintf( stderr, warn_implied_udp, option );
-            }
 
+        case '2': // Dual-test Mode
             if ( mExtSettings->mThreadMode != kMode_Client ) {
                 fprintf( stderr, warn_invalid_server_option, option );
                 break;
             }
+            if ( isCompat( mExtSettings ) ) {
+                fprintf( stderr, warn_invalid_compatibility_option, option );
+            }
+#ifdef HAVE_THREAD
+            mExtSettings->mMode = kTest_DualTest;
+#else
+            fprintf( stderr, warn_invalid_single_threaded, option );
+            mExtSettings->mMode = kTest_TradeOff;
+#endif
+            break;
 
-            Settings_GetLowerCaseArg(optarg,outarg);
-            mExtSettings->mUDPRate = byte_atoi(outarg);
-            setUDP( mExtSettings );
+        case 'b':
+            // This sets packet-oriented mode. The optional
+            // argument sets datagram bandwidth (as before).
+            // If not given, a default bandwith is used.
+            setPacketOriented(mExtSettings);
 
-            // if -l has already been processed, mBufLenSet is true
-            // so don't overwrite that value.
-            if ( !isBuflenSet( mExtSettings ) ) {
-                mExtSettings->mBufLen = kDefault_UDPBufLen;
-            }
+            if (optarg) {
+                Settings_GetLowerCaseArg(optarg, outarg);
+                mExtSettings->mDgramRate = byte_atoi(outarg);
+             } else
+                mExtSettings->mDgramRate = kDefault_DgramRate;
             break;
 
         case 'c': // client mode w/ server host to connect to
@@ -352,20 +367,14 @@ void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtS
             }
             break;
 
-        case 'd': // Dual-test Mode
-            if ( mExtSettings->mThreadMode != kMode_Client ) {
-                fprintf( stderr, warn_invalid_server_option, option );
-                break;
-            }
-            if ( isCompat( mExtSettings ) ) {
-                fprintf( stderr, warn_invalid_compatibility_option, option );
-            }
-#ifdef HAVE_THREAD
-            mExtSettings->mMode = kTest_DualTest;
-#else
-            fprintf( stderr, warn_invalid_single_threaded, option );
-            mExtSettings->mMode = kTest_TradeOff;
-#endif
+        case 'd': // DCCP as transport
+            mExtSettings->mProtocol  = kProto_DCCP;
+
+            // if -l has already been processed, mBufLenSet is true
+            // so don't overwrite that value.
+            if ( !isBuflenSet( mExtSettings ) )
+                mExtSettings->mBufLen = kDefault_DCCPBufLen;
+
             break;
 
         case 'f': // format to print in
@@ -373,9 +382,7 @@ void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtS
             break;
 
         case 'h': // print help and exit
-            fprintf( stderr, usage_long );
-            exit(1);
-            break;
+           die(usage_long);
 
         case 'i': // specify interval between periodic bw reports
             mExtSettings->mInterval = atof( optarg );
@@ -389,19 +396,20 @@ void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtS
             Settings_GetUpperCaseArg(optarg,outarg);
             mExtSettings->mBufLen = byte_atoi( outarg );
             setBuflenSet( mExtSettings );
-            if ( !isUDP( mExtSettings ) ) {
+
+            if ( !isPacketOriented( mExtSettings ) ) {
                  if ( mExtSettings->mBufLen < (int) sizeof( client_hdr ) &&
                       !isCompat( mExtSettings ) ) {
                     setCompat( mExtSettings );
                     fprintf( stderr, warn_implied_compatibility, option );
                  }
             } else {
-                if ( mExtSettings->mBufLen < (int) sizeof( UDP_datagram ) ) {
-                    mExtSettings->mBufLen = sizeof( UDP_datagram );
+                if ( mExtSettings->mBufLen < (int) sizeof( dgram_record ) ) {
+                    mExtSettings->mBufLen = sizeof( dgram_record );
                     fprintf( stderr, warn_buffer_too_small, mExtSettings->mBufLen );
                 }
                 if ( !isCompat( mExtSettings ) &&
-                            mExtSettings->mBufLen < (int) ( sizeof( UDP_datagram )
+                            mExtSettings->mBufLen < (int) ( sizeof( dgram_record )
                             + sizeof( client_hdr ) ) ) {
                     setCompat( mExtSettings );
                     fprintf( stderr, warn_implied_compatibility, option );
@@ -459,18 +467,19 @@ void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtS
             break;
 
         case 'u': // UDP instead of TCP
+            mExtSettings->mProtocol = kProto_UDP;
+
+            setPacketOriented(mExtSettings);
             // 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 ( mExtSettings->mDgramRate == 0 )
+                mExtSettings->mDgramRate = kDefault_DgramRate;
 
             // if -l has already been processed, mBufLenSet is true
             // so don't overwrite that value.
             if ( !isBuflenSet( mExtSettings ) ) {
                 mExtSettings->mBufLen = kDefault_UDPBufLen;
-            } else if ( mExtSettings->mBufLen < (int) ( sizeof( UDP_datagram ) 
+            } else if ( mExtSettings->mBufLen < (int) ( sizeof( dgram_record )
                         + sizeof( client_hdr ) ) &&
                         !isCompat( mExtSettings ) ) {
                 setCompat( mExtSettings );
@@ -479,17 +488,11 @@ void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtS
             break;
 
         case 'v': // print version and exit
-            fprintf( stderr, version );
-            exit(1);
-            break;
+            die(version);
 
-        case 'w': // TCP window size (socket buffer size)
+        case 'w': // TCP window size or socket send-buffer size (UDP/DCCP)
             Settings_GetUpperCaseArg(optarg,outarg);
-            mExtSettings->mTCPWin = byte_atoi(outarg);
-
-            if ( mExtSettings->mTCPWin < 2048 ) {
-                fprintf( stderr, warn_window_small, mExtSettings->mTCPWin );
-            }
+            mExtSettings->mWinSize = byte_atoi(outarg);
             break;
 
         case 'x': // Limit Reports
@@ -740,17 +743,17 @@ void Settings_GenerateClientSettings( thread_Settings *server,
         *client = new thread_Settings;
         memcpy(*client, server, sizeof( thread_Settings ));
         setCompat( (*client) );
-        (*client)->mTID = thread_zeroid();
+        (*client)->mTID        = thread_zeroid();
         (*client)->mPort       = (unsigned short) 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);
+            if ( isPacketOriented( server ) ) {
+                (*client)->mDgramRate = ntohl(hdr->mWinBand);
             } else {
-                (*client)->mTCPWin = ntohl(hdr->mWinBand);
+                (*client)->mWinSize = ntohl(hdr->mWinBand);
             }
         }
         (*client)->mAmount     = ntohl(hdr->mAmount);
@@ -803,10 +806,10 @@ void Settings_GenerateClientHdr( thread_Settings *client, client_hdr *hdr ) {
     } else {
         hdr->bufferlen = 0;
     }
-    if ( isUDP( client ) ) {
-        hdr->mWinBand  = htonl(client->mUDPRate);
+    if ( isPacketOriented( client ) ) {
+        hdr->mWinBand  = htonl(client->mDgramRate);
     } else {
-        hdr->mWinBand  = htonl(client->mTCPWin);
+        hdr->mWinBand  = htonl(client->mWinSize);
     }
     if ( client->mListenPort != 0 ) {
         hdr->mPort  = htonl(client->mListenPort);