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