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