]> sjero.net Git - iperf/blobdiff - src/Settings.cpp
Support for UDP-Lite in iperf
[iperf] / src / Settings.cpp
index 4034158cf261d326965afb4d5496de18700871a4..3cb619faf3bd36ef257ec383b94f0cb8e153beb2 100644 (file)
@@ -101,6 +101,7 @@ const struct option long_options[] =
 {"server",           no_argument, NULL, 's'},
 {"time",       required_argument, NULL, 't'},
 {"udp",              no_argument, NULL, 'u'},
+{"udplite",    required_argument, NULL, 'u'},
 {"version",          no_argument, NULL, 'v'},
 {"window",     required_argument, NULL, 'w'},
 {"reportexclude", required_argument, NULL, 'x'},
@@ -118,7 +119,7 @@ const struct option long_options[] =
 {"listenport", required_argument, NULL, 'L'},
 {"parallel",   required_argument, NULL, 'P'},
 {"remove",           no_argument, NULL, 'R'},
-{"tos",        required_argument, NULL, 'S'},
+{"dscp",       required_argument, NULL, 'S'},
 {"ttl",        required_argument, NULL, 'T'},
 {"single_udp",       no_argument, NULL, 'U'},
 {"ipv6_domian",      no_argument, NULL, 'V'},
@@ -163,7 +164,7 @@ const struct option env_options[] =
 {"IPERF_NODELAY",          no_argument, NULL, 'N'},
 {"IPERF_LISTENPORT", required_argument, NULL, 'L'},
 {"IPERF_PARALLEL",   required_argument, NULL, 'P'},
-{"IPERF_TOS",        required_argument, NULL, 'S'},
+{"IPERF_DSCP",       required_argument, NULL, 'S'},
 {"IPERF_TTL",        required_argument, NULL, 'T'},
 {"IPERF_SINGLE_UDP",       no_argument, NULL, 'U'},
 {"IPERF_IPV6_DOMAIN",      no_argument, NULL, 'V'},
@@ -174,7 +175,7 @@ const struct option env_options[] =
 #define SHORT_OPTIONS()
 
 const char short_options[] =
-      "12b::c:df:hi:j:l:mn:o:p:rst:uvw:x:y:A:B:CDF:IJ:L:M:NP:RS:T:UV:W";
+      "12b::c:df:hi:j:l:mn:o:p:rst:u::vw:x:y:A:B:CDF:IJ:L:M:NP:RS:T:UV:W";
 
 /* -------------------------------------------------------------------
  * defaults
@@ -472,8 +473,16 @@ void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtS
             mExtSettings->mAmount = (int) (atof( optarg ) * 100.0);
             break;
 
-        case 'u': // UDP instead of TCP
-            mExtSettings->mProtocol = kProto_UDP;
+        case 'u': // UDP(-Lite) instead of TCP
+             if (optarg) {
+                mExtSettings->mProtocol = kProto_UDPLITE;
+                // Set partial checksum coverage:
+                // - 0 means entire datagram,
+                // - 1..7 is illegal and will be rounded up to 8;
+                // - 8 and greater mean genuine partial coverage.
+                mExtSettings->cscov = atoi(optarg);
+             } else
+                mExtSettings->mProtocol = kProto_UDP;
 
             setPacketOriented(mExtSettings);
             // if -b has already been processed, UDP rate will
@@ -626,11 +635,20 @@ void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtS
             setRemoveService( mExtSettings );
             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 );
+        case 'S':
+            // Convert into IPv4/v6 6-bit DiffServ codepoint. If string
+            //  - consists of six 0/1 digits, it is seen as binary number;
+            //  - is preceded by `0x', it is interpreted as hex number;
+            //  - is preceded by `0', it is interpreted as octal number;
+            //  - otherwise it is interpreted as decimal number.
+            // The maximum possible 6-bit value is 252 (0xfc).
+            if ( strspn(optarg, "01") == 6 )
+               mExtSettings->mTOS = strtol(optarg, NULL, 2);
+            else
+               mExtSettings->mTOS = strtol(optarg, NULL, 0);
+            if ( mExtSettings->mTOS < 0 || mExtSettings->mTOS  > 0xfc )
+               die("Invalid DiffServ codepoint %s", optarg);
+            mExtSettings->mTOS <<= 2;
             break;
 
         case 'T': // time-to-live for multicast