20#include <boost/noncopyable.hpp>
21#include <boost/shared_ptr.hpp>
22#include <boost/function.hpp>
23#include <boost/date_time/posix_time/posix_time.hpp>
32static const size_t DHCPV4_TRANSID_OFFSET = 4;
34static const size_t DHCPV4_RANDOMIZATION_OFFSET = 35;
36static const size_t DHCPV4_ELAPSED_TIME_OFFSET = 8;
38static const size_t DHCPV4_SERVERID_OFFSET = 54;
40static const size_t DHCPV4_REQUESTED_IP_OFFSET = 240;
42static const size_t DHCPV6_TRANSID_OFFSET = 1;
45static const size_t DHCPV6_RANDOMIZATION_OFFSET = 21;
47static const size_t DHCPV6_ELAPSED_TIME_OFFSET = 84;
49static const size_t DHCPV6_SERVERID_OFFSET = 22;
51static const size_t DHCPV6_IA_NA_OFFSET = 40;
190 void initSocketData();
235 num_ = (num_ + 1) % range_;
717 const bool preload =
false);
735 const std::vector<uint8_t>& template_buf,
736 const bool preload =
false);
760 const uint64_t packets_num,
761 const bool preload =
false);
770 const uint64_t msg_num);
781 const uint32_t msg_type,
782 const uint64_t msg_num);
805 const TestControlSocket& socket);
838 const std::vector<uint8_t>& template_buf,
874 const std::vector<uint8_t>& template_buf,
895 const bool preload =
false);
909 const std::vector<uint8_t>& template_buf,
910 const bool preload =
false);
1005 std::string
byte2Hex(
const uint8_t b)
const;
1136 std::string
vector2Hex(
const std::vector<uint8_t>& vec,
1137 const std::string& separator =
"")
const;
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Universe
defines option universe DHCPv4 or DHCPv6
Exception thrown when the required option is not found in a packet.
OptionNotFound(const char *file, size_t line, const char *what)
Represents a list of packets with a sequential and random access to list elements.
A message sending rate control class for perfdhcp.
ExchangeType
DHCP packet exchange types.
virtual uint32_t generate()=0
Generate number.
virtual ~NumberGenerator()
Destructor.
Sequential numbers generator class.
virtual uint32_t generate()
Generate number sequentially.
SequentialGenerator(uint32_t range=0xFFFFFFFF)
Constructor.
void sendDiscover4(const TestControlSocket &socket, const bool preload=false)
Send DHCPv4 DISCOVER message.
void saveFirstPacket(const dhcp::Pkt4Ptr &pkt)
Save the first DHCPv4 sent packet of the specified type.
TestControl()
Default constructor.
static const uint8_t HW_ETHER_LEN
Length of the Ethernet HW address (MAC) in bytes.
isc::util::random::UniformRandomIntegerGenerator number_generator_
Generate uniformly distributed integers in range of [min, max].
std::map< uint8_t, dhcp::Pkt4Ptr > template_packets_v4_
First packets send.
StatsMgr< dhcp::Pkt6 > StatsMgr6
Statistics Manager for DHCPv6.
void addExtraOpts(const dhcp::Pkt4Ptr &pkt4)
Inserts extra options specified by user.
bool waitToExit() const
Delay the exit by a fixed given time to catch up to all exchanges that were already started.
void printDiagnostics() const
Print main diagnostics data.
static void handleChild(int sig)
Handle child signal.
void registerOptionFactories4() const
Register option factory functions for DHCPv4.
NumberGeneratorPtr transid_gen_
Transaction id generator.
void sendRequest4(const TestControlSocket &socket, const dhcp::Pkt4Ptr &discover_pkt4, const dhcp::Pkt4Ptr &offer_pkt4)
Send DHCPv4 REQUEST message.
NumberGeneratorPtr macaddr_gen_
Numbers generator for MAC address.
uint64_t getRcvdPacketsNum(ExchangeType xchg_type) const
Get number of received packets.
int getRequestedIpOffset() const
Return requested ip offset in a packet.
void processReceivedPacket4(const TestControlSocket &socket, const dhcp::Pkt4Ptr &pkt4)
Process received DHCPv4 packet.
boost::shared_ptr< StatsMgr4 > StatsMgr4Ptr
Pointer to Statistics Manager for DHCPv4;.
boost::shared_ptr< NumberGenerator > NumberGeneratorPtr
The default generator pointer.
int openSocket() const
Open socket to communicate with DHCP server.
void sendRequest6(const TestControlSocket &socket, const dhcp::Pkt6Ptr &advertise_pkt6)
Send DHCPv6 REQUEST message.
static bool interrupted_
Is program interrupted.
std::string byte2Hex(const uint8_t b) const
Convert binary value to hex string.
void readPacketTemplate(const std::string &file_name)
Read DHCP message template from file.
TemplateBuffer getTemplateBuffer(const size_t idx) const
Return template buffer.
std::vector< uint8_t > generateMacAddress(uint8_t &randomized)
Generate MAC address.
StatsMgr6Ptr stats_mgr6_
Statistics Manager 6.
void processReceivedPacket6(const TestControlSocket &socket, const dhcp::Pkt6Ptr &pkt6)
Process received DHCPv6 packet.
static TestControl & instance()
TestControl is a singleton class.
void setMacAddrGenerator(const NumberGeneratorPtr &generator)
Set new MAC address generator.
boost::posix_time::ptime last_report_
Last intermediate report time.
bool haveAllPacketsBeenReceived() const
Checks if all expected packets were already received.
StatsMgr4Ptr stats_mgr4_
Statistics Manager 4.
void cleanCachedPackets()
Removes cached DHCPv6 Reply packets every second.
bool sendRequestFromAck(const TestControlSocket &socket)
Send DHCPv4 renew (DHCPREQUEST) using specified socket.
void sendPackets(const TestControlSocket &socket, const uint64_t packets_num, const bool preload=false)
Send number of packets to initiate new exchanges.
std::vector< TemplateBuffer > TemplateBufferCollection
Packet template buffers list.
dhcp::Pkt4Ptr createRequestFromAck(const dhcp::Pkt4Ptr &ack)
Creates DHCPREQUEST from a DHCPACK message.
std::string vector2Hex(const std::vector< uint8_t > &vec, const std::string &separator="") const
Convert vector in hexadecimal string.
uint32_t getCurrentTimeout() const
Returns a timeout for packet reception.
RateControl release_rate_control_
A rate control class for Release messages.
static dhcp::OptionPtr factoryOptionRequestOption6(dhcp::Option::Universe u, uint16_t type, const dhcp::OptionBuffer &buf)
Factory function to create DHCPv6 ORO option.
bool sendMessageFromReply(const uint16_t msg_type, const TestControlSocket &socket)
Send DHCPv6 Renew or Release message using specified socket.
static dhcp::OptionPtr factoryIapd6(dhcp::Option::Universe u, uint16_t type, const dhcp::OptionBuffer &buf)
Factory function to create IA_PD option.
std::map< uint8_t, dhcp::Pkt6Ptr > template_packets_v6_
static dhcp::OptionPtr factoryRapidCommit6(dhcp::Option::Universe u, uint16_t type, const dhcp::OptionBuffer &buf)
Factory function to create DHCPv6 RAPID_COMMIT option instance.
PacketStorage< dhcp::Pkt6 > reply_storage_
A storage for reply messages.
void registerOptionFactories6() const
Register option factory functions for DHCPv6.
bool checkExitConditions() const
Check if test exit conditions fulfilled.
void registerOptionFactories() const
Register option factory functions for DHCPv4 or DHCPv6.
uint64_t receivePackets(const TestControlSocket &socket)
Receive DHCPv4 or DHCPv6 packets from the server.
std::vector< uint8_t > TemplateBuffer
Packet template buffer.
void runWrapped(bool do_stop=false) const
Run wrapped command.
uint32_t getElapsedTime(const T &pkt1, const T &pkt2)
Calculate elapsed time between two packets.
void reset()
Resets internal state of the object.
void setDefaults6(const TestControlSocket &socket, const dhcp::Pkt6Ptr &pkt)
Set default DHCPv6 packet parameters.
int run()
brief\ Run performance test.
boost::shared_ptr< StatsMgr6 > StatsMgr6Ptr
Pointer to Statistics Manager for DHCPv6.
int getRandomOffset(const int arg_idx) const
Return randomization offset in a packet.
dhcp::Pkt6Ptr createMessageFromReply(const uint16_t msg_type, const dhcp::Pkt6Ptr &reply)
Creates DHCPv6 message from the Reply packet.
int getElapsedTimeOffset() const
Return elapsed time offset in a packet.
uint64_t sendMultipleRequests(const TestControlSocket &socket, const uint64_t msg_num)
Send number of DHCPREQUEST (renew) messages to a server.
bool testDiags(const char diag) const
Find if diagnostic flag has been set.
void printTemplates() const
Print templates information.
void setDefaults4(const TestControlSocket &socket, const dhcp::Pkt4Ptr &pkt)
Set default DHCPv4 packet parameters.
TemplateBufferCollection template_buffers_
Packet template buffers.
uint64_t sendMultipleMessages6(const TestControlSocket &socket, const uint32_t msg_type, const uint64_t msg_num)
Send number of DHCPv6 Renew or Release messages to the server.
void printStats() const
Print performance statistics.
PacketStorage< dhcp::Pkt4 > ack_storage_
A storage for DHCPACK messages.
void copyIaOptions(const dhcp::Pkt6Ptr &pkt_from, dhcp::Pkt6Ptr &pkt_to)
Copies IA_NA or IA_PD option from one packet to another.
StatsMgr< dhcp::Pkt4 > StatsMgr4
Statistics Manager for DHCPv4.
void setTransidGenerator(const NumberGeneratorPtr &generator)
Set new transaction id generator.
static dhcp::OptionPtr factoryGeneric(dhcp::Option::Universe u, uint16_t type, const dhcp::OptionBuffer &buf)
Factory function to create generic option.
static dhcp::OptionPtr factoryRequestList4(dhcp::Option::Universe u, uint16_t type, const dhcp::OptionBuffer &buf)
Factory function to create DHCPv4 Request List option.
void sendSolicit6(const TestControlSocket &socket, const bool preload=false)
Send DHCPv6 SOLICIT message.
uint64_t getSentPacketsNum(ExchangeType xchg_type) const
Get number of sent packets.
void initializeStatsMgr()
Initializes Statistics Manager.
static dhcp::OptionPtr factoryElapsedTime6(dhcp::Option::Universe u, uint16_t type, const dhcp::OptionBuffer &buf)
Factory function to create DHCPv6 ELAPSED_TIME option.
static void handleInterrupt(int sig)
Handle interrupt signal.
int getTransactionIdOffset(const int arg_idx) const
Return transaction id offset in a packet.
RateControl renew_rate_control_
A rate control class for Renew messages.
void initPacketTemplates()
Reads packet templates from files.
void printRate() const
Print rate statistics.
void printIntermediateStats()
Print intermediate statistics.
void printTemplate(const uint8_t packet_type) const
Print template information.
int getServerIdOffset() const
Return server id offset in a packet.
std::vector< uint8_t > generateDuid(uint8_t &randomized)
Generate DUID.
StatsMgr ::ExchangeType ExchangeType
Packet exchange type.
void checkLateMessages(RateControl &rate_control)
Increments counter of late sent messages if required.
bool hasLateExitCommenced() const
Check if the program is in that period where the program was bound to exit, but was delayed by lateEx...
dhcp::OptionPtr generateClientId(const dhcp::HWAddrPtr &hwaddr) const
Generate DHCPv4 client identifier from HW address.
RateControl basic_rate_control_
A rate control class for Discover and Solicit messages.
dhcp::OptionBuffer first_packet_serverid_
Buffer holding server id received in first packet.
uint32_t generateTransid()
generate transaction id.
static dhcp::OptionPtr factoryIana6(dhcp::Option::Universe u, uint16_t type, const dhcp::OptionBuffer &buf)
Factory function to create IA_NA option.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
boost::shared_ptr< Option > OptionPtr
Defines the logger used by the top-level component of kea-dhcp-ddns.
Holds information about socket.
Socket wrapper structure.
bool valid_
Is socket valid.
~TestControlSocket()
Destructor of the socket wrapper class.
uint16_t ifindex_
Interface index.