Browse Source

[3181] Added support for the new perfdhcp command line option: release-rate

Marcin Siodelski 11 years ago
parent
commit
3ed35605cc

+ 37 - 14
tests/tools/perfdhcp/command_options.cc

@@ -114,6 +114,7 @@ CommandOptions::reset() {
     lease_type_.set(LeaseType::ADDRESS);
     rate_ = 0;
     renew_rate_ = 0;
+    release_rate_ = 0;
     report_delay_ = 0;
     clients_num_ = 0;
     mac_template_.assign(mac, mac + 6);
@@ -211,7 +212,7 @@ CommandOptions::initialize(int argc, char** argv, bool print_cmd_line) {
     // In this section we collect argument values from command line
     // they will be tuned and validated elsewhere
     while((opt = getopt(argc, argv, "hv46r:t:R:b:n:p:d:D:l:P:a:L:"
-                        "s:iBc1T:X:O:E:S:I:x:w:e:f:")) != -1) {
+                        "s:iBc1T:X:O:E:S:I:x:w:e:f:F:")) != -1) {
         stream << " -" << static_cast<char>(opt);
         if (optarg) {
             stream << " " << optarg;
@@ -307,6 +308,12 @@ CommandOptions::initialize(int argc, char** argv, bool print_cmd_line) {
                                           " must be a positive integer");
             break;
 
+        case 'F':
+            release_rate_ = positiveInteger("value of the release rate:"
+                                            " -F<release-rate> must be a"
+                                            " positive integer");
+            break;
+
         case 'h':
             usage();
             return (true);
@@ -690,6 +697,8 @@ CommandOptions::validate() const {
           "-6 (IPv6) must be set to use -c");
     check((getIpVersion() != 6) && (getRenewRate() !=0),
           "-f<renew-rate> may be used with -6 (IPv6) only");
+    check((getIpVersion() != 6) && (getReleaseRate() != 0),
+          "-F<release-rate> may be used with -6 (IPv6) only");
     check((getExchangeMode() == DO_SA) && (getNumRequests().size() > 1),
           "second -n<num-request> is not compatible with -i");
     check((getIpVersion() == 4) && !getLeaseType().is(LeaseType::ADDRESS),
@@ -719,6 +728,8 @@ CommandOptions::validate() const {
           "-I<ip-offset> is not compatible with -i");
     check((getExchangeMode() == DO_SA) && (getRenewRate() != 0),
           "-f<renew-rate> is not compatible with -i");
+    check((getExchangeMode() == DO_SA) && (getReleaseRate() != 0),
+          "-F<release-rate> is not compatible with -i");
     check((getExchangeMode() != DO_SA) && (isRapidCommit() != 0),
           "-i must be set to use -c");
     check((getRate() == 0) && (getReportDelay() != 0),
@@ -730,12 +741,16 @@ CommandOptions::validate() const {
     check((getRate() == 0) &&
           ((getMaxDrop().size() > 0) || getMaxDropPercentage().size() > 0),
           "-r<rate> must be set to use -D<max-drop>");
-    check((getRate() != 0) && (getRenewRate() > getRate()),
-          "Renew rate specified as -f<renew-rate> must not be greater than"
-          " the rate specified as -r<rate>");
+    check((getRate() != 0) && (getRenewRate() + getReleaseRate() > getRate()),
+          "The sum of Renew rate (-f<renew-rate>) and Release rate"
+          " (-F<release-rate>) must not be greater than the rate specified"
+          " as -r<rate>");
     check((getRate() == 0) && (getRenewRate() != 0),
           "Renew rate specified as -f<renew-rate> must not be specified"
           " when -r<rate> parameter is not specified");
+    check((getRate() == 0) && (getReleaseRate() != 0),
+          "Release rate specified as -F<release-rate> must not be specified"
+          " when -r<rate> parameter is not specified");
     check((getTemplateFiles().size() < getTransactionIdOffset().size()),
           "-T<template-file> must be set to use -X<xid-offset>");
     check((getTemplateFiles().size() < getRandomOffset().size()),
@@ -816,6 +831,9 @@ CommandOptions::printCommandLine() const {
     if (getRenewRate() != 0) {
         std::cout << "renew-rate[1/s]=" << getRenewRate() << std::endl;
     }
+    if (getReleaseRate() != 0) {
+        std::cout << "release-rate[1/s]=" << getReleaseRate() << std::endl;
+    }
     if (report_delay_ != 0) {
         std::cout << "report[s]=" << report_delay_ << std::endl;
     }
@@ -899,13 +917,14 @@ void
 CommandOptions::usage() const {
     std::cout <<
         "perfdhcp [-hv] [-4|-6] [-e<lease-type>] [-r<rate>] [-f<renew-rate>]\n"
-        "         [-t<report>] [-R<range>] [-b<base>] [-n<num-request>]\n"
-        "         [-p<test-period>] [-d<drop-time>] [-D<max-drop>]\n"
-        "         [-l<local-addr|interface>] [-P<preload>] [-a<aggressivity>]\n"
-        "         [-L<local-port>] [-s<seed>] [-i] [-B] [-c] [-1]\n"
-        "         [-T<template-file>] [-X<xid-offset>] [-O<random-offset]\n"
-        "         [-E<time-offset>] [-S<srvid-offset>] [-I<ip-offset>]\n"
-        "         [-x<diagnostic-selector>] [-w<wrapped>] [server]\n"
+        "         [-F<release-rate>] [-t<report>] [-R<range>] [-b<base>]\n"
+        "         [-n<num-request>] [-p<test-period>] [-d<drop-time>]\n"
+        "         [-D<max-drop>] [-l<local-addr|interface>] [-P<preload>]\n"
+        "         [-a<aggressivity>] [-L<local-port>] [-s<seed>] [-i] [-B]\n"
+        "         [-c] [-1] [-T<template-file>] [-X<xid-offset>]\n"
+        "         [-O<random-offset] [-E<time-offset>] [-S<srvid-offset>]\n"
+        "         [-I<ip-offset>] [-x<diagnostic-selector>] [-w<wrapped>]\n"
+        "         [server]\n"
         "\n"
         "The [server] argument is the name/address of the DHCP server to\n"
         "contact.  For DHCPv4 operation, exchanges are initiated by\n"
@@ -949,9 +968,13 @@ CommandOptions::usage() const {
         "    elapsed-time option in the (second/request) template.\n"
         "    The value 0 disables it.\n"
         "-f<renew-rate>: A rate at which IPv6 Renew requests are sent to\n"
-        "    a server. This value must not be equal or lower than the rate\n"
-        "    specified as -r<rate>. If -r<rate> is not specified, this\n"
-        "    parameter must not be specified too.\n"
+        "    a server. The sum of this value and release-rate must be equal\n"
+        "    or lower than the rate specified as -r<rate>. If -r<rate> is\n"
+        "    not specified, this parameter must not be specified too.\n"
+        "-F<release-rate>: A rate at which IPv6 Release requests are sent to\n"
+        "    a server. The sum of this value and renew-rate must be equal or\n"
+        "    lower than the rate specified as -r<rate>. If -r<rate> is not\n"
+        "    specified, this parameter must not be specified too.\n"
         "-h: Print this help.\n"
         "-i: Do only the initial part of an exchange: DO or SA, depending on\n"
         "    whether -6 is given.\n"

+ 8 - 2
tests/tools/perfdhcp/command_options.h

@@ -1,4 +1,3 @@
-
 // Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
@@ -156,11 +155,16 @@ public:
     /// \return exchange rate per second.
     int getRate() const { return rate_; }
 
-    /// \brief Returns a rate at which IPv6 Renew messages are sent.
+    /// \brief Returns a rate at which DHCPv6 Renew messages are sent.
     ///
     /// \return A rate at which IPv6 Renew messages are sent.
     int getRenewRate() const { return (renew_rate_); }
 
+    /// \brief Returns a rate at which DHCPv6 Release messages are sent.
+    ///
+    /// \return A rate at which DHCPv6 Release messages are sent.
+    int getReleaseRate() const { return (release_rate_); }
+
     /// \brief Returns delay between two performance reports.
     ///
     /// \return delay between two consecutive performance reports.
@@ -469,6 +473,8 @@ private:
     int rate_;
     /// A rate at which DHCPv6 Renew messages are sent.
     int renew_rate_;
+    /// A rate at which DHCPv6 Release messages are sent.
+    int release_rate_;
     /// Delay between generation of two consecutive
     /// performance reports
     int report_delay_;

+ 59 - 1
tests/tools/perfdhcp/tests/command_options_unittest.cc

@@ -168,6 +168,8 @@ protected:
         EXPECT_EQ(CommandOptions::DORA_SARR, opt.getExchangeMode());
         EXPECT_TRUE(opt.getLeaseType().is(CommandOptions::LeaseType::ADDRESS));
         EXPECT_EQ(0, opt.getRate());
+        EXPECT_EQ(0, opt.getRenewRate());
+        EXPECT_EQ(0, opt.getReleaseRate());
         EXPECT_EQ(0, opt.getReportDelay());
         EXPECT_EQ(0, opt.getClientsNum());
 
@@ -341,10 +343,13 @@ TEST_F(CommandOptionsTest, RenewRate) {
     EXPECT_NO_THROW(process("perfdhcp -6 -r 10 -f 10 -l ethx all"));
     EXPECT_EQ(10, opt.getRenewRate());
     // Check that the release rate can be set to different value than
-    // rate specified as -r<rate>. Also, swap -f na d-r to make sure
+    // rate specified as -r<rate>. Also, swap -f and -r to make sure
     // that order doesn't matter.
     EXPECT_NO_THROW(process("perfdhcp -6 -f 5 -r 10 -l ethx all"));
     EXPECT_EQ(5, opt.getRenewRate());
+    // The renew rate should not be greater than the rate.
+    EXPECT_THROW(process("perfdhcp -6 -r 10 -f 11 -l ethx all"),
+                 isc::InvalidParameter);
     // The renew-rate of 0 is invalid.
     EXPECT_THROW(process("perfdhcp -6 -r 10 -f 0 - l ethx all"),
                  isc::InvalidParameter);
@@ -365,6 +370,59 @@ TEST_F(CommandOptionsTest, RenewRate) {
                  isc::InvalidParameter);
 }
 
+TEST_F(CommandOptionsTest, ReleaseRate) {
+    CommandOptions& opt = CommandOptions::instance();
+    // If -F is specified together with -r the command line should
+    // be accepted and the release rate should be set.
+    EXPECT_NO_THROW(process("perfdhcp -6 -r 10 -F 10 -l ethx all"));
+    EXPECT_EQ(10, opt.getReleaseRate());
+    // Check that the release rate can be set to different value than
+    // rate specified as -r<rate>. Also, swap -F and -r to make sure
+    // that order doesn't matter.
+    EXPECT_NO_THROW(process("perfdhcp -6 -F 5 -r 10 -l ethx all"));
+    EXPECT_EQ(5, opt.getReleaseRate());
+    // The release rate should not be greater than the rate.
+    EXPECT_THROW(process("perfdhcp -6 -r 10 -F 11 -l ethx all"),
+                 isc::InvalidParameter);
+    // The release-rate of 0 is invalid.
+    EXPECT_THROW(process("perfdhcp -6 -r 10 -F 0 -l ethx all"),
+                 isc::InvalidParameter);
+    // If -r<rate> is not specified the -F<release-rate> should not
+    // be accepted.
+    EXPECT_THROW(process("perfdhcp -6 -F 10 -l ethx all"),
+                 isc::InvalidParameter);
+    // Currently the -F<release-rate> can be specified for IPv6 mode
+    // only.
+    EXPECT_THROW(process("perfdhcp -4 -r 10 -F 10 -l ethx all"),
+                 isc::InvalidParameter);
+    // Release rate should be specified.
+    EXPECT_THROW(process("perfdhcp -6 -r 10 -F -l ethx all"),
+                 isc::InvalidParameter);
+
+    // -F and -i are mutually exclusive
+    EXPECT_THROW(process("perfdhcp -6 -r 10 -F 10 -l ethx -i all"),
+                 isc::InvalidParameter);
+}
+
+TEST_F(CommandOptionsTest, ReleaseRenew) {
+    CommandOptions& opt = CommandOptions::instance();
+    // It should be possible to specify the -F, -f and -r options.
+    EXPECT_NO_THROW(process("perfdhcp -6 -r 10 -F 3 -f 5 -l ethx all"));
+    EXPECT_EQ(10, opt.getRate());
+    EXPECT_EQ(3, opt.getReleaseRate());
+    EXPECT_EQ(5, opt.getRenewRate());
+    // It should be possible to specify the -F and -f with the values which
+    // sum is equal to the rate specified as -r<rate>.
+    EXPECT_NO_THROW(process("perfdhcp -6 -r 8 -F 3 -f 5 -l ethx all"));
+    EXPECT_EQ(8, opt.getRate());
+    EXPECT_EQ(3, opt.getReleaseRate());
+    EXPECT_EQ(5, opt.getRenewRate());
+    // Check that the sum of the release and renew rate is not greater
+    // than the rate specified as -r<rate>.
+    EXPECT_THROW(process("perfdhcp -6 -F 6 -f 5 -r 10 -l ethx all"),
+                 isc::InvalidParameter);
+}
+
 TEST_F(CommandOptionsTest, ReportDelay) {
     CommandOptions& opt = CommandOptions::instance();
     EXPECT_NO_THROW(process("perfdhcp -r 100 -t 17 -l ethx all"));