24 #include <boost/noncopyable.hpp> 25 #include <boost/shared_ptr.hpp> 26 #include <boost/date_time/posix_time/posix_time.hpp> 30 #include <unordered_map> 36 static const size_t DHCPV4_TRANSID_OFFSET = 4;
38 static const size_t DHCPV4_RANDOMIZATION_OFFSET = 35;
40 static const size_t DHCPV4_ELAPSED_TIME_OFFSET = 8;
42 static const size_t DHCPV4_SERVERID_OFFSET = 54;
44 static const size_t DHCPV4_REQUESTED_IP_OFFSET = 240;
46 static const size_t DHCPV6_TRANSID_OFFSET = 1;
49 static const size_t DHCPV6_RANDOMIZATION_OFFSET = 21;
51 static const size_t DHCPV6_ELAPSED_TIME_OFFSET = 84;
53 static const size_t DHCPV6_SERVERID_OFFSET = 22;
55 static const size_t DHCPV6_IA_NA_OFFSET = 40;
178 num_ = (num_ + 1) % range_;
268 const bool preload =
false);
278 const uint64_t msg_num);
288 const uint64_t msg_num);
330 static std::string
byte2Hex(
const uint8_t b);
338 static std::string
vector2Hex(
const std::vector<uint8_t>& vec,
339 const std::string& separator =
"");
618 for (
auto current_it = current.begin();
619 current_it != current.end(); ++current_it) {
629 for (
auto current_it = current.begin();
630 current_it != current.end(); ++current_it) {
645 for (
auto current_it = current.begin();
646 current_it != current.end(); ++current_it) {
656 for (
auto current_it = current.begin();
657 current_it != current.end(); ++current_it) {
680 for (
auto addr_it = addr.begin(); addr_it != addr.end(); ++addr_it) {
800 const bool preload =
false);
849 void sendRequest4(
const std::vector<uint8_t>& template_buf,
881 void sendRequest6(
const std::vector<uint8_t>& template_buf,
912 void sendSolicit6(
const std::vector<uint8_t>& template_buf,
913 const bool preload =
false);
1116 #endif // TEST_CONTROL_H void sendPackets(const uint64_t packets_num, const bool preload=false)
Send number of packets to initiate new exchanges.
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.
void address6Uniqueness(const dhcp::Pkt6Ptr &pkt6, ExchangeType xchg_type)
Process received v6 addresses uniqueness.
static bool interrupted_
Program interrupted flag.
uint32_t generateTransid()
generate transaction id.
void printTemplates() const
Print templates information.
void printStats() const
Print performance statistics.
void sendSolicit6(const bool preload=false)
Send DHCPv6 SOLICIT message.
std::set< std::string > unique_address_
Keep addresses and prefixes from advertise msg for uniqueness checks.
DHCPv6 SOLICIT-ADVERTISE.
ExchangeType
DHCP packet exchange types.
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.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
PacketStorage< dhcp::Pkt4 > ack_storage_
Storage for DHCPACK messages.
std::vector< uint8_t > generateDuid(uint8_t &randomized)
Generate DUID.
bool sendMessageFromAck(const uint16_t msg_type)
Send DHCPv4 renew (DHCPREQUEST).
void registerOptionFactories4() const
Register option factory functions for DHCPv4.
static std::string vector2Hex(const std::vector< uint8_t > &vec, const std::string &separator="")
Convert vector in hexadecimal string.
void stop()
Stop a receiving thread in multi-thread mode.
void start()
Start receiver.
boost::shared_ptr< Option > OptionPtr
void setTransidGenerator(const NumberGeneratorPtr &generator)
Set new transaction id generator.
void setDefaults6(const dhcp::Pkt6Ptr &pkt)
Set default DHCPv6 packet parameters.
StatsMgr stats_mgr_
Statistics Manager.
bool sendMessageFromReply(const uint16_t msg_type)
Send DHCPv6 Renew or Release message.
Universe
defines option universe DHCPv4 or DHCPv6
void stop()
Stop receiver.
void removeUniqueAddr(const std::set< std::string > &addr)
remove unique address from list.
void printIntermediateStats()
Print intermediate statistics.
std::set< std::string > & getAllUniqueAddrReply()
Get set of unique replied addresses.
static dhcp::OptionPtr factoryRapidCommit6(dhcp::Option::Universe u, uint16_t type, const dhcp::OptionBuffer &buf)
Factory function to create DHCPv6 RAPID_COMMIT option instance.
std::string getServerId() const
Get received server id.
void address4Uniqueness(const dhcp::Pkt4Ptr &pkt4, ExchangeType xchg_type)
Process received v4 addresses uniqueness.
uint64_t sendMultipleMessages4(const uint32_t msg_type, const uint64_t msg_num)
Send number of DHCPREQUEST (renew) messages to a server.
void initPacketTemplates()
Reads packet templates from files.
bool validateIA(const dhcp::Pkt6Ptr &pkt6)
Process IA in received DHCPv6 packet.
dhcp::OptionPtr generateClientId(const dhcp::HWAddrPtr &hwaddr) const
Generate DHCPv4 client identifier from HW address.
static std::string byte2Hex(const uint8_t b)
Convert binary value to hex string.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
std::vector< TemplateBuffer > TemplateBufferCollection
Packet template buffers list.
bool waitToExit()
Delay the exit by a fixed given time to catch up to all exchanges that were already started...
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.
void setDefaults4(const dhcp::Pkt4Ptr &pkt)
Set default DHCPv4 packet parameters.
void printRate() const
Print rate statistics.
uint64_t sendMultipleMessages6(const uint32_t msg_type, const uint64_t msg_num)
Send number of DHCPv6 Renew or Release messages to the server.
std::vector< uint8_t > TemplateBuffer
Packet template buffer.
dhcp::Pkt4Ptr createMessageFromAck(const uint16_t msg_type, const dhcp::Pkt4Ptr &ack)
Creates DHCPREQUEST from a DHCPACK message.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
int getRandomOffset(const int arg_idx) const
Return randomization offset in a packet.
std::set< std::string > unique_reply_address_
Keep addresses and prefixes from reply msg for uniqueness checks.
DHCPv4 REQUEST-ACK (renewal)
void runWrapped(bool do_stop=false) const
Run wrapped command.
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_
Template for v6.
UniformRandomIntegerGenerator number_generator_
Generate uniformly distributed integers in range of [min, max].
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::posix_time::ptime exit_time_
Initialized at first exit condition with the time perfdhcp should exit.
TemplateBuffer getTemplateBuffer(const size_t idx) const
Return template buffer.
int getTransactionIdOffset(const int arg_idx) const
Return transaction id offset in a packet.
void processReceivedPacket4(const dhcp::Pkt4Ptr &pkt4)
Process received DHCPv4 packet.
void start()
Start a receiving thread in multi-thread mode.
void sendDiscover4(const bool preload=false)
Send DHCPv4 DISCOVER message.
Receiver receiver_
Receiver used to receive DHCP traffic.
std::vector< uint8_t > generateMacAddress(uint8_t &randomized)
Generate MAC address.
void sendRequest6(const dhcp::Pkt6Ptr &advertise_pkt6)
Send DHCPv6 REQUEST message.
Defines the logger used by the top-level component of kea-lfc.
static dhcp::OptionPtr factoryRequestList4(dhcp::Option::Universe u, uint16_t type, const dhcp::OptionBuffer &buf)
Factory function to create DHCPv4 Request List option.
void sendRequest4(const dhcp::Pkt4Ptr &discover_pkt4, const dhcp::Pkt4Ptr &offer_pkt4)
Send DHCPv4 REQUEST message.
unsigned int consumeReceivedPackets()
Pull packets from receiver and process them.
void copyIaOptions(const dhcp::Pkt6Ptr &pkt_from, dhcp::Pkt6Ptr &pkt_to)
Copies IA_NA or IA_PD option from one packet to another.
static void handleChild(int sig)
Handle child signal.
void cleanCachedPackets()
Removes cached DHCPv6 Reply packets every second.
PacketStorage< dhcp::Pkt6 > reply_storage_
Storage for reply messages.
void saveFirstPacket(const dhcp::Pkt4Ptr &pkt)
Save the first DHCPv4 sent packet of the specified type.
bool interrupted() const
Get interrupted flag.
void registerOptionFactories() const
Register option factory functions for DHCPv4 or DHCPv6.
bool serverIdReceived() const
Get received server id flag.
void registerOptionFactories6() const
Register option factory functions for DHCPv6.
CommandOptions & options_
Command options.
StatsMgr & getStatsMgr()
Get stats manager.
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.
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.
void processReceivedPacket6(const dhcp::Pkt6Ptr &pkt6)
Process received DHCPv6 packet.
TestControl(CommandOptions &options, BasePerfSocket &socket)
Default constructor.
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.
Socket wrapper structure.
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.
void addUniqeAddr(const std::set< std::string > ¤t, ExchangeType xchg_type)
add unique address to already assigned list.
uint32_t getElapsedTime(const T &pkt1, const T &pkt2)
Calculate elapsed time between two packets.
void setMacAddrGenerator(const NumberGeneratorPtr &generator)
Set new MAC address generator.
void updateNonUniqueAddrNum(const ExchangeType xchg_type)
Increase total number of non unique addresses.
virtual ~NumberGenerator()
Destructor.
std::set< std::string > & getAllUniqueAddrAdvert()
Get set of unique advertised addresses.
std::map< uint8_t, dhcp::Pkt4Ptr > template_packets_v4_
First packets send.
int getRequestedIpOffset() const
Return requested ip offset in a packet.
BasePerfSocket & socket_
Socket used for DHCP traffic.
virtual uint32_t generate()
Generate number sequentially.
int getElapsedTimeOffset() const
Return elapsed time offset in a packet.
int getServerIdOffset() const
Return server id offset in a packet.
A receiving DHCP packets class.
void reset()
Resets internal state of the object.
Represents a list of packets with a sequential and random access to list elements.
static void handleInterrupt(int sig)
Handle interrupt signal.
Sequential numbers generator class.
void addExtraOpts(const dhcp::Pkt4Ptr &pkt4)
Inserts extra options specified by user.