Browse Source

[1960] Code cleanup.

Marcin Siodelski 12 years ago
parent
commit
9967f37261

+ 79 - 21
tests/tools/perfdhcp/stats_mgr.h

@@ -258,22 +258,26 @@ public:
         /// \param xchg_type exchange type
         /// \param archive_enabled if true packets archive mode is enabled.
         /// In this mode all packets are stored throughout the test execution.
-        ExchangeStats(const ExchangeType xchg_type, const bool archive_enabled)
+        ExchangeStats(const ExchangeType xchg_type,
+                      const double drop_time,
+                      const bool archive_enabled)
             : xchg_type_(xchg_type),
-            sent_packets_(),
-            rcvd_packets_(),
-            archived_packets_(),
-            archive_enabled_(archive_enabled),
-            min_delay_(std::numeric_limits<double>::max()),
-            max_delay_(0.),
-            sum_delay_(0.),
-            sum_delay_squared_(0.),
-            orphans_(0),
-            unordered_lookup_size_sum_(0),
-            unordered_lookups_(0),
-            ordered_lookups_(0),
-            sent_packets_num_(0),
-            rcvd_packets_num_(0)
+              sent_packets_(),
+              rcvd_packets_(),
+              archived_packets_(),
+              archive_enabled_(archive_enabled),
+              drop_time_(drop_time),
+              min_delay_(std::numeric_limits<double>::max()),
+              max_delay_(0.),
+              sum_delay_(0.),
+              sum_delay_squared_(0.),
+              orphans_(0),
+              collected_(0),
+              unordered_lookup_size_sum_(0),
+              unordered_lookups_(0),
+              ordered_lookups_(0),
+              sent_packets_num_(0),
+              rcvd_packets_num_(0)
         {
             next_sent_ = sent_packets_.begin();
         }
@@ -375,6 +379,8 @@ public:
         /// not found
         boost::shared_ptr<T>
         matchPackets(const boost::shared_ptr<T>& rcvd_packet) {
+            using namespace boost::posix_time;
+
             if (!rcvd_packet) {
                 isc_throw(BadValue, "Received packet is null");
             }
@@ -437,6 +443,20 @@ public:
                             sent_packets_.template project<0>(it);
                         break;
                     }
+                    ptime now = microsec_clock::universal_time();
+                    ptime packet_time = (*it)->getTimestamp();
+                    time_period packet_period(packet_time, now);
+                    if (!packet_period.is_null()) {
+                        double period_fractional =
+                            packet_period.length().total_seconds() +
+                            (static_cast<double>(packet_period.length().fractional_seconds())
+                             / packet_period.length().ticks_per_second());
+                        if (drop_time_ > 0 &&
+                            (period_fractional > drop_time_)) {
+                            eraseSent(sent_packets_.template project<0>(it));
+                            ++collected_;
+                        }
+                    }
                 }
             }
 
@@ -515,6 +535,17 @@ public:
         /// \return number of orphant received packets.
         uint64_t getOrphans() const { return(orphans_); }
 
+        /// \brief Return number of garbage collected packets.
+        ///
+        /// Method returns number of garbage collected timed out
+        /// packets. Packet is assumed timed out when duration
+        /// between sending it to server and receiving server's
+        /// response is greater than value specified with -d<value>
+        /// command line argument.
+        ///
+        /// \return number of garbage collected packets.
+        uint64_t getCollectedNum() const { return(collected_); }
+
         /// \brief Return average unordered lookup set size.
         ///
         /// Method returns average unordered lookup set size.
@@ -608,9 +639,10 @@ public:
                      << "avg delay: " << getAvgDelay() * 1e3 << " ms" << endl
                      << "max delay: " << getMaxDelay() * 1e3 << " ms" << endl
                      << "std deviation: " << getStdDevDelay() * 1e3 << " ms"
-                     << endl;
+                     << endl
+                     << "collected packets: " << getCollectedNum() << endl;
             } catch (const Exception& e) {
-                cout << "Unavailable! No packets received." << endl;
+                cout << "Delay summary unavailable! No packets received." << endl;
             }
         }
 
@@ -738,6 +770,10 @@ public:
         /// to keep all packets archived throughout the test.
         bool archive_enabled_;
 
+        /// Maxmimum time elapsed between sending and receiving packet
+        /// before packet is assumed dropped.
+        double drop_time_;
+
         double min_delay_;             ///< Minimum delay between sent
                                        ///< and received packets.
         double max_delay_;             ///< Maximum delay between sent
@@ -749,6 +785,8 @@ public:
 
         uint64_t orphans_;   ///< Number of orphant received packets.
 
+        uint64_t collected_; ///< Number of garbage collected packets.
+
         /// Sum of unordered lookup sets. Needed to calculate mean size of
         /// lookup set. It is desired that number of unordered lookups is
         /// minimal for performance reasons. Tracking number of lookups and
@@ -787,11 +825,12 @@ public:
     /// for performance reasons and to avoid waste of memory for storing
     /// large list of archived packets.
     ///
+    /// \param drop_time maximum time elapsed before packet is
+    /// assumed dropped. Negative value disables it.
     /// \param archive_enabled true indicates that packets
     /// archive mode is enabled.
     StatsMgr(const bool archive_enabled = false) :
         exchanges_(),
-        custom_counters_(),
         archive_enabled_(archive_enabled),
         boot_time_(boost::posix_time::microsec_clock::universal_time()) {
     }
@@ -804,12 +843,15 @@ public:
     ///
     /// \param xchg_type exchange type.
     /// \throw isc::BadValue if exchange of specified type exists.
-    void addExchangeStats(const ExchangeType xchg_type) {
+    void addExchangeStats(const ExchangeType xchg_type,
+                          const double drop_time = -1) {
         if (exchanges_.find(xchg_type) != exchanges_.end()) {
             isc_throw(BadValue, "Exchange of specified type already added.");
         }
         exchanges_[xchg_type] =
-            ExchangeStatsPtr(new ExchangeStats(xchg_type, archive_enabled_));
+            ExchangeStatsPtr(new ExchangeStats(xchg_type,
+                                               drop_time,
+                                               archive_enabled_));
     }
 
     /// \brief Add named custom uint64 counter.
@@ -1062,6 +1104,22 @@ public:
         return(xchg_stats->getDroppedPacketsNum());
     }
 
+    /// \brief Return number of garbage collected packets.
+    ///
+    /// Method returns number of garbage collected timed out
+    /// packets. Packet is assumed timed out when duration
+    /// between sending it to server and receiving server's
+    /// response is greater than value specified with -d<value>
+    /// command line argument.
+    ///
+    /// \throw isc::BadValue if invalid exchange type specified.
+    /// \return number of garbage collected packets.
+    uint64_t getCollectedNum(const ExchangeType xchg_type) const {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        return(xchg_stats->getCollectedNum());
+    }
+
+
     /// \brief Get time period since the start of test.
     ///
     /// Calculate dna return period since the test start. This
@@ -1149,7 +1207,7 @@ public:
             stream_rcvd << sep << it->second->getRcvdPacketsNum();
             stream_drops << sep << it->second->getDroppedPacketsNum();
         }
-        std::cout << "sent: " << stream_sent.str() 
+        std::cout << "sent: " << stream_sent.str()
                   << "; received: " << stream_rcvd.str()
                   << "; drops: " << stream_drops.str()
                   << std::endl;

+ 10 - 6
tests/tools/perfdhcp/test_control.cc

@@ -553,17 +553,21 @@ TestControl::initializeStatsMgr() {
     if (options.getIpVersion() == 4) {
         stats_mgr4_.reset();
         stats_mgr4_ = StatsMgr4Ptr(new StatsMgr4(archive_mode));
-        stats_mgr4_->addExchangeStats(StatsMgr4::XCHG_DO);
+        stats_mgr4_->addExchangeStats(StatsMgr4::XCHG_DO,
+                                      options.getDropTime()[0]);
         if (options.getExchangeMode() == CommandOptions::DORA_SARR) {
-            stats_mgr4_->addExchangeStats(StatsMgr4::XCHG_RA);
+            stats_mgr4_->addExchangeStats(StatsMgr4::XCHG_RA,
+                                          options.getDropTime()[1]);
         }
 
     } else if (options.getIpVersion() == 6) {
         stats_mgr6_.reset();
         stats_mgr6_ = StatsMgr6Ptr(new StatsMgr6(archive_mode));
-        stats_mgr6_->addExchangeStats(StatsMgr6::XCHG_SA);
+        stats_mgr6_->addExchangeStats(StatsMgr6::XCHG_SA,
+                                      options.getDropTime()[0]);
         if (options.getExchangeMode() == CommandOptions::DORA_SARR) {
-            stats_mgr6_->addExchangeStats(StatsMgr6::XCHG_RR);
+            stats_mgr6_->addExchangeStats(StatsMgr6::XCHG_RR,
+                                          options.getDropTime()[1]);
         }
     }
     if (testDiags('i')) {
@@ -768,8 +772,8 @@ TestControl::printRate() const {
     }
     std::cout << "***Rate statistics***" << std::endl;
     if (options.getRate() > 0) {
-        std::cout << "Rate: " << rate << ", expected rate: "
-                  << options.getRate() << std::endl << std::endl;
+        std::cout << "Rate: " << rate << " exchanges/second, expected rate: "
+                  << options.getRate() << " exchanges/second" <<  std::endl << std::endl;
     } else {
         std::cout << "Rate: " << rate << std::endl << std::endl;
     }

+ 2 - 1
tests/tools/perfdhcp/tests/stats_mgr_unittest.cc

@@ -166,6 +166,7 @@ TEST_F(StatsMgrTest, Constructor) {
     EXPECT_EQ(0, stats_mgr->getUnorderedLookups(StatsMgr4::XCHG_DO));
     EXPECT_EQ(0, stats_mgr->getSentPacketsNum(StatsMgr4::XCHG_DO));
     EXPECT_EQ(0, stats_mgr->getRcvdPacketsNum(StatsMgr4::XCHG_DO));
+    EXPECT_EQ(0, stats_mgr->getCollectedNum(StatsMgr4::XCHG_DO));
 
     EXPECT_THROW(stats_mgr->getAvgDelay(StatsMgr4::XCHG_DO), InvalidOperation);
     EXPECT_THROW(stats_mgr->getStdDevDelay(StatsMgr4::XCHG_DO),
@@ -342,7 +343,7 @@ TEST_F(StatsMgrTest, Orphans) {
 TEST_F(StatsMgrTest, Delays) {
 
     boost::shared_ptr<StatsMgr4> stats_mgr(new StatsMgr4());
-    stats_mgr->addExchangeStats(StatsMgr4::XCHG_DO);
+    stats_mgr->addExchangeStats(StatsMgr4::XCHG_DO, 5);
 
     // Send DISCOVER, wait 2s and receive OFFER. This will affect
     // counters in Stats Manager.