Browse Source

[3183] Passive wait for the packets to receive.

Marcin Siodelski 11 years ago
parent
commit
f1094390dc
2 changed files with 29 additions and 3 deletions
  1. 20 3
      tests/tools/perfdhcp/test_control.cc
  2. 9 0
      tests/tools/perfdhcp/test_control.h

+ 20 - 3
tests/tools/perfdhcp/test_control.cc

@@ -483,6 +483,24 @@ TestControl::generateDuid(uint8_t& randomized) const {
     return (duid);
 }
 
+uint32_t
+TestControl::getCurrentTimeout() const {
+    CommandOptions& options = CommandOptions::instance();
+    ptime now(microsec_clock::universal_time());
+    // Check that we haven't passed the moment to send the next set of
+    // packets.
+    if (now >= send_due_ ||
+        (options.getRenewRate() != 0 && now >= renew_due_)) {
+        return (0);
+    }
+
+    // There is a due time to send Solicit and Renew. We should adjust
+    // the timeout to the due time which occurs sooner.
+    ptime due = send_due_ > renew_due_ ? renew_due_ : send_due_;
+    time_period due_period(now, due);
+    return (due_period.length().total_microseconds());
+}
+
 int
 TestControl::getElapsedTimeOffset() const {
     int elp_offset = CommandOptions::instance().getIpVersion() == 4 ?
@@ -1110,14 +1128,13 @@ TestControl::processReceivedPacket6(const TestControlSocket& socket,
 
 uint64_t
 TestControl::receivePackets(const TestControlSocket& socket) {
-    int timeout = 0;
     bool receiving = true;
     uint64_t received = 0;
     while (receiving) {
         if (CommandOptions::instance().getIpVersion() == 4) {
             Pkt4Ptr pkt4;
             try {
-                pkt4 = IfaceMgr::instance().receive4(timeout);
+                pkt4 = IfaceMgr::instance().receive4(getCurrentTimeout());
             } catch (const Exception& e) {
                 std::cerr << "Failed to receive DHCPv4 packet: "
                           << e.what() <<  std::endl;
@@ -1135,7 +1152,7 @@ TestControl::receivePackets(const TestControlSocket& socket) {
         } else if (CommandOptions::instance().getIpVersion() == 6) {
             Pkt6Ptr pkt6;
             try {
-                pkt6 = IfaceMgr::instance().receive6(timeout);
+                pkt6 = IfaceMgr::instance().receive6(getCurrentTimeout());
             } catch (const Exception& e) {
                 std::cerr << "Failed to receive DHCPv6 packet: "
                           << e.what() << std::endl;

+ 9 - 0
tests/tools/perfdhcp/test_control.h

@@ -469,6 +469,15 @@ protected:
         return (transid_gen_->generate());
     }
 
+    /// \brief Returns a timeout for packet reception.
+    ///
+    /// The calculation is based on the value of the timestamp
+    /// when the next set of packets is to be sent. If no packet is
+    /// received until then, new packets are sent.
+    ///
+    /// \return A current timeout in microseconds.
+    uint32_t getCurrentTimeout() const;
+
     /// \brief Returns number of exchanges to be started.
     ///
     /// Method returns number of new exchanges to be started as soon