]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1332] added elapsed time increease in perfdhcp for HA simulations
authorWlodek Wencel <wlodek@isc.org>
Tue, 17 Nov 2020 11:10:49 +0000 (12:10 +0100)
committerWlodzimierz Wencel <wlodek@isc.org>
Fri, 20 Nov 2020 09:00:16 +0000 (09:00 +0000)
src/bin/perfdhcp/command_options.cc
src/bin/perfdhcp/command_options.h
src/bin/perfdhcp/test_control.cc
src/bin/perfdhcp/tests/command_options_unittest.cc

index ca5c580644974ab9df66ab60ba2c91daaec22a43..de95899294a377bb7836d76bf787f413ac7ee769 100644 (file)
@@ -132,6 +132,8 @@ CommandOptions::reset() {
     num_request_.clear();
     exit_wait_time_ = 0;
     period_ = 0;
+    wait_for_elapsed_time_ = -1;
+    increased_elapsed_time_ = -1;
     drop_time_set_ = 0;
     drop_time_.assign(dt, dt + 2);
     max_drop_.clear();
@@ -240,7 +242,7 @@ CommandOptions::initialize(int argc, char** argv, bool print_cmd_line) {
     // they will be tuned and validated elsewhere
     while((opt = getopt_long(argc, argv,
                              "huv46A:r:t:R:b:n:p:d:D:l:P:a:L:N:M:s:iBc1"
-                             "J:T:X:O:o:E:S:I:x:W:w:e:f:F:g:C:",
+                             "J:T:X:O:o:E:S:I:x:W:w:e:f:F:g:C:y:Y:",
                              long_options, NULL)) != -1) {
         stream << " -" << static_cast<char>(opt);
         if (optarg) {
@@ -573,6 +575,16 @@ CommandOptions::initialize(int argc, char** argv, bool print_cmd_line) {
             xid_offset_.push_back(offset_arg);
             break;
 
+        case 'Y':
+            wait_for_elapsed_time_ = nonNegativeInteger("value of time:"
+                                     " -Y<value> must be a non negative integer");
+            break;
+
+        case 'y':
+            increased_elapsed_time_ = positiveInteger("value of time:"
+                                      " -y<value> must be a positive integer");
+            break;
+
         case LONG_OPT_SCENARIO: {
             auto optarg_text = std::string(optarg);
             if (optarg_text == "basic") {
@@ -964,7 +976,10 @@ CommandOptions::validate() {
           "use -I<ip-offset>");
     check((!getMacListFile().empty() && base_.size() > 0),
           "Can't use -b with -M option");
-
+    check((getWaitForElapsedTime() == -1 && getIncreaseElapsedTime() != -1),
+         "Option -y can't be used without -Y");
+    check((getWaitForElapsedTime() != -1 && getIncreaseElapsedTime() == -1),
+         "Option -Y can't be used without -y");
     auto nthreads = std::thread::hardware_concurrency();
     if (nthreads == 1 && isSingleThreaded() == false) {
         std::cout << "WARNING: Currently system can run only 1 thread in parallel." << std::endl
@@ -1272,7 +1287,10 @@ CommandOptions::usage() const {
         "   * 't': when finished, print timers of all successful exchanges\n"
         "   * 'T': when finished, print templates\n"
         "-X<xid-offset>: Transaction ID (aka. xid) offset in the template.\n"
-        "\n"
+        "-Y<time>: time in seconds after which perfdhcp will start sending\n"
+        "    messages with increased elapsed time option.\n"
+        "-y<time>: period of time in seconds in which perfdhcp will be sending\n"
+        "    messages with increased elapsed time option.\n"
         "DHCPv4 only options:\n"
         "-B: Force broadcast handling.\n"
         "\n"
index 6796cb0c082fdfc41d740c9cc52df7df8d02249a..152342627098619d7f7eb51a4b1c22b98428ee6b 100644 (file)
@@ -218,6 +218,18 @@ public:
     /// \return test period before it is aborted.
     int getPeriod() const { return period_; }
 
+    /// \brief Returns time to wait for elapsed time increase.
+    ///
+    /// \return how long perfdhp will wait before start sending
+    /// messages with increased elapsed time.
+    int getWaitForElapsedTime() const { return wait_for_elapsed_time_; }
+
+    /// \brief Returns increased elapsed time.
+    ///
+    /// \return how long perfdhcp will send messages with increased
+    /// elapsed time.
+    int getIncreaseElapsedTime() const { return increased_elapsed_time_; }
+
     /// \brief Returns drop time.
     ///
     /// The method returns maximum time elapsed from
@@ -617,6 +629,14 @@ private:
     /// Test period in seconds.
     int period_;
 
+    // for how long perfdhcp will wait before start senging
+    // messages with increased elapsed time.
+    int wait_for_elapsed_time_;
+
+    // Amount of time after which perfdhcp will send messages with
+    // elapsed time increased.
+    int increased_elapsed_time_;
+
     /// Indicates number of -d<value> parameters specified by user.
     /// If this value goes above 2, command line parsing fails.
     uint8_t drop_time_set_;
index 7e321b7047eb1e9f5c64a344e5b4f0315d5f8ef1..c4e2605a32c21fa1bb158b2c6d75c732e105ce03 100644 (file)
@@ -1171,6 +1171,14 @@ TestControl::sendDiscover4(const bool preload /*= false*/) {
     // Set client identifier
     pkt4->addOption(generateClientId(pkt4->getHWAddr()));
 
+    if (options_.getWaitForElapsedTime() &&
+        stats_mgr_.getTestPeriod().length().total_seconds() >= options_.getWaitForElapsedTime() &&
+        stats_mgr_.getTestPeriod().length().total_seconds() <= options_.getWaitForElapsedTime() +
+                                     options_.getIncreaseElapsedTime()) {
+    // increase field elapsed time heree
+    pkt4->setSecs(static_cast<uint16_t>(10));
+    }
+
     // Add any extra options that user may have specified.
     addExtraOpts(pkt4);
 
@@ -1629,7 +1637,18 @@ TestControl::sendSolicit6(const bool preload /*= false*/) {
     if (!pkt6) {
         isc_throw(Unexpected, "failed to create SOLICIT packet");
     }
-    pkt6->addOption(Option::factory(Option::V6, D6O_ELAPSED_TIME));
+    if (options_.getWaitForElapsedTime() &&
+        stats_mgr_.getTestPeriod().length().total_seconds() >= options_.getWaitForElapsedTime() &&
+        stats_mgr_.getTestPeriod().length().total_seconds() <= options_.getWaitForElapsedTime() +
+                                     options_.getIncreaseElapsedTime()) {
+        boost::shared_ptr<LocalizedOption>
+            opt_elapsed_time(new LocalizedOption(Option::V6, D6O_ELAPSED_TIME,
+                                                 OptionBuffer(2, 10)));
+        pkt6->addOption(opt_elapsed_time);
+    } else {
+        pkt6->addOption(Option::factory(Option::V6, D6O_ELAPSED_TIME));
+    }
+
     if (options_.isRapidCommit()) {
         pkt6->addOption(Option::factory(Option::V6, D6O_RAPID_COMMIT));
     }
index 411ede6e7a156755706938f3b456476630e99b49..056ef2b55942eb044fc563e3fc8970d87eeb7b34 100644 (file)
@@ -239,6 +239,8 @@ TEST_F(CommandOptionsTest, Defaults) {
     EXPECT_FALSE(opt.isRapidCommit());
     EXPECT_FALSE(opt.isUseFirst());
     EXPECT_FALSE(opt.getAddrUnique());
+    EXPECT_EQ(-1, opt.getIncreaseElapsedTime());
+    EXPECT_EQ(-1, opt.getWaitForElapsedTime());
     EXPECT_EQ(0, opt.getTemplateFiles().size());
     EXPECT_EQ(0, opt.getTransactionIdOffset().size());
     EXPECT_EQ(0, opt.getRandomOffset().size());
@@ -859,3 +861,11 @@ TEST_F(CommandOptionsTest, LoadMacsFromFileNegativeCases) {
     EXPECT_THROW(process(opt, "perfdhcp -M foo -b mac=1234 all"),
                  isc::InvalidParameter);
 }
+
+TEST_F(CommandOptionsTest, ElapsedTime) {
+    CommandOptions opt;
+    EXPECT_NO_THROW(process(opt, "perfdhcp -y 3 -Y 10 192.168.0.1"));
+
+    EXPECT_EQ(3, opt.getIncreaseElapsedTime());
+    EXPECT_EQ(10, opt.getWaitForElapsedTime());
+}