const CommandOptions::MacAddrsVector& macs = options_.getMacsFromFile();
// if we are using the -M option return a random one from the list...
if (macs.size() > 0) {
- uint16_t r = number_generator_();
+ uint16_t r = random_generator_->generate();
if (r >= macs.size()) {
r = 0;
}
const CommandOptions::MacAddrsVector& macs = options_.getMacsFromFile();
// pick a random mac address if we are using option -M..
if (macs.size() > 0) {
- uint16_t r = number_generator_();
+ uint16_t r = random_generator_->generate();
if (r >= macs.size()) {
r = 0;
}
TestControl::TestControl(CommandOptions& options, BasePerfSocket &socket) :
exit_time_(not_a_date_time),
- number_generator_(0, options.getMacsFromFile().size()),
socket_(socket),
receiver_(socket, options.isSingleThreaded(), options.getIpVersion()),
stats_mgr_(options),
+ random_generator_(NumberGeneratorPtr(
+ new RandomGenerator(0, options.getMacsFromFile().size())
+ )),
options_(options)
{
// Reset singleton state before test starts.
#include <perfdhcp/receiver.h>
#include <perfdhcp/command_options.h>
#include <perfdhcp/perf_socket.h>
-#include <perfdhcp/random_number_generator.h>
#include <dhcp/iface_mgr.h>
#include <dhcp/dhcp4.h>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_int_distribution.hpp>
#include <string>
#include <vector>
uint32_t range_; ///< Number of unique numbers generated.
};
+ /// \brief Random numbers generator class. The generated numbers
+ /// are uniformly distributed in the range of [min, max].
+ class RandomGenerator : public NumberGenerator {
+ public:
+ /// \brief Constructor.
+ ///
+ /// \param min minimum number generated.
+ /// \param max maximum number generated.
+ RandomGenerator(uint32_t min, uint32_t max) :
+ NumberGenerator(),
+ distribution(min, max) {
+ // Initialize the randomness source with the current time.
+ randomnessGenerator.seed(time(NULL));
+ }
+
+ /// \brief Generate number in range of [min, max].
+ ///
+ /// \return generated number.
+ virtual uint32_t generate() {
+ return distribution(randomnessGenerator);
+ }
+
+ private:
+ boost::random::uniform_int_distribution<> distribution;
+ boost::random::mt19937 randomnessGenerator;
+ };
+
/// \brief Length of the Ethernet HW address (MAC) in bytes.
///
/// \todo Make this variable length as there are cases when HW
// solution is to make this class friend of test class but this is not
// what's followed in other classes.
protected:
- /// Generate uniformly distributed integers in range of [min, max]
- UniformRandomIntegerGenerator number_generator_;
-
/// \brief Creates DHCPREQUEST from a DHCPACK message.
///
/// @param msg_type the message type to be created (DHCPREQUEST or DHCPRELEASE)
/// \brief Storage for reply messages.
PacketStorage<dhcp::Pkt6> reply_storage_;
+ /// \brief Generate uniformly distributed integers in range of
+ /// [min, max].
+ NumberGeneratorPtr random_generator_;
+
/// \brief Transaction id generator.
NumberGeneratorPtr transid_gen_;