]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
perdhcp avalanche: removed ignore_timestamp_reorder and added correcting pkt timestam...
authorMichal Nowikowski <godfryd@isc.org>
Wed, 13 Feb 2019 13:55:23 +0000 (14:55 +0100)
committerMichal Nowikowski <godfryd@isc.org>
Tue, 19 Feb 2019 20:54:31 +0000 (21:54 +0100)
src/bin/perfdhcp/avalanche_scen.cc
src/bin/perfdhcp/avalanche_scen.h
src/bin/perfdhcp/basic_scen.h
src/bin/perfdhcp/stats_mgr.cc
src/bin/perfdhcp/stats_mgr.h
src/bin/perfdhcp/test_control.cc
src/bin/perfdhcp/test_control.h
src/lib/dhcp/pkt.h

index 3c96946305e372388c88ec9774e150eaea430d64..c796c46e7fae31804e1426ae06912bd995cfeac1 100644 (file)
@@ -27,6 +27,7 @@ AvalancheScen::resendPackets(ExchangeType xchg_type) {
     auto end_it = std::get<1>(sent_packets_its);
 
     auto& retrans = retransmissions_[xchg_type];
+    auto& start_times = start_times_[xchg_type];
 
     int still_left_cnt = 0;
     int resent_cnt = 0;
@@ -34,10 +35,15 @@ AvalancheScen::resendPackets(ExchangeType xchg_type) {
         still_left_cnt++;
         dhcp::PktPtr pkt = *it;
         auto trans_id = pkt->getTransid();
+        bool first_resend = false;
+        auto start_time = pkt->getTimestamp();
         int rx_times = 0;
         auto r_it = retrans.find(trans_id);
         if (r_it != retrans.end()) {
             rx_times = (*r_it).second;
+            start_time = (*start_times.find(trans_id)).second;
+        } else {
+            first_resend = true;
         }
 
         int delay = (1 << rx_times); // in seconds
@@ -47,10 +53,14 @@ AvalancheScen::resendPackets(ExchangeType xchg_type) {
         delay *= 1000;  // to miliseconds
         delay += random() % 2000 - 1000;  // adjust by random from -1000..1000 range
         auto now = microsec_clock::universal_time();
-        if (now - pkt->getTimestamp() > milliseconds(delay)) {
+        if (now - start_time > milliseconds(delay)) {
             resent_cnt++;
             total_resent_++;
 
+            boost::posix_time::ptime original_timestamp;
+            if (!first_resend) {
+                original_timestamp = pkt->getTimestamp();
+            }
             if (options.getIpVersion() == 4) {
                 Pkt4Ptr pkt4 = boost::dynamic_pointer_cast<Pkt4>(pkt);
                 IfaceMgr::instance().send(pkt4);
@@ -58,6 +68,11 @@ AvalancheScen::resendPackets(ExchangeType xchg_type) {
                 Pkt6Ptr pkt6 = boost::dynamic_pointer_cast<Pkt6>(pkt);
                 IfaceMgr::instance().send(pkt6);
             }
+            if (first_resend) {
+                start_times[trans_id] = pkt->getTimestamp();
+            } else {
+                pkt->setTimestamp(original_timestamp);
+            }
 
             rx_times++;
             retrans[trans_id] = rx_times;
index 66cf04028673b5d94faf5f726e6aabadc25d9ad7..037ee7daede09b08b1480ba884a825c3c0590339 100644 (file)
@@ -18,7 +18,7 @@ namespace perfdhcp {
 
 class AvalancheScen : public boost::noncopyable {
 public:
-    AvalancheScen(): tc_(true), total_resent_(0) {};
+    AvalancheScen(): total_resent_(0) {};
 
     /// brief\ Run performance test.
     ///
@@ -36,6 +36,7 @@ private:
     TestControl tc_;
 
     std::unordered_map<ExchangeType, std::unordered_map<uint32_t, int>> retransmissions_;
+    std::unordered_map<ExchangeType, std::unordered_map<uint32_t, boost::posix_time::ptime>> start_times_;
     int total_resent_;
 
     int resendPackets(ExchangeType xchg_type);
index 7a5d115d4e8a44a9bb8945a7fd00555cc6ea3a39..336be7eecac9ab2be9b18603173f07c9beb5dbbb 100644 (file)
@@ -18,7 +18,7 @@ namespace perfdhcp {
 
 class BasicScen : public boost::noncopyable {
 public:
-    BasicScen() : tc_(false) {};
+    BasicScen() {};
 
     /// \brief Check if test exit conditions fulfilled.
     ///
index bc8fe641a11322c1ba085ac2b4944e632d4511c6..bd741e31ed5e4972e5d97fbd8feeae5f538ea59a 100644 (file)
@@ -37,8 +37,7 @@ std::ostream& operator<<(std::ostream& os, ExchangeType xchg_type)
 ExchangeStats::ExchangeStats(const ExchangeType xchg_type,
                              const double drop_time,
                              const bool archive_enabled,
-                             const boost::posix_time::ptime boot_time,
-                             bool ignore_timestamp_reorder)
+                             const boost::posix_time::ptime boot_time)
     : xchg_type_(xchg_type),
       sent_packets_(),
       rcvd_packets_(),
@@ -56,8 +55,7 @@ ExchangeStats::ExchangeStats(const ExchangeType xchg_type,
       ordered_lookups_(0),
       sent_packets_num_(0),
       rcvd_packets_num_(0),
-      boot_time_(boot_time),
-      ignore_timestamp_reorder_(ignore_timestamp_reorder)
+      boot_time_(boot_time)
 {
     next_sent_ = sent_packets_.begin();
 }
@@ -89,7 +87,7 @@ ExchangeStats::updateDelays(const dhcp::PktPtr& sent_packet,
     double delta =
         static_cast<double>(period.length().total_nanoseconds()) / 1e9;
 
-    if (!ignore_timestamp_reorder_ && delta < 0) {
+    if (delta < 0) {
         isc_throw(Unexpected, "Sent packet's timestamp must not be "
                   "greater than received packet's timestamp in "
                   << xchg_type_ << ".\nTime difference: "
@@ -315,10 +313,9 @@ ExchangeStats::printTimestamps() {
     }
 }
 
-StatsMgr::StatsMgr(bool ignore_timestamp_reorder) :
+StatsMgr::StatsMgr() :
     exchanges_(),
-    boot_time_(boost::posix_time::microsec_clock::universal_time()),
-    ignore_timestamp_reorder_(ignore_timestamp_reorder)
+    boot_time_(boost::posix_time::microsec_clock::universal_time())
 {
     CommandOptions& options = CommandOptions::instance();
 
index adc028177aa01b48433b8676483ce74305a14b1f..b05a75b800304e0d90798db7c937770a0e93018e 100644 (file)
@@ -260,14 +260,10 @@ public:
     /// \param archive_enabled if true packets archive mode is enabled.
     /// In this mode all packets are stored throughout the test execution.
     /// \param boot_time Holds the timestamp when perfdhcp has been started.
-    /// \param ignore_timestamp_reorder if true then while matching
-    /// response packets to request ones negative time difference is ignored
-    /// otherwise exception is raised.
     ExchangeStats(const ExchangeType xchg_type,
                   const double drop_time,
                   const bool archive_enabled,
-                  const boost::posix_time::ptime boot_time,
-                  bool ignore_timestamp_reorder);
+                  const boost::posix_time::ptime boot_time);
 
     /// \brief Add new packet to list of sent packets.
     ///
@@ -614,11 +610,6 @@ private:
     uint64_t sent_packets_num_;    ///< Total number of sent packets.
     uint64_t rcvd_packets_num_;    ///< Total number of received packets.
     boost::posix_time::ptime boot_time_; ///< Time when test is started.
-
-    /// If true then while matching
-    /// response packets to request ones negative time difference is ignored
-    /// otherwise exception is raised.
-    bool ignore_timestamp_reorder_;
 };
 
 /// Pointer to ExchangeStats.
@@ -658,10 +649,7 @@ public:
     /// the test. If this is not selected archiving should be disabled
     /// for performance reasons and to avoid waste of memory for storing
     /// large list of archived packets.
-    /// \param ignore_timestamp_reorder if true then while matching
-    /// response packets to request ones negative time difference is ignored
-    /// otherwise exception is raised.
-    StatsMgr(bool ignore_timestamp_reorder);
+    StatsMgr();
 
     /// \brief Specify new exchange type.
     ///
@@ -682,8 +670,7 @@ public:
             ExchangeStatsPtr(new ExchangeStats(xchg_type,
                                                drop_time,
                                                archive_enabled_,
-                                               boot_time_,
-                                               ignore_timestamp_reorder_));
+                                               boot_time_));
     }
 
     /// \brief Check if the exchange type has been specified.
@@ -1122,11 +1109,6 @@ private:
     bool archive_enabled_;
 
     boost::posix_time::ptime boot_time_; ///< Time when test is started.
-
-    /// If true then while matching
-    /// response packets to request ones negative time difference is ignored
-    /// otherwise exception is raised.
-    bool ignore_timestamp_reorder_;
 };
 
 /// Pointer to Statistics Manager;
index a37394c78ca7c38e4b552ad12061c38f4a80f3a4..9a5cad831065edc7f7316a0c7b045f6fb7494bab 100644 (file)
@@ -966,9 +966,8 @@ TestControl::reset() {
     interrupted_ = false;
 }
 
-TestControl::TestControl(bool ignore_timestamp_reorder) :
-    number_generator_(0, CommandOptions::instance().getMacsFromFile().size()),
-    stats_mgr_(ignore_timestamp_reorder)
+TestControl::TestControl() :
+    number_generator_(0, CommandOptions::instance().getMacsFromFile().size())
 {
     // Reset singleton state before test starts.
     reset();
index bb496e8c6cbd64c4eafb01fef145707026591cec..4ece6157faab837a9775dfb458d1c6805800db9c 100644 (file)
@@ -124,11 +124,7 @@ public:
 class TestControl : public boost::noncopyable {
 public:
     /// \brief Default constructor.
-    ///
-    /// \param ignore_timestamp_reorder if true then while matching
-    /// response packets to request ones negative time difference is ignored
-    /// otherwise exception is raised.
-    TestControl(bool ignore_timestamp_reorder);
+    TestControl();
 
     /// Packet template buffer.
     typedef std::vector<uint8_t> TemplateBuffer;
index cf90eb40732319efa55c16570e118d927b7b8e41..959eaf9a81ef16ca2cb1f3b320d563afcfa52998 100644 (file)
@@ -396,6 +396,14 @@ public:
         return timestamp_;
     }
 
+    /// @brief Set packet timestamp.
+    ///
+    /// Sets packet timestamp to arbitrary value.
+    /// It is used by perfdhcp tool and should be used elsewhere.
+    void setTimestamp(boost::posix_time::ptime& timestamp) {
+        timestamp_ = timestamp;
+    }
+
     /// @brief Copies content of input buffer to output buffer.
     ///
     /// This is mostly a diagnostic function. It is being used for sending