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;
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
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);
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;
class AvalancheScen : public boost::noncopyable {
public:
- AvalancheScen(): tc_(true), total_resent_(0) {};
+ AvalancheScen(): total_resent_(0) {};
/// brief\ Run performance test.
///
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);
class BasicScen : public boost::noncopyable {
public:
- BasicScen() : tc_(false) {};
+ BasicScen() {};
/// \brief Check if test exit conditions fulfilled.
///
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_(),
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();
}
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: "
}
}
-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();
/// \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.
///
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.
/// 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.
///
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.
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;
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();
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;
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