25#include <boost/date_time/posix_time/posix_time.hpp>
37using namespace boost::posix_time;
53 const ptime now = microsec_clock::universal_time();
57 exit_time_ = now + time_duration(microseconds(wait_time));
72 const size_t& num_request_size = num_request.size();
74 if (num_request_size == 0) {
78 uint32_t responses = 0;
79 uint32_t requests = num_request[0];
80 if (num_request_size >= 2) {
81 requests += num_request[1];
92 return (responses == requests);
103 static boost::posix_time::ptime last_clean =
104 microsec_clock::universal_time();
107 time_period time_since_clean(last_clean,
108 microsec_clock::universal_time());
110 if (time_since_clean.length().total_seconds() >= 1) {
122 last_clean = microsec_clock::universal_time();
128 if (!pkt_from || !pkt_to) {
130 " for the copyIaOptions function");
138 " server's response");
140 pkt_to->addOption(option);
148 " server's response");
150 pkt_to->addOption(option);
156 const int b1 = b / 16;
157 const int b0 = b % 16;
158 ostringstream stream;
159 stream << std::hex << b1 << b0 << std::dec;
160 return (stream.str());
169 <<
" to be created from Reply, expected DHCPREQUEST or"
175 auto msg_type_str = [=]() ->
const char* {
176 return (msg_type ==
DHCPREQUEST ?
"Request" :
"Release");
182 <<
" from a null DHCPACK message");
183 }
else if (ack->getYiaddr().isV4Zero()) {
187 <<
" from a DHCPACK message containing yiaddr of 0");
190 msg->setCiaddr(ack->getYiaddr());
191 msg->setHWAddr(ack->getHWAddr());
201 <<
"from the first packet which lacks the server "
202 "identifier option");
204 msg->addOption(Option::factory(Option::V4,
211 if (!server_identifier) {
215 <<
"from a DHCPACK message without the server "
216 "identifier option");
218 msg->addOption(server_identifier);
230 <<
" to be created from Reply, expected DHCPV6_RENEW or"
236 auto msg_type_str = [=]() ->
const char* {
237 return (msg_type ==
DHCPV6_RENEW ?
"Renew" :
"Release");
243 <<
" message from the Reply message because the instance of"
244 " the Reply message is NULL");
252 <<
" message because client id option has not been found"
253 " in the Reply message");
255 msg->addOption(opt_clientid);
260 <<
" because server id option has not been found in the"
263 msg->addOption(opt_serverid);
271 if (buf.size() == 2) {
273 }
else if (buf.size() == 0) {
278 "elapsed time option buffer size has to be 0 or 2");
292 const uint8_t buf_array[] = {
294 0, 0, 3600 >> 8, 3600 & 0xff,
295 0, 0, 5400 >> 8, 5400 & 0xff,
297 OptionBuffer buf_ia_na(buf_array, buf_array +
sizeof(buf_array));
298 for (
size_t i = 0; i < buf.size(); ++i) {
299 buf_ia_na.push_back(buf[i]);
308 static const uint8_t buf_array[] = {
310 0, 0, 3600 >> 8, 3600 & 0xff,
311 0, 0, 5400 >> 8, 5400 & 0xff,
313 OptionBuffer buf_ia_pd(buf_array, buf_array +
sizeof(buf_array));
315 buf_ia_pd.insert(buf_ia_pd.end(), buf.begin(), buf.end());
330 const uint8_t buf_array[] = {
334 OptionBuffer buf_with_options(buf_array, buf_array +
sizeof(buf_array));
343 const uint8_t buf_array[] = {
353 OptionBuffer buf_with_options(buf_array, buf_array +
sizeof(buf_array));
355 opt->setData(buf_with_options.begin(), buf_with_options.end());
363 if (macs.size() > 0) {
365 if (r >= macs.size()) {
373 if (clients_num < 2) {
384 for (std::vector<uint8_t>::iterator it = mac_addr.end() - 1;
385 it >= mac_addr.begin();
407 std::vector<uint8_t> client_id(1,
static_cast<uint8_t
>(hwaddr->htype_));
408 client_id.insert(client_id.end(), hwaddr->hwaddr_.begin(),
409 hwaddr->hwaddr_.end());
419 if (macs.size() > 0) {
421 if (r >= macs.size()) {
424 std::vector<uint8_t> mac = macs[r];
438 uint8_t duid_ll[] = {0, 3, 0, 1, 0, 0, 0, 0, 0, 0};
440 std::vector<uint8_t> duid(duid_ll,
441 duid_ll +
sizeof(duid_ll) /
sizeof(duid_ll[0]));
443 std::copy(mac.begin(), mac.end(), duid.begin() + 4);
447 if ((clients_num == 0) || (clients_num == 1)) {
453 duid.resize(duid.size());
454 std::copy(mac_addr.begin(), mac_addr.end(),
455 duid.begin() + duid.size() - mac_addr.size());
463 DHCPV4_ELAPSED_TIME_OFFSET : DHCPV6_ELAPSED_TIME_OFFSET;
473 using namespace boost::posix_time;
474 ptime pkt1_time = pkt1->getTimestamp();
475 ptime pkt2_time = pkt2->getTimestamp();
476 if (pkt1_time.is_not_a_date_time() ||
477 pkt2_time.is_not_a_date_time()) {
480 time_period elapsed_period(pkt1_time, pkt2_time);
481 return (elapsed_period.is_null() ? 0 :
482 elapsed_period.length().total_milliseconds());
488 DHCPV4_RANDOMIZATION_OFFSET : DHCPV6_RANDOMIZATION_OFFSET;
492 return (rand_offset);
498 DHCPV4_REQUESTED_IP_OFFSET : DHCPV6_IA_NA_OFFSET;
508 DHCPV4_SERVERID_OFFSET : DHCPV6_SERVERID_OFFSET;
512 return (srvid_offset);
526 DHCPV4_TRANSID_OFFSET : DHCPV6_TRANSID_OFFSET;
536 while (wait3(&status, WNOHANG, NULL) > 0) {
552 for (std::vector<std::string>::const_iterator it = template_files.begin();
553 it != template_files.end(); ++it) {
560 const bool preload ) {
561 for (uint64_t i = packets_num; i > 0; --i) {
588 const uint64_t msg_num) {
589 for (uint64_t i = 0; i < msg_num; ++i) {
599 const uint64_t msg_num) {
600 for (uint64_t i = 0; i < msg_num; ++i) {
630 std::map<uint8_t, dhcp::Pkt4Ptr>::const_iterator pkt_it =
635 const char* out_buf_data =
636 static_cast<const char*
>(out_buf.
getData());
637 std::vector<uint8_t> buf(out_buf_data, out_buf_data + out_buf.
getLength());
644 std::map<uint8_t, dhcp::Pkt6Ptr>::const_iterator pkt_it =
649 const char* out_buf_data =
650 static_cast<const char*
>(out_buf.
getData());
651 std::vector<uint8_t> buf(out_buf_data, out_buf_data + out_buf.
getLength());
656 std::cout <<
"random-offset=" <<
getRandomOffset(arg_idx) << std::endl;
663 std::cout <<
"contents: " << std::endl;
666 while (line_len == 32) {
667 if (hex_buf.length() - i < 32) {
668 line_len = hex_buf.length() - i;
671 std::cout << setfill(
'0') << setw(4) << std::hex << i << std::dec
672 <<
" " << hex_buf.substr(i, line_len) << std::endl;
676 std::cout << std::endl;
693 std::string exchange_name =
"4-way exchanges";
700 exchange_name =
"DISCOVER-OFFER";
714 std::ostringstream s;
715 s <<
"***Rate statistics***" << std::endl;
716 s <<
"Rate: " << rate <<
" " << exchange_name <<
"/second";
721 std::cout << s.str() << std::endl;
723 std::cout <<
"***Malformed Packets***" << std::endl
731 ptime now = microsec_clock::universal_time();
733 if (time_since_report.length().total_seconds() >= delay) {
751 const std::string& separator ) {
752 std::ostringstream stream;
753 for (std::vector<uint8_t>::const_iterator it = vec.begin();
756 if (it == vec.begin()) {
759 stream << separator <<
byte2Hex(*it);
762 return (stream.str());
767 std::ifstream temp_file;
768 temp_file.open(file_name.c_str(), ios::in | ios::binary | ios::ate);
769 if (!temp_file.is_open()) {
773 std::streampos temp_size = temp_file.tellg();
774 if (temp_size == std::streampos(0)) {
778 temp_file.seekg(0, ios::beg);
779 std::vector<char> file_contents(temp_size);
780 temp_file.read(&file_contents[0], temp_size);
786 std::vector<char> hex_digits;
787 for (
size_t i = 0; i < file_contents.size(); ++i) {
788 if (isxdigit(file_contents[i])) {
789 hex_digits.push_back(file_contents[i]);
790 }
else if (!isxdigit(file_contents[i]) &&
791 !isspace(file_contents[i])) {
793 " hexadecimal digit");
797 if (hex_digits.size() % 2 != 0) {
799 }
else if (hex_digits.empty()) {
802 std::vector<uint8_t> binary_stream;
803 for (
size_t i = 0; i < hex_digits.size(); i += 2) {
805 s <<
"0x" << hex_digits[i] << hex_digits[i+1];
808 binary_stream.push_back(
static_cast<uint8_t
>(b));
818 Pkt4Ptr discover_pkt4(boost::dynamic_pointer_cast<Pkt4>(pkt));
829 }
else if (pkt4->getType() ==
DHCPACK) {
861 std::set<std::string> current;
864 for (
const auto& opt : pkt6->options_) {
865 switch (opt.second->getType()) {
869 auto ret = current.emplace(boost::dynamic_pointer_cast<
879 auto ret = current.emplace(boost::dynamic_pointer_cast<
901 std::set<std::string> current;
902 current.insert(pkt4->getYiaddr().toText());
919 iapref = boost::dynamic_pointer_cast<
923 iaaddr = boost::dynamic_pointer_cast<
933 if ((address_and_prefix && iapref && iaaddr) ||
934 (prefix_only && iapref && !address_and_prefix) ||
935 (address_only && iaaddr && !address_and_prefix)) {
944 uint8_t packet_type = pkt6->getType();
947 Pkt6Ptr solicit_pkt6(boost::dynamic_pointer_cast<Pkt6>(pkt));
1008 unsigned int pkt_count = 0;
1013 Pkt4Ptr pkt4 = boost::dynamic_pointer_cast<Pkt4>(pkt);
1016 Pkt6Ptr pkt6 = boost::dynamic_pointer_cast<Pkt6>(pkt);
1024 static bool factories_registered =
false;
1025 if (!factories_registered) {
1027 LibDHCP::OptionFactoryRegister(Option::V4,
1031 LibDHCP::OptionFactoryRegister(Option::V4,
1035 LibDHCP::OptionFactoryRegister(Option::V4,
1039 factories_registered =
true;
1044 static bool factories_registered =
false;
1045 if (!factories_registered) {
1047 LibDHCP::OptionFactoryRegister(Option::V6,
1051 LibDHCP::OptionFactoryRegister(Option::V6,
1055 LibDHCP::OptionFactoryRegister(Option::V6,
1059 LibDHCP::OptionFactoryRegister(Option::V6,
1063 LibDHCP::OptionFactoryRegister(Option::V6,
1067 LibDHCP::OptionFactoryRegister(Option::V6,
1072 LibDHCP::OptionFactoryRegister(Option::V6,
1078 factories_registered =
true;
1092 "before DHCP option factories can be registered");
1109 exit_time_(not_a_date_time),
1110 number_generator_(0, options.getMacsFromFile().size()),
1112 receiver_(socket, options.isSingleThreaded(), options.getIpVersion()),
1113 stats_mgr_(options),
1125 "command options must be parsed before running a test");
1128 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET,
data::ElementPtr());
1132 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET6,
data::ElementPtr());
1151 time_period duration(from_iso_string(
"20111231T235959"),
1152 microsec_clock::universal_time());
1153 srandom(duration.length().total_seconds()
1154 + duration.length().fractional_seconds());
1168 }
else if (pid == 0) {
1195 uint8_t randomized = 0;
1212 pkt4->addOption(Option::factory(Option::V4,
1221 pkt4->setHWAddr(
HTYPE_ETHER, mac_address.size(), mac_address);
1238 pkt4->setSecs(
static_cast<uint16_t
>(val));
1255 const bool preload ) {
1258 const uint8_t arg_idx = 0;
1260 uint8_t randomized = 0;
1273 std::vector<uint8_t> in_buf(template_buf.begin(),
1274 template_buf.end());
1284 pkt4->writeAt(rand_offset, mac_address.begin(), mac_address.end());
1290 socket_.
send(boost::static_pointer_cast<Pkt4>(pkt4));
1294 boost::static_pointer_cast<Pkt4>(pkt4));
1305 "invalid message type "
1307 <<
" to be sent, expected DHCPREQUEST or DHCPRELEASE");
1321 msg->setGiaddr(ack->getGiaddr());
1344 <<
" to be sent, expected DHCPV6_RENEW or DHCPV6_RELEASE");
1374 const uint32_t transid = discover_pkt4->getTransid();
1386 if (!opt_serverid) {
1388 <<
"in OFFER message");
1393 pkt4->addOption(opt_serverid);
1398 if (!yiaddr.
isV4()) {
1405 opt_requested_address->setUint32(yiaddr.
toUint32());
1406 pkt4->addOption(opt_requested_address);
1409 pkt4->addOption(opt_parameter_list);
1413 pkt4->setGiaddr(offer_pkt4->getGiaddr());
1418 pkt4->setHWAddr(offer_pkt4->getHWAddr());
1422 uint32_t elapsed_time = getElapsedTime<Pkt4Ptr>(discover_pkt4, offer_pkt4);
1423 pkt4->setSecs(
static_cast<uint16_t
>(elapsed_time / 1000));
1437 const uint8_t arg_idx = 1;
1439 const uint32_t transid = discover_pkt4->getTransid();
1447 std::vector<uint8_t> in_buf(template_buf.begin(),
1448 template_buf.end());
1460 HWAddrPtr hwaddr = offer_pkt4->getHWAddr();
1462 uint8_t hw_len = hwaddr->hwaddr_.size();
1464 memcpy(&mac_address[0], &hwaddr->hwaddr_[0],
1467 pkt4->writeAt(rand_offset, mac_address.begin(), mac_address.end());
1471 uint32_t elapsed_time = getElapsedTime<Pkt4Ptr>(discover_pkt4, offer_pkt4);
1472 pkt4->writeValueAt<uint16_t>(elp_offset,
1473 static_cast<uint16_t
>(elapsed_time / 1000));
1481 boost::shared_ptr<LocalizedOption>
1486 pkt4->addOption(opt_serverid);
1492 if (!opt_serverid_offer) {
1494 <<
"in OFFER message");
1496 boost::shared_ptr<LocalizedOption>
1499 opt_serverid_offer->getData(),
1501 pkt4->addOption(opt_serverid);
1509 if (!yiaddr.
isV4()) {
1517 boost::shared_ptr<LocalizedOption>
1523 opt_requested_ip->setUint32(yiaddr.
toUint32());
1524 pkt4->addOption(opt_requested_ip);
1533 socket_.
send(boost::static_pointer_cast<Pkt4>(pkt4));
1536 boost::static_pointer_cast<Pkt4>(pkt4));
1547 pkt6->addOption(opt_elapsed_time);
1550 if (!opt_clientid) {
1553 pkt6->addOption(opt_clientid);
1559 pkt6->addOption(Option::factory(Option::V6,
D6O_SERVERID,
1563 if (!opt_serverid) {
1569 pkt6->addOption(opt_serverid);
1594 const Pkt6Ptr& advertise_pkt6) {
1597 const uint8_t arg_idx = 1;
1603 transid_offset, transid));
1606 boost::shared_ptr<LocalizedOption>
1609 pkt6->addOption(opt_elapsed_time);
1617 boost::shared_ptr<LocalizedOption>
1622 pkt6->addOption(opt_serverid);
1629 if (!opt_serverid_advertise) {
1631 <<
"in ADVERTISE message");
1633 boost::shared_ptr<LocalizedOption>
1636 opt_serverid_advertise->getData(),
1638 pkt6->addOption(opt_serverid);
1645 if (!opt_ia_na_advertise) {
1650 boost::shared_ptr<LocalizedOption>
1652 if (!opt_ia_na->valid()) {
1655 pkt6->addOption(opt_ia_na);
1658 if (!opt_serverid_advertise) {
1663 boost::shared_ptr<LocalizedOption>
1665 opt_serverid_advertise->getData(),
1667 pkt6->addOption(opt_serverid);
1671 if (!opt_clientid_advertise) {
1674 rand_offset -= (opt_clientid_advertise->len() - 1);
1676 boost::shared_ptr<LocalizedOption>
1678 opt_clientid_advertise->getData(),
1680 pkt6->addOption(opt_clientid);
1708 uint8_t randomized = 0;
1731 pkt6->addOption(elapsed);
1739 pkt6->addOption(Option::factory(Option::V6,
D6O_CLIENTID, duid));
1740 pkt6->addOption(Option::factory(Option::V6,
D6O_ORO));
1748 pkt6->addOption(Option::factory(Option::V6,
D6O_IA_NA));
1752 pkt6->addOption(Option::factory(Option::V6,
D6O_IA_PD));
1771 const bool preload ) {
1772 const int arg_idx = 0;
1779 transid_offset, transid));
1787 uint8_t randomized = 0;
1789 if (rand_offset > template_buf.size()) {
1793 pkt6->writeAt(rand_offset - randomized + 1,
1794 duid.end() - randomized, duid.end());
1817 if (iface == NULL) {
1820 pkt->setIface(iface->getName());
1824 pkt->setLocalPort(DHCP4_CLIENT_PORT);
1829 pkt->setRemotePort(DHCP4_SERVER_PORT);
1850 if (iface == NULL) {
1853 pkt->setIface(iface->getName());
1857 pkt->setLocalPort(DHCP6_CLIENT_PORT);
1862 pkt->setRemotePort(DHCP6_SERVER_PORT);
1883 pkt->addRelayInfo(relay_info);
1892 result.insert(result.end(), a.begin(), a.end());
1893 result.insert(result.end(), b.begin(), b.end());
1897static void mergeOptionIntoPacket(
Pkt4Ptr const& packet,
1899 uint16_t
const code(extra_option->getType());
1901 OptionPtr const& option(packet->getOption(code));
1906 packet->delOption(code);
1907 packet->addOption(boost::make_shared<Option>(
1909 concatenateBuffers(option->getData(),
1910 extra_option->getData())));
1918 packet->addOption(extra_option);
1927 for (
auto entry : extra_opts) {
1928 mergeOptionIntoPacket(pkt, entry.second);
1936 for (
auto entry : extra_opts) {
1937 pkt->addOption(entry.second);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown when an object can not be found.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
bool isV4() const
Convenience function to check for an IPv4 address.
isc::asiolink::IOAddress getAddress() const
Returns address contained within this option.
Class that represents IAPREFIX option in DHCPv6.
Forward declaration to OptionInt.
Universe
defines option universe DHCPv4 or DHCPv6
Represents DHCPv4 packet.
Represents a DHCPv6 packet.
Socket wrapper structure.
virtual dhcp::IfacePtr getIface()=0
See description of this method in PerfSocket class below.
unsigned int ifindex_
Interface index.
virtual bool send(const dhcp::Pkt4Ptr &pkt)=0
See description of this method in PerfSocket class below.
bool includes(const Type lease_type) const
Checks if lease type implies request for the address, prefix (or both) as specified by the function a...
bool testDiags(const char diag)
Find if diagnostic flag has been set.
std::string getRandRelayAddr()
Returns random relay address.
int getIncreaseElapsedTime() const
Returns increased elapsed time.
int getServerIdOffset() const
Returns template offset for server-ID.
std::string getWrapped() const
Returns wrapped command.
int getRenewRate() const
Returns a rate at which DHCPv6 Renew messages are sent.
uint8_t getIpVersion() const
Returns IP version.
std::vector< uint8_t > getDuidTemplate() const
Returns DUID template.
bool getAddrUnique() const
Returns address uniqueness value.
int getRate() const
Returns exchange rate.
std::string getCleanReportSeparator() const
Returns clean report separator.
bool isRapidCommit() const
Check if rapid commit option used.
bool checkMultiSubnet()
Check if multi subnet mode is enabled.
const isc::dhcp::OptionCollection & getExtraOpts() const
Returns extra options to be inserted.
bool isUseFirst() const
Check if server-ID to be taken from first package.
int getReportDelay() const
Returns delay between two performance reports.
std::vector< int > getRandomOffset() const
Returns template offsets for rnd.
int getRemotePort() const
Returns remote port number.
int getWaitForElapsedTime() const
Returns time to wait for elapsed time increase.
ExchangeMode
2-way (cmd line param -i) or 4-way exchanges
const MacAddrsVector & getMacsFromFile() const
Returns reference to a vector of MAC addresses read from a file.
std::vector< std::string > getTemplateFiles() const
Returns template file names.
std::vector< int > getTransactionIdOffset() const
brief Returns template offsets for xid.
std::vector< std::vector< uint8_t > > MacAddrsVector
A vector holding MAC addresses.
int getElapsedTimeOffset() const
Returns template offset for elapsed time.
std::string getServerName() const
Returns server name.
const isc::dhcp::OptionCollection & getRelayOpts(uint8_t encapsulation_level=1) const
Returns relay options to be inserted at given level of encapsulation.
std::vector< int > getNumRequests() const
Returns maximum number of exchanges.
LeaseType getLeaseType() const
\ brief Returns the type of lease being requested.
bool isUseRelayedV6() const
Check if generated DHCPv6 messages should appear as relayed.
int getExitWaitTime() const
Returns the time in microseconds to delay the program by.
uint32_t getClientsNum() const
Returns number of simulated clients.
bool isSeeded() const
Checks if seed provided.
uint32_t getSeed() const
Returns random seed.
ExchangeMode getExchangeMode() const
Returns packet exchange mode.
void printCommandLine() const
Print command line arguments.
int getCleanReport() const
Returns clean report mode.
std::vector< uint8_t > getMacTemplate() const
Returns MAC address template.
int getRequestedIpOffset() const
Returns template offset for requested IP.
static int malformed_pkts_
DHCP option at specific offset.
dhcp::PktPtr getPkt()
Get DHCP packet.
void updateRejLeases(const ExchangeType xchg_type)
Increase total number of rejected leases.
void printStats() const
Print statistics counters for all exchange types.
void printCustomCounters() const
Print names and values of custom counters.
void updateNonUniqueAddrNum(const ExchangeType xchg_type)
Increase total number of non unique addresses.
uint64_t getRcvdPacketsNum(const ExchangeType xchg_type) const
Return total number of received packets.
bool hasExchangeStats(const ExchangeType xchg_type) const
Check if the exchange type has been specified.
void printIntermediateStats(bool clean_report, std::string clean_sep) const
Print intermediate statistics.
boost::posix_time::time_period getTestPeriod() const
Get time period since the start of test.
void passSentPacket(const ExchangeType xchg_type, const dhcp::PktPtr &packet)
Adds new packet to the sent packets list.
dhcp::PktPtr passRcvdPacket(const ExchangeType xchg_type, const dhcp::PktPtr &packet)
Add new received packet and match with sent packet.
Sequential numbers generator class.
void saveFirstPacket(const dhcp::Pkt4Ptr &pkt)
Save the first DHCPv4 sent packet of the specified type.
void address6Uniqueness(const dhcp::Pkt6Ptr &pkt6, ExchangeType xchg_type)
Process received v6 addresses uniqueness.
static const uint8_t HW_ETHER_LEN
Length of the Ethernet HW address (MAC) in bytes.
bool waitToExit()
Delay the exit by a fixed given time to catch up to all exchanges that were already started.
std::map< uint8_t, dhcp::Pkt4Ptr > template_packets_v4_
First packets send.
bool sendMessageFromReply(const uint16_t msg_type)
Send DHCPv6 Renew or Release message.
void addExtraOpts(const dhcp::Pkt4Ptr &pkt4)
Inserts extra options specified by user.
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.
NumberGeneratorPtr macaddr_gen_
Numbers generator for MAC address.
int getRequestedIpOffset() const
Return requested ip offset in a packet.
boost::shared_ptr< NumberGenerator > NumberGeneratorPtr
The default generator pointer.
uint64_t sendMultipleMessages4(const uint32_t msg_type, const uint64_t msg_num)
Send number of DHCPREQUEST (renew) messages to a server.
bool validateIA(const dhcp::Pkt6Ptr &pkt6)
Process IA in received DHCPv6 packet.
dhcp::Pkt4Ptr createMessageFromAck(const uint16_t msg_type, const dhcp::Pkt4Ptr &ack)
Creates DHCPREQUEST from a DHCPACK message.
static bool interrupted_
Program interrupted flag.
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.
void setDefaults4(const dhcp::Pkt4Ptr &pkt)
Set default DHCPv4 packet parameters.
boost::posix_time::ptime exit_time_
Initialized at first exit condition with the time perfdhcp should exit.
CommandOptions & options_
Command options.
Receiver receiver_
Receiver used to receive DHCP traffic.
static std::string vector2Hex(const std::vector< uint8_t > &vec, const std::string &separator="")
Convert vector in hexadecimal string.
uint64_t sendMultipleMessages6(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.
void setDefaults6(const dhcp::Pkt6Ptr &pkt)
Set default DHCPv6 packet parameters.
boost::posix_time::ptime last_report_
Last intermediate report time.
bool haveAllPacketsBeenReceived() const
Checks if all expected packets were already received.
void cleanCachedPackets()
Removes cached DHCPv6 Reply packets every second.
void processReceivedPacket4(const dhcp::Pkt4Ptr &pkt4)
Process received DHCPv4 packet.
void sendRequest6(const dhcp::Pkt6Ptr &advertise_pkt6)
Send DHCPv6 REQUEST message.
TestControl(CommandOptions &options, BasePerfSocket &socket)
Default constructor.
static dhcp::OptionPtr factoryOptionRequestOption6(dhcp::Option::Universe u, uint16_t type, const dhcp::OptionBuffer &buf)
Factory function to create DHCPv6 ORO option.
void sendSolicit6(const bool preload=false)
Send DHCPv6 SOLICIT message.
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_
Template for 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_
Storage for reply messages.
void registerOptionFactories6() const
Register option factory functions for DHCPv6.
void sendPackets(const uint64_t packets_num, const bool preload=false)
Send number of packets to initiate new exchanges.
void registerOptionFactories() const
Register option factory functions for DHCPv4 or DHCPv6.
UniformRandomIntegerGenerator number_generator_
Generate uniformly distributed integers in range of [min, max].
std::vector< uint8_t > TemplateBuffer
Packet template buffer.
bool sendMessageFromAck(const uint16_t msg_type)
Send DHCPv4 renew (DHCPREQUEST).
void runWrapped(bool do_stop=false) const
Run wrapped command.
void processReceivedPacket6(const dhcp::Pkt6Ptr &pkt6)
Process received DHCPv6 packet.
uint32_t getElapsedTime(const T &pkt1, const T &pkt2)
Calculate elapsed time between two packets.
BasePerfSocket & socket_
Socket used for DHCP traffic.
void reset()
Resets internal state of the object.
void addUniqeAddr(const std::set< std::string > ¤t, ExchangeType xchg_type)
add unique address to already assigned list.
void address4Uniqueness(const dhcp::Pkt4Ptr &pkt4, ExchangeType xchg_type)
Process received v4 addresses uniqueness.
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.
static std::string byte2Hex(const uint8_t b)
Convert binary value to hex string.
void printTemplates() const
Print templates information.
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.
TemplateBufferCollection template_buffers_
Packet template buffers.
StatsMgr stats_mgr_
Statistics Manager.
void printStats() const
Print performance statistics.
PacketStorage< dhcp::Pkt4 > ack_storage_
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.
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.
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.
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.
void sendDiscover4(const bool preload=false)
Send DHCPv4 DISCOVER message.
dhcp::OptionPtr generateClientId(const dhcp::HWAddrPtr &hwaddr) const
Generate DHCPv4 client identifier from HW address.
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.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
size_t getLength() const
Return the length of data written in the buffer.
const void * getData() const
Return a pointer to the head of the data stored in the buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
@ DHO_DOMAIN_NAME_SERVERS
@ DHO_DHCP_SERVER_IDENTIFIER
@ DHO_DHCP_CLIENT_IDENTIFIER
@ DHO_DHCP_REQUESTED_ADDRESS
@ DHO_DHCP_PARAMETER_REQUEST_LIST
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
boost::shared_ptr< Option6IAPrefix > Option6IAPrefixPtr
Pointer to the Option6IAPrefix object.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
boost::shared_ptr< Option6IAAddr > Option6IAAddrPtr
A pointer to the isc::dhcp::Option6IAAddr object.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
@ HTYPE_ETHER
Ethernet 10Mbps.
boost::shared_ptr< Option > OptionPtr
boost::shared_ptr< PerfPkt4 > PerfPkt4Ptr
ExchangeType
DHCP packet exchange types.
@ SA
DHCPv6 SOLICIT-ADVERTISE.
@ RNA
DHCPv4 REQUEST-ACK (renewal)
@ RL
DHCPv6 RELEASE-REPLY.
@ DO
DHCPv4 DISCOVER-OFFER.
@ RR
DHCPv6 REQUEST-REPLY.
boost::shared_ptr< PerfPkt6 > PerfPkt6Ptr
Defines the logger used by the top-level component of kea-lfc.
structure that describes a single relay information
isc::dhcp::OptionCollection options_
options received from a specified relay, except relay-msg option
uint8_t msg_type_
message type (RELAY-FORW oro RELAY-REPL)
isc::asiolink::IOAddress linkaddr_
fixed field in relay-forw/relay-reply
uint8_t hop_count_
number of traversed relays (up to 32)
isc::asiolink::IOAddress peeraddr_
fixed field in relay-forw/relay-reply
isc::asiolink::IOAddress addr_