19 #include <boost/lexical_cast.hpp> 20 #include <boost/date_time/posix_time/posix_time.hpp> 44 CommandOptions::LeaseType::LeaseType()
54 return (lease_type == type_);
69 if (cmd_line_arg ==
"address-only") {
72 }
else if (cmd_line_arg ==
"prefix-only") {
75 }
else if (cmd_line_arg ==
"address-and-prefix") {
80 " must be one of the following: 'address-only' or" 89 return (
"address-only (IA_NA option added to the client's request)");
91 return (
"prefix-only (IA_PD option added to the client's request)");
93 return (
"address-and-prefix (Both IA_NA and IA_PD options added to the" 94 " client's request)");
97 " returning textual representation of the lease type");
105 uint8_t mac[6] = { 0x0, 0xC, 0x1, 0x2, 0x3, 0x4 };
109 double dt[2] = { 1., 1. };
120 clean_report_ =
false;
121 clean_report_separator_ =
"";
123 mac_template_.assign(mac, mac + 6);
124 duid_template_.clear();
126 addr_unique_ =
false;
127 mac_list_file_.clear();
129 relay_addr_list_file_.clear();
130 relay_addr_list_.clear();
131 multi_subnet_ =
false;
132 num_request_.clear();
135 wait_for_elapsed_time_ = -1;
136 increased_elapsed_time_ = -1;
138 drop_time_.assign(dt, dt + 2);
142 is_interface_ =
false;
149 rapid_commit_ =
false;
151 template_file_.clear();
159 server_name_.clear();
160 v6_relay_encapsulation_level_ = 0;
161 generateDuidTemplate();
163 if (std::thread::hardware_concurrency() == 1) {
164 single_thread_mode_ =
true;
166 single_thread_mode_ =
false;
210 bool help_or_version_mode = initialize(argc, argv, print_cmd_line);
211 if (!help_or_version_mode) {
214 return (help_or_version_mode);
220 CommandOptions::initialize(
int argc,
char** argv,
bool print_cmd_line) {
222 std::string drop_arg;
223 size_t percent_loc = 0;
224 double drop_percent = 0;
231 std::ostringstream stream;
232 stream <<
"perfdhcp";
233 int num_mac_list_files = 0;
234 int num_subnet_list_files = 0;
236 struct option long_options[] = {
237 {
"scenario", required_argument, 0, LONG_OPT_SCENARIO},
243 while((opt = getopt_long(argc, argv,
244 "huv46A:r:t:R:b:n:p:d:D:l:P:a:L:N:M:s:iBc1" 245 "J:T:X:O:o:E:S:I:x:W:w:e:f:F:g:C:y:Y:",
246 long_options, NULL)) != -1) {
247 stream <<
" -" <<
static_cast<char>(opt);
249 stream <<
" " << optarg;
261 v6_relay_encapsulation_level_ =
262 static_cast<uint8_t
>(positiveInteger(
"-A<encapsulation-level> must" 263 " be a positive integer"));
264 if (v6_relay_encapsulation_level_ != 1) {
274 check(ipversion_ == 6,
"IP version already set to 6");
279 check(ipversion_ == 4,
"IP version already set to 4");
284 check(base_.size() > 3,
"-b<value> already specified," 285 " unexpected occurrence of 5th -b<value>");
286 base_.push_back(optarg);
287 decodeBase(base_.back());
295 rapid_commit_ =
true;
299 clean_report_ =
true;
300 clean_report_separator_ = optarg;
304 check(drop_time_set_ > 1,
305 "maximum number of drops already specified, " 306 "unexpected 3rd occurrence of -d<value>");
308 drop_time_[drop_time_set_] =
309 boost::lexical_cast<
double>(optarg);
310 }
catch (
const boost::bad_lexical_cast&) {
312 "value of drop time: -d<value>" 313 " must be positive number");
315 check(drop_time_[drop_time_set_] <= 0.,
316 "drop-time must be a positive number");
317 drop_time_set_ =
true;
321 drop_arg = std::string(optarg);
322 percent_loc = drop_arg.find(
'%');
323 check(max_pdrop_.size() > 1 || max_drop_.size() > 1,
324 "values of maximum drops: -D<value> already " 325 "specified, unexpected 3rd occurrence of -D<value>");
326 if ((percent_loc) != std::string::npos) {
329 boost::lexical_cast<
double>(drop_arg.substr(0, percent_loc));
330 }
catch (
const boost::bad_lexical_cast&) {
332 "value of drop percentage: -D<value%>" 335 check((drop_percent <= 0) || (drop_percent >= 100),
336 "value of drop percentage: -D<value%> must be 0..100");
337 max_pdrop_.push_back(drop_percent);
339 num_drops = positiveInteger(
"value of max drops number:" 340 " -D<value> must be a positive integer");
341 max_drop_.push_back(num_drops);
350 elp_offset_ = nonNegativeInteger(
"value of time-offset: -E<value>" 351 " must not be a negative integer");
355 renew_rate_ = positiveInteger(
"value of the renew rate: -f<renew-rate>" 356 " must be a positive integer");
360 release_rate_ = positiveInteger(
"value of the release rate:" 361 " -F<release-rate> must be a" 362 " positive integer");
366 auto optarg_text = std::string(optarg);
367 if (optarg_text ==
"single") {
368 single_thread_mode_ =
true;
369 }
else if (optarg_text ==
"multi") {
370 single_thread_mode_ =
false;
372 isc_throw(
InvalidParameter,
"value of thread mode (-g) '" << optarg <<
"' is wrong - should be '-g single' or '-g multi'");
381 exchange_mode_ =
DO_SA;
385 rip_offset_ = positiveInteger(
"value of ip address offset:" 386 " -I<value> must be a" 387 " positive integer");
391 check(num_subnet_list_files >= 1,
"only one -J option can be specified");
392 num_subnet_list_files++;
393 relay_addr_list_file_ = std::string(optarg);
398 localname_ = std::string(optarg);
403 local_port_ = nonNegativeInteger(
"value of local port:" 404 " -L<value> must not be a" 405 " negative integer");
407 static_cast<int>(std::numeric_limits<uint16_t>::max()),
408 "local-port must be lower than " +
409 boost::lexical_cast<std::string>(std::numeric_limits<uint16_t>::max()));
413 remote_port_ = nonNegativeInteger(
"value of remote port:" 414 " -L<value> must not be a" 415 " negative integer");
417 static_cast<int>(std::numeric_limits<uint16_t>::max()),
418 "remote-port must be lower than " +
419 boost::lexical_cast<std::string>(std::numeric_limits<uint16_t>::max()));
423 check(num_mac_list_files >= 1,
"only one -M option can be specified");
424 num_mac_list_files++;
425 mac_list_file_ = std::string(optarg);
430 exit_wait_time_ = nonNegativeInteger(
"value of exist wait time: " 431 "-W<value> must not be a " 436 num_req = positiveInteger(
"value of num-request:" 437 " -n<value> must be a positive integer");
438 if (num_request_.size() >= 2) {
440 "value of maximum number of requests: -n<value> " 441 "already specified, unexpected 3rd occurrence" 444 num_request_.push_back(num_req);
448 if (rnd_offset_.size() < 2) {
449 offset_arg = positiveInteger(
"value of random offset: " 450 "-O<value> must be greater than 3");
453 "random offsets already specified," 454 " unexpected 3rd occurrence of -O<value>");
456 check(offset_arg < 3,
"value of random random-offset:" 457 " -O<value> must be greater than 3 ");
458 rnd_offset_.push_back(offset_arg);
463 check( (ipversion_ != 4) && (ipversion_ != 6),
464 "-4 or -6 must be explicitly specified before -o is used.");
467 std::string opt_text = std::string(optarg);
468 size_t coma_loc = opt_text.find(
',');
469 check(coma_loc == std::string::npos,
470 "-o option must provide option code, a coma and hexstring for" 471 " the option content, e.g. -o60,646f63736973 for sending option" 472 " 60 (class-id) with the value 'docsis'");
477 code = boost::lexical_cast<
int>(opt_text.substr(0,coma_loc));
478 check(code <= 0,
"Option code can't be negative");
479 }
catch (
const boost::bad_lexical_cast&) {
481 "-o option, expected format: -o<integer>,<hexstring>");
485 opt_text = opt_text.substr(coma_loc + 1);
486 std::vector<uint8_t> bin;
497 extra_opts_.insert(make_pair(code, opt));
501 period_ = positiveInteger(
"value of test period:" 502 " -p<value> must be a positive integer");
506 preload_ = nonNegativeInteger(
"number of preload packets:" 507 " -P<value> must not be " 508 "a negative integer");
512 rate_ = positiveInteger(
"value of rate:" 513 " -r<value> must be a positive integer");
521 seed_ =
static_cast<unsigned int> 522 (nonNegativeInteger(
"value of seed:" 523 " -s <seed> must be non-negative integer"));
524 seeded_ = seed_ > 0 ? true :
false;
528 sid_offset_ = positiveInteger(
"value of server id offset:" 529 " -S<value> must be a" 530 " positive integer");
534 report_delay_ = positiveInteger(
"value of report delay:" 535 " -t<value> must be a" 536 " positive integer");
540 if (template_file_.size() < 2) {
541 sarg = nonEmptyString(
"template file name not specified," 542 " expected -T<filename>");
543 template_file_.push_back(sarg);
546 "template files are already specified," 547 " unexpected 3rd -T<filename> occurrence");
556 wrapped_ = nonEmptyString(
"command for wrapped mode:" 557 " -w<command> must be specified");
561 diags_ = nonEmptyString(
"value of diagnostics selectors:" 562 " -x<value> must be specified");
566 if (xid_offset_.size() < 2) {
567 offset_arg = positiveInteger(
"value of transaction id:" 568 " -X<value> must be a" 569 " positive integer");
572 "transaction ids already specified," 573 " unexpected 3rd -X<value> occurrence");
575 xid_offset_.push_back(offset_arg);
579 wait_for_elapsed_time_ = nonNegativeInteger(
"value of time:" 580 " -Y<value> must be a non negative integer");
584 increased_elapsed_time_ = positiveInteger(
"value of time:" 585 " -y<value> must be a positive integer");
589 auto optarg_text = std::string(optarg);
590 if (optarg_text ==
"basic") {
592 }
else if (optarg_text ==
"avalanche") {
606 if (ipversion_ == 0) {
615 if (template_file_.size() > 1) {
616 if (xid_offset_.size() == 1) {
617 xid_offset_.push_back(xid_offset_[0]);
619 if (rnd_offset_.size() == 1) {
620 rnd_offset_.push_back(rnd_offset_[0]);
628 check(optind < argc -1,
"extra arguments?");
629 if (optind == argc - 1) {
630 server_name_ = argv[optind];
631 stream <<
" " << server_name_;
633 if ((ipversion_ == 4) && (server_name_.compare(
"all") == 0)) {
637 }
else if ((ipversion_ == 6) && (server_name_.compare(
"all") == 0)) {
639 }
else if ((ipversion_ == 6) &&
640 (server_name_.compare(
"servers") == 0)) {
645 if (print_cmd_line) {
646 std::cout <<
"Running: " << stream.str() << std::endl;
650 std::cout <<
"Scenario: basic." << std::endl;
652 std::cout <<
"Scenario: avalanche." << std::endl;
656 std::cout <<
"Multi-thread mode enabled." << std::endl;
661 if (!localname_.empty()) {
662 if (server_name_.empty()) {
663 if (is_interface_ && (ipversion_ == 4)) {
666 }
else if (is_interface_ && (ipversion_ == 6)) {
671 if (server_name_.empty()) {
673 "without an interface, server is required");
678 if (duid_template_.empty()) {
679 generateDuidTemplate();
685 CommandOptions::initClientsNum() {
686 const std::string errmsg =
687 "value of -R <value> must be non-negative integer";
694 long long clients_num = boost::lexical_cast<
long long>(optarg);
695 check(clients_num < 0, errmsg);
696 clients_num_ = boost::lexical_cast<uint32_t>(optarg);
697 }
catch (
const boost::bad_lexical_cast&) {
703 CommandOptions::initIsInterface() {
704 is_interface_ =
false;
705 if (!localname_.empty()) {
707 if (iface_mgr.
getIface(localname_) != NULL) {
708 is_interface_ =
true;
714 CommandOptions::decodeBase(
const std::string& base) {
716 boost::algorithm::to_lower(b);
719 if ((b.substr(0, 4) ==
"mac=") || (b.substr(0, 6) ==
"ether=")) {
721 }
else if (b.substr(0, 5) ==
"duid=") {
725 "base value not provided as -b<value>," 726 " expected -b mac=<mac> or -b duid=<duid>");
731 CommandOptions::decodeMacBase(
const std::string& base) {
733 size_t found = base.find(
'=');
734 static const char* errmsg =
"expected -b<base> format for" 735 " mac address is -b mac=00::0C::01::02::03::04 or" 736 " -b mac=00:0C:01:02:03:04";
737 check(found == std::string::npos, errmsg);
740 std::istringstream s1(base.substr(found + 1));
742 mac_template_.clear();
744 while (std::getline(s1, token,
':')) {
746 if (token.length() > 0) {
750 ui = convertHexString(token);
753 "invalid characters in MAC provided");
757 mac_template_.push_back(ui);
761 check(mac_template_.size() != 6, errmsg);
765 CommandOptions::decodeDuid(
const std::string& base) {
767 std::vector<uint8_t> duid_template;
768 size_t found = base.find(
'=');
769 check(found == std::string::npos,
"expected -b<base>" 770 " format for duid is -b duid=<duid>");
771 std::string b = base.substr(found + 1);
774 check(b.length() & 1,
"odd number of hexadecimal digits in duid");
775 check(b.length() > 128,
"duid too large");
776 check(b.length() == 0,
"no duid specified");
779 for (
size_t i = 0; i < b.length(); i += 2) {
783 ui = convertHexString(b.substr(i, 2));
786 "invalid characters in DUID provided," 787 " expected hex digits");
789 duid_template.push_back(static_cast<uint8_t>(ui));
794 check(duid_template.size() < 6,
"DUID must be at least 6 octets long");
796 std::swap(duid_template, duid_template_);
800 CommandOptions::generateDuidTemplate() {
805 duid_template_.clear();
806 const uint8_t duid_template_len = 14;
807 duid_template_.resize(duid_template_len);
811 duid_template_[2] = HWTYPE_ETHERNET >> 8;
812 duid_template_[3] = HWTYPE_ETHERNET & 0xff;
817 ptime now = microsec_clock::universal_time();
818 ptime duid_epoch(from_iso_string(
"20000101T000000"));
819 time_period period(duid_epoch, now);
820 uint32_t duration_sec = htonl(period.length().total_seconds());
821 memcpy(&duid_template_[4], &duration_sec, 4);
826 memcpy(&duid_template_[8], &mac_template_[0], 6);
830 CommandOptions::convertHexString(
const std::string& text)
const {
833 for (
size_t i = 0; i < text.length(); ++i) {
834 if (!std::isxdigit(text[i])) {
836 "The following digit: " << text[i] <<
" in " 837 << text <<
"is not hexadecimal");
841 std::istringstream text_stream(text);
842 text_stream >> std::hex >> ui >> std::dec;
846 " two hex digits to byte");
851 bool CommandOptions::validateIP(
const std::string& line) {
861 relay_addr_list_.push_back(line);
862 multi_subnet_ =
true;
866 void CommandOptions::loadRelayAddr() {
868 std::ifstream infile(relay_addr_list_file_.c_str());
870 while (std::getline(infile, line)) {
873 tmp <<
"invalid address or wrong address version in line: " << cnt;
874 check(validateIP(line), tmp.str());
876 check(cnt == 0,
"file with addresses is empty!");
879 void CommandOptions::loadMacs() {
881 std::ifstream infile(mac_list_file_.c_str());
883 while (std::getline(infile, line)) {
886 tmp <<
"invalid mac in input line " << cnt;
888 check(decodeMacString(line), tmp.str());
892 bool CommandOptions::decodeMacString(
const std::string& line) {
894 std::istringstream s(line);
896 std::vector<uint8_t> mac;
897 while(std::getline(s, token,
':')) {
899 if (token.length() > 0) {
903 ui = convertHexString(token);
911 mac_list_.push_back(mac);
916 CommandOptions::validate() {
918 "-B is not compatible with IPv6 (-6)");
920 "-6 (IPv6) must be set to use -c");
922 "Can't use -4 with -A, it's a V6 only option.");
924 "second -n<num-request> is not compatible with -i");
926 "-6 option must be used if lease type other than '-e address-only'" 930 "template files may be only used with '-e address-only'");
932 "second -d<drop-time> is not compatible with -i");
935 "second -D<max-drop> is not compatible with -i");
937 "-1 is not compatible with -i");
939 "second -T<template-file> is not compatible with -i");
941 "second -X<xid-offset> is not compatible with -i");
943 "second -O<random-offset is not compatible with -i");
945 "-E<time-offset> is not compatible with -i");
947 "-S<srvid-offset> is not compatible with -i");
949 "-I<ip-offset> is not compatible with -i");
951 "-f<renew-rate> is not compatible with -i");
953 "-F<release-rate> is not compatible with -i");
955 "-i must be set to use -c");
957 "The sum of Renew rate (-f<renew-rate>) and Release rate" 958 " (-F<release-rate>) must not be greater than the exchange" 959 " rate specified as -r<rate>");
961 "Renew rate specified as -f<renew-rate> must not be specified" 962 " when -r<rate> parameter is not specified");
964 "Release rate specified as -F<release-rate> must not be specified" 965 " when -r<rate> parameter is not specified");
967 "-T<template-file> must be set to use -X<xid-offset>");
969 "-T<template-file> must be set to use -O<random-offset>");
971 "second/request -T<template-file> must be set to use -E<time-offset>");
973 "second/request -T<template-file> must be set to " 974 "use -S<srvid-offset>");
976 "second/request -T<template-file> must be set to " 977 "use -I<ip-offset>");
979 "Can't use -b with -M option");
981 "Option -y can't be used without -Y");
983 "Option -Y can't be used without -y");
984 auto nthreads = std::thread::hardware_concurrency();
986 std::cout <<
"WARNING: Currently system can run only 1 thread in parallel." << std::endl
987 <<
"WARNING: Better results are achieved when run in single-threaded mode." << std::endl
988 <<
"WARNING: To switch use -g single option." << std::endl;
990 std::cout <<
"WARNING: Currently system can run more than 1 thread in parallel." << std::endl
991 <<
"WARNING: Better results are achieved when run in multi-threaded mode." << std::endl
992 <<
"WARNING: To switch use -g multi option." << std::endl;
997 "in case of avalanche scenario number\nof clients must be specified" 998 " using -R option explicitly");
1001 double dt[2] = { 1000.0, 1000.0 };
1002 drop_time_.assign(dt, dt + 2);
1003 if (drop_time_set_) {
1004 std::cout <<
"INFO: in avalanche scenario drop time is ignored" << std::endl;
1010 CommandOptions::check(
bool condition,
const std::string& errmsg)
const {
1013 std::ostringstream stream;
1014 stream << errmsg <<
"\n";
1021 CommandOptions::positiveInteger(
const std::string& errmsg)
const {
1023 int value = boost::lexical_cast<
int>(optarg);
1024 check(value <= 0, errmsg);
1026 }
catch (
const boost::bad_lexical_cast&) {
1032 CommandOptions::nonNegativeInteger(
const std::string& errmsg)
const {
1034 int value = boost::lexical_cast<
int>(optarg);
1035 check(value < 0, errmsg);
1037 }
catch (
const boost::bad_lexical_cast&) {
1043 CommandOptions::nonEmptyString(
const std::string& errmsg)
const {
1044 std::string sarg = optarg;
1045 if (sarg.length() == 0) {
1052 CommandOptions::initLeaseType() {
1053 std::string lease_type_arg = optarg;
1054 lease_type_.fromCommandLine(lease_type_arg);
1059 std::cout <<
"IPv" <<
static_cast<int>(ipversion_) << std::endl;
1060 if (exchange_mode_ ==
DO_SA) {
1061 if (ipversion_ == 4) {
1062 std::cout <<
"DISCOVER-OFFER only" << std::endl;
1064 std::cout <<
"SOLICIT-ADVERTISE only" << std::endl;
1069 std::cout <<
"rate[1/s]=" << rate_ << std::endl;
1072 std::cout <<
"renew-rate[1/s]=" <<
getRenewRate() << std::endl;
1075 std::cout <<
"release-rate[1/s]=" <<
getReleaseRate() << std::endl;
1077 if (report_delay_ != 0) {
1078 std::cout <<
"report[s]=" << report_delay_ << std::endl;
1080 if (clients_num_ != 0) {
1081 std::cout <<
"clients=" << clients_num_ << std::endl;
1083 for (
size_t i = 0; i < base_.size(); ++i) {
1084 std::cout <<
"base[" << i <<
"]=" << base_[i] << std::endl;
1086 for (
size_t i = 0; i < num_request_.size(); ++i) {
1087 std::cout <<
"num-request[" << i <<
"]=" << num_request_[i] << std::endl;
1090 std::cout <<
"test-period=" << period_ << std::endl;
1092 for (
size_t i = 0; i < drop_time_.size(); ++i) {
1093 std::cout <<
"drop-time[" << i <<
"]=" << drop_time_[i] << std::endl;
1095 for (
size_t i = 0; i < max_drop_.size(); ++i) {
1096 std::cout <<
"max-drop{" << i <<
"]=" << max_drop_[i] << std::endl;
1098 for (
size_t i = 0; i < max_pdrop_.size(); ++i) {
1099 std::cout <<
"max-pdrop{" << i <<
"]=" << max_pdrop_[i] << std::endl;
1101 if (preload_ != 0) {
1102 std::cout <<
"preload=" << preload_ << std::endl;
1105 std::cout <<
"local-port=" << local_port_ << std::endl;
1108 std::cout <<
"remote-port=" << remote_port_ << std::endl;
1111 std::cout <<
"seed=" << seed_ << std::endl;
1114 std::cout <<
"broadcast" << std::endl;
1116 if (rapid_commit_) {
1117 std::cout <<
"rapid-commit" << std::endl;
1120 std::cout <<
"use-first" << std::endl;
1122 if (!mac_list_file_.empty()) {
1123 std::cout <<
"mac-list-file=" << mac_list_file_ << std::endl;
1125 for (
size_t i = 0; i < template_file_.size(); ++i) {
1126 std::cout <<
"template-file[" << i <<
"]=" << template_file_[i] << std::endl;
1128 for (
size_t i = 0; i < xid_offset_.size(); ++i) {
1129 std::cout <<
"xid-offset[" << i <<
"]=" << xid_offset_[i] << std::endl;
1131 if (elp_offset_ != 0) {
1132 std::cout <<
"elp-offset=" << elp_offset_ << std::endl;
1134 for (
size_t i = 0; i < rnd_offset_.size(); ++i) {
1135 std::cout <<
"rnd-offset[" << i <<
"]=" << rnd_offset_[i] << std::endl;
1137 if (sid_offset_ != 0) {
1138 std::cout <<
"sid-offset=" << sid_offset_ << std::endl;
1140 if (rip_offset_ != 0) {
1141 std::cout <<
"rip-offset=" << rip_offset_ << std::endl;
1143 if (!diags_.empty()) {
1144 std::cout <<
"diagnostic-selectors=" << diags_ << std::endl;
1146 if (!wrapped_.empty()) {
1147 std::cout <<
"wrapped=" << wrapped_ << std::endl;
1149 if (!localname_.empty()) {
1150 if (is_interface_) {
1151 std::cout <<
"interface=" << localname_ << std::endl;
1153 std::cout <<
"local-addr=" << localname_ << std::endl;
1156 if (!server_name_.empty()) {
1157 std::cout <<
"server=" << server_name_ << std::endl;
1159 if (single_thread_mode_) {
1160 std::cout <<
"single-thread-mode" << std::endl;
1162 std::cout <<
"multi-thread-mode" << std::endl;
1169 R
"(perfdhcp [-1] [-4 | -6] [-A encapsulation-level] [-b base] [-B] [-c] 1170 [-C separator] [-d drop-time] [-D max-drop] [-e lease-type] 1171 [-E time-offset] [-f renew-rate] [-F release-rate] [-g thread-mode] 1172 [-h] [-i] [-I ip-offset] [-J remote-address-list-file] 1173 [-l local-address|interface] [-L local-port] [-M mac-list-file] 1174 [-n num-request] [-N remote-port] [-O random-offset] 1175 [-o code,hexstring] [-p test-period] [-P preload] [-r rate] 1176 [-R num-clients] [-s seed] [-S srvid-offset] [--scenario name] 1177 [-t report] [-T template-file] [-u] [-v] [-W exit-wait-time] 1178 [-w script_name] [-x diagnostic-selector] [-X xid-offset] [server] 1180 The [server] argument is the name/address of the DHCP server to 1181 contact. For DHCPv4 operation, exchanges are initiated by 1182 transmitting a DHCP DISCOVER to this address. 1184 For DHCPv6 operation, exchanges are initiated by transmitting a DHCP 1185 SOLICIT to this address. In the DHCPv6 case, the special name 'all' 1186 can be used to refer to All_DHCP_Relay_Agents_and_Servers (the 1187 multicast address FF02::1:2), or the special name 'servers' to refer 1188 to All_DHCP_Servers (the multicast address FF05::1:3). The [server] 1189 argument is optional only in the case that -l is used to specify an 1190 interface, in which case [server] defaults to 'all'. 1192 The default is to perform a single 4-way exchange, effectively pinging 1194 The -r option is used to set up a performance test, without 1195 it exchanges are initiated as fast as possible. 1196 The other scenario is an avalanche which is selected by 1197 --scenario avalanche. It first sends as many Discovery or Solicit 1198 messages as request in -R option then back off mechanism is used for 1199 each simulated client until all requests are answered. At the end 1200 time of whole scenario is reported. 1203 -1: Take the server-ID option from the first received message. 1204 -4: DHCPv4 operation (default). This is incompatible with the -6 option. 1205 -6: DHCPv6 operation. This is incompatible with the -4 option. 1206 -b<base>: The base mac, duid, IP, etc, used to simulate different 1207 clients. This can be specified multiple times, each instance is 1208 in the <type>=<value> form, for instance: 1209 (and default) mac=00:0c:01:02:03:04. 1210 -d<drop-time>: Specify the time after which a request is treated as 1211 having been lost. The value is given in seconds and may contain a 1212 fractional component. The default is 1 second. 1213 -e<lease-type>: A type of lease being requested from the server. It 1214 may be one of the following: address-only, prefix-only or 1215 address-and-prefix. The address-only indicates that the regular 1216 address (v4 or v6) will be requested. The prefix-only indicates 1217 that the IPv6 prefix will be requested. The address-and-prefix 1218 indicates that both IPv6 address and prefix will be requested. 1219 The '-e prefix-only' and -'e address-and-prefix' must not be 1221 -E<time-offset>: Offset of the (DHCPv4) secs field / (DHCPv6) 1222 elapsed-time option in the (second/request) template. 1223 The value 0 disables it. 1224 -F<release-rate>: Rate at which Release requests are sent to 1225 a server. This value is only valid when used in conjunction with 1226 the exchange rate (given by -r<rate>). Furthermore the sum of 1227 this value and the renew-rate (given by -f<rate>) must be equal 1228 to or less than the exchange rate. 1229 -f<renew-rate>: Rate at which DHCPv4 or DHCPv6 renew requests are sent 1230 to a server. This value is only valid when used in conjunction 1231 with the exchange rate (given by -r<rate>). Furthermore the sum of 1232 this value and the release-rate (given by -F<rate>) must be equal 1233 to or less than the exchange rate. 1234 -g<thread-mode>: 'single' or 'multi'. In multi-thread mode packets 1235 are received in separate thread. This allows better utilisation of CPUs. 1236 If more than 1 CPU is present then multi-thread mode is the default, 1237 otherwise single-thread is the default. 1238 -h: Print this help. 1239 -i: Do only the initial part of an exchange: DO or SA, depending on 1240 whether -6 is given. 1241 -I<ip-offset>: Offset of the (DHCPv4) IP address in the requested-IP 1242 option / (DHCPv6) IA_NA option in the (second/request) template. 1243 -J<remote-address-list-file>: Text file that include multiple addresses. 1244 If provided perfdhcp will choose randomly one of addresses for each 1246 -l<local-addr|interface>: For DHCPv4 operation, specify the local 1247 hostname/address to use when communicating with the server. By 1248 default, the interface address through which traffic would 1249 normally be routed to the server is used. 1250 For DHCPv6 operation, specify the name of the network interface 1251 via which exchanges are initiated. 1252 -L<local-port>: Specify the local port to use 1253 (the value 0 means to use the default). 1254 -M<mac-list-file>: A text file containing a list of MAC addresses, 1255 one per line. If provided, a MAC address will be chosen randomly 1256 from this list for every new exchange. In the DHCPv6 case, MAC 1257 addresses are used to generate DUID-LLs. This parameter must not be 1258 used in conjunction with the -b parameter. 1259 -N<remote-port>: Specify the remote port to use 1260 (the value 0 means to use the default). 1261 -o<code,hexstring>: Send custom option with the specified code and the 1262 specified buffer in hexstring format. 1263 -O<random-offset>: Offset of the last octet to randomize in the template. 1264 -P<preload>: Initiate first <preload> exchanges back to back at startup. 1265 -r<rate>: Initiate <rate> DORA/SARR (or if -i is given, DO/SA) 1266 exchanges per second. A periodic report is generated showing the 1267 number of exchanges which were not completed, as well as the 1268 average response latency. The program continues until 1269 interrupted, at which point a final report is generated. 1270 -R<range>: Specify how many different clients are used. With 1 1271 (the default), all requests seem to come from the same client. 1272 -s<seed>: Specify the seed for randomization, making it repeatable. 1273 --scenario <name>: where name is 'basic' (default) or 'avalanche'. 1274 -S<srvid-offset>: Offset of the server-ID option in the 1275 (second/request) template. 1276 -T<template-file>: The name of a file containing the template to use 1277 as a stream of hexadecimal digits. 1278 -u: Enable checking address uniqueness. Lease valid lifetime should not be 1279 shorter than test duration and clients should not request address more than 1280 once without releasing it first. 1281 -v: Report the version number of this program. 1282 -W<time>: Specifies exit-wait-time parameter, that makes perfdhcp wait 1283 for <time> us after an exit condition has been met to receive all 1284 packets without sending any new packets. Expressed in microseconds. 1285 -w<wrapped>: Command to call with start/stop at the beginning/end of 1287 -x<diagnostic-selector>: Include extended diagnostics in the output. 1288 <diagnostic-selector> is a string of single-keywords specifying 1289 the operations for which verbose output is desired. The selector 1291 * 'a': print the decoded command line arguments 1292 * 'e': print the exit reason 1293 * 'i': print rate processing details 1294 * 'l': print received leases 1295 * 's': print first server-id 1296 * 't': when finished, print timers of all successful exchanges 1297 * 'T': when finished, print templates 1298 -X<xid-offset>: Transaction ID (aka. xid) offset in the template. 1299 -Y<time>: time in seconds after which perfdhcp will start sending 1300 messages with increased elapsed time option. 1301 -y<time>: period of time in seconds in which perfdhcp will be sending 1302 messages with increased elapsed time option. 1303 DHCPv4 only options: 1304 -B: Force broadcast handling. 1306 DHCPv6 only options: 1307 -c: Add a rapid commit option (exchanges will be SA). 1308 -A<encapsulation-level>: Specifies that relayed traffic must be 1309 generated. The argument specifies the level of encapsulation, i.e. 1310 how many relay agents are simulated. Currently the only supported 1311 <encapsulation-level> value is 1, which means that the generated 1312 traffic is an equivalent of the traffic passing through a single 1315 The remaining options are typically used in conjunction with -r: 1317 -D<max-drop>: Abort the test immediately if max-drop requests have 1318 been dropped. max-drop must be a positive integer. If max-drop 1319 includes the suffix '%', it specifies a maximum percentage of 1320 requests that may be dropped before abort. In this case, testing 1321 of the threshold begins after 10 requests have been expected to 1323 -n<num-request>: Initiate <num-request> transactions. No report is 1324 generated until all transactions have been initiated/waited-for, 1325 after which a report is generated and the program terminates. 1326 -p<test-period>: Send requests for the given test period, which is 1327 specified in the same manner as -d. This can be used as an 1328 alternative to -n, or both options can be given, in which case the 1329 testing is completed when either limit is reached. 1330 -t<report>: Delay in seconds between two periodic reports. 1331 -C<separator>: Output reduced, an argument is a separator for periodic 1332 (-t) reports generated in easy parsable mode. Data output won't be 1333 changed, remain identical as in -t option. 1336 - tooshort: received a too short message 1337 - orphans: received a message which doesn't match an exchange 1338 (duplicate, late or not related) 1339 - locallimit: reached to local system limits when sending a message. 1343 0 on complete success. 1344 1 for a general error. 1345 2 if an error is found in the command line arguments. 1346 3 if there are no general failures in operation, but one or more 1347 exchanges are not successfully completed. 1353 std::cout <<
"VERSION: " << VERSION << std::endl;
IfacePtr getIface(int ifindex)
Returns interface specified interface index.
int getCleanReport() const
Returns clean report mode.
bool parse(int argc, char **const argv, bool print_cmd_line=false)
Parse command line.
bool isUseRelayedV6() const
Check if generated DHCPv6 messages should appear as relayed.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
const char *const * perfdhcp_config_report
link-layer + time, see RFC3315, section 11.2
void set(const Type lease_type)
Sets the lease type code.
#define DHCP_IPV4_BROADCAST_ADDRESS
int getServerIdOffset() const
Returns template offset for server-ID.
boost::shared_ptr< Option > OptionPtr
bool is(const Type lease_type) const
Checks if lease type has the specified code.
bool isUseFirst() const
Check if server-ID to be taken from first package.
Handles network interfaces, transmission and reception.
std::vector< std::string > getTemplateFiles() const
Returns template file names.
uint8_t getIpVersion() const
Returns IP version.
ExchangeMode getExchangeMode() const
Returns packet exchange mode.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void fromCommandLine(const std::string &cmd_line_arg)
Sets the lease type from the command line argument.
#define ALL_DHCP_RELAY_AGENTS_AND_SERVERS
bool isBroadcast() const
Checks if broadcast address is to be used.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void version() const
Print program version.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
static void usage()
Print usage.
const int LONG_OPT_SCENARIO
std::vector< int > getTransactionIdOffset() const
brief Returns template offsets for xid.
void printCommandLine() const
Print command line arguments.
bool isSingleThreaded() const
Check if single-threaded mode is enabled.
LeaseType getLeaseType() const
\ brief Returns the type of lease being requested.
std::vector< int > getRandomOffset() const
Returns template offsets for rnd.
int getReleaseRate() const
Returns a rate at which DHCPv6 Release messages are sent.
void decodeHex(const string &input, vector< uint8_t > &result)
Decode a text encoded in the base16 ('hex') format into the original data.
A generic exception that is thrown when an unexpected error condition occurs.
std::vector< double > getDropTime() const
Returns drop time.
std::string toText() const
Return textual representation of the lease type.
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 isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
int getLocalPort() const
Returns local port number.
Defines the logger used by the top-level component of kea-lfc.
const char *const config_report[]
int getElapsedTimeOffset() const
Returns template offset for elapsed time.
void reset()
Reset to defaults.
std::vector< int > getMaxDrop() const
Returns maximum drops number.
int getRemotePort() const
Returns remote port number.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
std::vector< int > getNumRequests() const
Returns maximum number of exchanges.
int getRate() const
Returns exchange rate.
An exception that is thrown if an error occurs within the IO module.
int getWaitForElapsedTime() const
Returns time to wait for elapsed time increase.
std::vector< double > getMaxDropPercentage() const
Returns maximal percentage of drops.
int getIncreaseElapsedTime() const
Returns increased elapsed time.
The IOAddress class represents an IP addresses (version agnostic)
std::string getMacListFile() const
Returns location of the file containing list of MAC addresses.
int getRequestedIpOffset() const
Returns template offset for requested IP.
bool isRapidCommit() const
Check if rapid commit option used.
int getRenewRate() const
Returns a rate at which DHCPv6 Renew messages are sent.
uint32_t getClientsNum() const
Returns number of simulated clients.