command_options.cc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <stdint.h>
  17. #include <unistd.h>
  18. #include <boost/algorithm/string.hpp>
  19. #include <boost/foreach.hpp>
  20. #include <boost/lexical_cast.hpp>
  21. #include "exceptions/exceptions.h"
  22. #include "command_options.h"
  23. using namespace std;
  24. using namespace isc;
  25. namespace isc {
  26. namespace perfdhcp {
  27. CommandOptions&
  28. CommandOptions::instance() {
  29. static CommandOptions options;
  30. return (options);
  31. }
  32. void
  33. CommandOptions::reset() {
  34. // Default mac address used in DHCP messages
  35. // if -b mac=<mac-address> was not specified
  36. uint8_t mac[6] = { 0x0, 0xC, 0x1, 0x2, 0x3, 0x4 };
  37. // Default packet drop time if -D<drop-time> parameter
  38. // was not specified
  39. double dt[2] = { 1., 1. };
  40. // We don't use constructor initialization list because we
  41. // will need to reset all members many times to perform unit tests
  42. ipversion_ = 0;
  43. exchange_mode_ = DORA_SARR;
  44. rate_ = 0;
  45. report_delay_ = 0;
  46. clients_num_ = 0;
  47. mac_prefix_.assign(mac, mac + 6);
  48. base_.resize(0);
  49. num_request_.resize(0);
  50. period_ = 0;
  51. drop_time_set_ = 0;
  52. drop_time_.assign(dt, dt + 2);
  53. max_drop_.clear();
  54. max_pdrop_.clear();
  55. localname_.clear();
  56. is_interface_ = false;
  57. preload_ = 0;
  58. aggressivity_ = 1;
  59. local_port_ = 0;
  60. seeded_ = false;
  61. seed_ = 0;
  62. broadcast_ = false;
  63. rapid_commit_ = false;
  64. use_first_ = false;
  65. template_file_.clear();
  66. rnd_offset_.clear();
  67. xid_offset_.clear();
  68. elp_offset_ = -1;
  69. sid_offset_ = -1;
  70. rip_offset_ = -1;
  71. diags_.clear();
  72. wrapped_.clear();
  73. server_name_.clear();
  74. }
  75. void
  76. CommandOptions::parse(int argc, char** const argv) {
  77. // Reset internal variables used by getopt
  78. // to eliminate undefined behavior when
  79. // parsing different command lines multiple times
  80. optind = 1;
  81. opterr = 0;
  82. // Reset values of class members
  83. reset();
  84. initialize(argc, argv);
  85. validate();
  86. }
  87. void
  88. CommandOptions::initialize(int argc, char** argv) {
  89. char opt = 0; // Subsequent options returned by getopt()
  90. std::string drop_arg; // Value of -D<value>argument
  91. size_t percent_loc = 0; // Location of % sign in -D<value>
  92. double drop_percent = 0; // % value (1..100) in -D<value%>
  93. int num_drops = 0; // Max number of drops specified in -D<value>
  94. int num_req = 0; // Max number of dropped requests in -n<max-drops>
  95. int offset_arg = 0; // Temporary variable holding offset arguments
  96. std::string sarg; // Temporary variable for string args
  97. // In this section we collect argument values from command line
  98. // they will be tuned and validated elsewhere
  99. while((opt = getopt(argc, argv, "hv46r:t:R:b:n:p:d:D:l:P:a:L:s:iBc1T:X:O:E:S:I:x:w:")) != -1) {
  100. switch (opt) {
  101. case 'v':
  102. version();
  103. return;
  104. case '1':
  105. use_first_ = true;
  106. break;
  107. case '4':
  108. check(ipversion_ == 6, "IP version already set to 6");
  109. ipversion_ = 4;
  110. break;
  111. case '6':
  112. check(ipversion_ == 4, "IP version already set to 4");
  113. ipversion_ = 6;
  114. break;
  115. case 'a':
  116. aggressivity_ = positiveInteger("value of aggressivity: -a<value> must be a positive integer");
  117. break;
  118. case 'b':
  119. check(base_.size() > 3, "-b<value> already specified, unexpected occurence of 5th -b<value>");
  120. base_.push_back(optarg);
  121. decodeBase(base_.back());
  122. break;
  123. case 'B':
  124. broadcast_ = true;
  125. break;
  126. case 'c':
  127. rapid_commit_ = true;
  128. break;
  129. case 'd':
  130. check(drop_time_set_ > 1, "maximum number of drops already specified, "
  131. "unexpected 3rd occurence of -d<value>");
  132. try {
  133. drop_time_[drop_time_set_] = boost::lexical_cast<double>(optarg);
  134. } catch (boost::bad_lexical_cast&) {
  135. isc_throw(isc::InvalidParameter,
  136. "value of drop time: -d<value> must be positive number");
  137. }
  138. check(drop_time_[drop_time_set_] <= 0., "drop-time must be a positive number");
  139. drop_time_set_ = true;
  140. break;
  141. case 'D':
  142. drop_arg = std::string(optarg);
  143. percent_loc = drop_arg.find('%');
  144. check(max_pdrop_.size() > 1 || max_drop_.size() > 1, "values of maximum drops: -D<value> already "
  145. "specified, unexpected 3rd occurence of -D,value>");
  146. if ((percent_loc) != std::string::npos) {
  147. try {
  148. drop_percent = boost::lexical_cast<double>(drop_arg.substr(0, percent_loc));
  149. } catch (boost::bad_lexical_cast&) {
  150. isc_throw(isc::InvalidParameter,
  151. "value of drop percentage: -D<value%> must be 0..100");
  152. }
  153. check((drop_percent <= 0) || (drop_percent >= 100),
  154. "value of drop percentage: -D<value%> must be 0..100");
  155. max_pdrop_.push_back(drop_percent);
  156. } else {
  157. num_drops = positiveInteger("value of max drops number: -d<value> must be a positive integer");
  158. max_drop_.push_back(num_drops);
  159. }
  160. break;
  161. case 'E':
  162. elp_offset_ = nonNegativeInteger("value of time-offset: -E<value> must not be a negative integer");
  163. break;
  164. case 'h':
  165. usage();
  166. return;
  167. case 'i':
  168. exchange_mode_ = DO_SA;
  169. break;
  170. case 'I':
  171. rip_offset_ = positiveInteger("value of ip address offset: -I<value> must be a positive integer");
  172. break;
  173. case 'l':
  174. localname_ = std::string(optarg);
  175. break;
  176. case 'L':
  177. local_port_ = nonNegativeInteger("value of local port: -L<value> must not be a negative integer");
  178. check(local_port_ > static_cast<int>(std::numeric_limits<uint16_t>::max()),
  179. "local-port must be lower than " +
  180. boost::lexical_cast<std::string>(std::numeric_limits<uint16_t>::max()));
  181. break;
  182. case 'n':
  183. num_req = positiveInteger("value of num-request: -n<value> must be a positive integer");
  184. if (num_request_.size() >= 2) {
  185. isc_throw(isc::InvalidParameter,"value of maximum number of requests: -n<value> "
  186. "already specified, unexpected 3rd occurence of -n<value>");
  187. }
  188. num_request_.push_back(num_req);
  189. break;
  190. case 'O':
  191. if (rnd_offset_.size() < 2) {
  192. offset_arg = positiveInteger("value of random offset: -O<value> must be greater than 3");
  193. } else {
  194. isc_throw(isc::InvalidParameter,
  195. "random offsets already specified, unexpected 3rd occurence of -O<value>");
  196. }
  197. check(offset_arg < 3, "value of random random-offset: -O<value> must be greater than 3 ");
  198. rnd_offset_.push_back(offset_arg);
  199. break;
  200. case 'p':
  201. period_ = positiveInteger("value of test period: -p<value> must be a positive integer");
  202. break;
  203. case 'P':
  204. preload_ = nonNegativeInteger("number of preload packets: -P<value> must not be "
  205. "a negative integer");
  206. break;
  207. case 'r':
  208. rate_ = positiveInteger("value of rate: -r<value> must be a positive integer");
  209. break;
  210. case 'R':
  211. initClientsNum();
  212. break;
  213. case 's':
  214. seed_ = static_cast<unsigned int>
  215. (nonNegativeInteger("value of seed: -s <seed> must be non-negative integer"));
  216. seeded_ = seed_ > 0 ? true : false;
  217. break;
  218. case 'S':
  219. sid_offset_ = positiveInteger("value of server id offset: -S<value> must be a positive integer");
  220. break;
  221. case 't':
  222. report_delay_ = positiveInteger("value of report delay: -t<value> must be a positive integer");
  223. break;
  224. case 'T':
  225. if (template_file_.size() < 2) {
  226. sarg = nonEmptyString("template file name not specified, expected -T<filename>");
  227. template_file_.push_back(sarg);
  228. } else {
  229. isc_throw(isc::InvalidParameter,
  230. "template files are already specified, unexpected 3rd -T<filename> occurence");
  231. }
  232. break;
  233. case 'w':
  234. wrapped_ = nonEmptyString("command for wrapped mode: -w<command> must be specified");
  235. break;
  236. case 'x':
  237. diags_ = nonEmptyString("value of diagnostics selectors: -x<value> must be specified");
  238. break;
  239. case 'X':
  240. if (xid_offset_.size() < 2) {
  241. offset_arg = positiveInteger("value of transaction id: -X<value> must be a positive integer");
  242. } else {
  243. isc_throw(isc::InvalidParameter,
  244. "transaction ids already specified, unexpected 3rd -X<value> occurence");
  245. }
  246. xid_offset_.push_back(offset_arg);
  247. break;
  248. default:
  249. isc_throw(isc::InvalidParameter, "unknown command line option");
  250. }
  251. }
  252. // If the IP version was not specified in the
  253. // command line, assume IPv4.
  254. if (ipversion_ == 0) {
  255. ipversion_ = 4;
  256. }
  257. // If template packet files specified for both DISCOVER/SOLICIT
  258. // and REQUEST/REPLY exchanges make sure we have transaction id
  259. // and random duid offsets for both exchanges. We will duplicate
  260. // value specified as -X<value> and -R<value> for second
  261. // exchange if user did not specified otherwise.
  262. if (template_file_.size() > 1) {
  263. if (xid_offset_.size() == 1) {
  264. xid_offset_.push_back(xid_offset_[0]);
  265. }
  266. if (rnd_offset_.size() == 1) {
  267. rnd_offset_.push_back(rnd_offset_[0]);
  268. }
  269. }
  270. // Get server argument
  271. // NoteFF02::1:2 and FF02::1:3 are defined in RFC3315 as
  272. // All_DHCP_Relay_Agents_and_Servers and All_DHCP_Servers
  273. // addresses
  274. check(optind < argc -1, "extra arguments?");
  275. if (optind == argc - 1) {
  276. server_name_ = argv[optind];
  277. // Decode special cases
  278. if ((ipversion_ == 4) && (server_name_.compare("all") == 0)) {
  279. broadcast_ = 1;
  280. // 255.255.255.255 is IPv4 broadcast address
  281. server_name_ = "255.255.255.255";
  282. } else if ((ipversion_ == 6) && (server_name_.compare("all") == 0)) {
  283. server_name_ = "FF02::1:2";
  284. } else if ((ipversion_ == 6) && (server_name_.compare("servers") == 0)) {
  285. server_name_ = "FF05::1:3";
  286. }
  287. }
  288. // TODO handle -l option with IfaceManager when it is created
  289. }
  290. void
  291. CommandOptions::initClientsNum() {
  292. const std::string errmsg = "value of -R <value> must be non-negative integer";
  293. // Declare clients_num as as 64-bit signed value to
  294. // be able to detect negative values provided
  295. // by user. We would not detect negative values
  296. // if we casted directly to unsigned value.
  297. long long clients_num = 0;
  298. try {
  299. clients_num = boost::lexical_cast<long long>(optarg);
  300. } catch (boost::bad_lexical_cast&) {
  301. isc_throw(isc::InvalidParameter, errmsg.c_str());
  302. }
  303. check(clients_num < 0, errmsg);
  304. try {
  305. clients_num_ = boost::lexical_cast<uint32_t>(optarg);
  306. } catch (boost::bad_lexical_cast&) {
  307. isc_throw(isc::InvalidParameter, errmsg);
  308. }
  309. }
  310. void
  311. CommandOptions::decodeBase(const std::string& base) {
  312. std::string b(base);
  313. boost::algorithm::to_lower(b);
  314. // Currently we only support mac and duid
  315. if ((b.substr(0, 4) == "mac=") || (b.substr(0, 6) == "ether=")) {
  316. decodeMac(b);
  317. } else if (b.substr(0, 5) == "duid=") {
  318. decodeDuid(b);
  319. } else {
  320. isc_throw(isc::InvalidParameter,
  321. "base value not provided as -b<value>, expected -b mac=<mac> or -b duid=<duid>");
  322. }
  323. }
  324. void
  325. CommandOptions::decodeMac(const std::string& base) {
  326. // Strip string from mac=
  327. size_t found = base.find('=');
  328. static const char* errmsg = "expected -b<base> format for mac address is -b mac=00::0C::01::02::03::04";
  329. check(found == std::string::npos, errmsg);
  330. // Decode mac address to vector of uint8_t
  331. std::istringstream s1(base.substr(found + 1));
  332. std::string token;
  333. mac_prefix_.clear();
  334. // Get pieces of MAC address separated with : (or even ::)
  335. while (std::getline(s1, token, ':')) {
  336. unsigned int ui = 0;
  337. // Convert token to byte value using std::istringstream
  338. if (token.length() > 0) {
  339. try {
  340. // Do actual conversion
  341. ui = convertHexString(token);
  342. } catch (isc::InvalidParameter&) {
  343. isc_throw(isc::InvalidParameter,
  344. "invalid characters in MAC provided");
  345. }
  346. // If conversion succeeded store byte value
  347. mac_prefix_.push_back(ui);
  348. }
  349. }
  350. // MAC address must consist of 6 octets, otherwise it is invalid
  351. check(mac_prefix_.size() != 6, errmsg);
  352. }
  353. void
  354. CommandOptions::decodeDuid(const std::string& base) {
  355. // Strip argument from duid=
  356. size_t found = base.find('=');
  357. check(found == std::string::npos, "expected -b<base> format for duid is -b duid=<duid>");
  358. std::string b = base.substr(found + 1);
  359. // DUID must have even number of digits and must not be longer than 64 bytes
  360. check(b.length() & 1, "odd number of hexadecimal digits in duid");
  361. check(b.length() > 128, "duid too large");
  362. check(b.length() == 0, "no duid specified");
  363. // Turn pairs of hexadecimal digits into vector of octets
  364. for (int i = 0; i < b.length(); i += 2) {
  365. unsigned int ui = 0;
  366. try {
  367. // Do actual conversion
  368. ui = convertHexString(b.substr(i, 2));
  369. } catch (isc::InvalidParameter&) {
  370. isc_throw(isc::InvalidParameter,
  371. "invalid characters in DUID provided, exepected hex digits");
  372. }
  373. duid_prefix_.push_back(static_cast<uint8_t>(ui));
  374. }
  375. }
  376. uint8_t
  377. CommandOptions::convertHexString(const std::string& text) const {
  378. unsigned int ui = 0;
  379. // First, check if we are dealing with hexadecimal digits only
  380. for (int i = 0; i < text.length(); ++i) {
  381. if (!std::isxdigit(text[i])) {
  382. isc_throw(isc::InvalidParameter,
  383. "The following digit: " << text[i] << " in "
  384. << text << "is not hexadecimal");
  385. }
  386. }
  387. // If we are here, we have valid string to convert to octet
  388. std::istringstream text_stream(text);
  389. text_stream >> std::hex >> ui >> std::dec;
  390. // Check if for some reason we have overflow - this should never happen!
  391. if (ui > 0xFF) {
  392. isc_throw(isc::InvalidParameter, "Can't convert more than two hex digits to byte");
  393. }
  394. return ui;
  395. }
  396. void
  397. CommandOptions::validate() const {
  398. check((getIpVersion() != 4) && (isBroadcast() != 0),
  399. "-B is not compatible with IPv6 (-6)");
  400. check((getIpVersion() != 6) && (isRapidCommit() != 0),
  401. "-6 (IPv6) must be set to use -c");
  402. check((getExchangeMode() == DO_SA) && (getNumRequests().size() > 1),
  403. "second -n<num-request> is not compatible with -i");
  404. check((getExchangeMode() == DO_SA) && (getDropTime()[1] != 1.),
  405. "second -d<drop-time> is not compatible with -i");
  406. check((getExchangeMode() == DO_SA) &&
  407. ((getMaxDrop().size() > 1) || (getMaxDropPercentage().size() > 1)),
  408. "second -D<max-drop> is not compatible with -i\n");
  409. check((getExchangeMode() == DO_SA) && (isUseFirst()),
  410. "-1 is not compatible with -i\n");
  411. check((getExchangeMode() == DO_SA) && (getTemplateFiles().size() > 1),
  412. "second -T<template-file> is not compatible with -i\n");
  413. check((getExchangeMode() == DO_SA) && (getTransactionIdOffset().size() > 1),
  414. "second -X<xid-offset> is not compatible with -i\n");
  415. check((getExchangeMode() == DO_SA) && (getRandomOffset().size() > 1),
  416. "second -O<random-offset is not compatible with -i\n");
  417. check((getExchangeMode() == DO_SA) && (getElapsedTimeOffset() >= 0),
  418. "-E<time-offset> is not compatible with -i\n");
  419. check((getExchangeMode() == DO_SA) && (getServerIdOffset() >= 0),
  420. "-S<srvid-offset> is not compatible with -i\n");
  421. check((getExchangeMode() == DO_SA) && (getRequestedIpOffset() >= 0),
  422. "-I<ip-offset> is not compatible with -i\n");
  423. check((getExchangeMode() != DO_SA) && (isRapidCommit() != 0),
  424. "-i must be set to use -c\n");
  425. check((getRate() == 0) && (getReportDelay() != 0),
  426. "-r<rate> must be set to use -t<report>\n");
  427. check((getRate() == 0) && (getNumRequests().size() > 0),
  428. "-r<rate> must be set to use -n<num-request>\n");
  429. check((getRate() == 0) && (getPeriod() != 0),
  430. "-r<rate> must be set to use -p<test-period>\n");
  431. check((getRate() == 0) &&
  432. ((getMaxDrop().size() > 0) || getMaxDropPercentage().size() > 0),
  433. "-r<rate> must be set to use -D<max-drop>\n");
  434. check((getTemplateFiles().size() < getTransactionIdOffset().size()),
  435. "-T<template-file> must be set to use -X<xid-offset>\n");
  436. check((getTemplateFiles().size() < getRandomOffset().size()),
  437. "-T<template-file> must be set to use -O<random-offset>\n");
  438. check((getTemplateFiles().size() < 2) && (getElapsedTimeOffset() >= 0),
  439. "second/request -T<template-file> must be set to use -E<time-offset>\n");
  440. check((getTemplateFiles().size() < 2) && (getServerIdOffset() >= 0),
  441. "second/request -T<template-file> must be set to "
  442. "use -S<srvid-offset>\n");
  443. check((getTemplateFiles().size() < 2) && (getRequestedIpOffset() >= 0),
  444. "second/request -T<template-file> must be set to "
  445. "use -I<ip-offset>\n");
  446. }
  447. void
  448. CommandOptions::check(bool condition, const std::string& errmsg) const {
  449. // The same could have been done with macro or just if statement but
  450. // we prefer functions to macros here
  451. if (condition) {
  452. isc_throw(isc::InvalidParameter, errmsg);
  453. }
  454. }
  455. int
  456. CommandOptions::positiveInteger(const std::string& errmsg) const {
  457. try {
  458. int value = boost::lexical_cast<int>(optarg);
  459. check(value <= 0, errmsg);
  460. return (value);
  461. } catch (boost::bad_lexical_cast&) {
  462. isc_throw(InvalidParameter, errmsg);
  463. }
  464. }
  465. int
  466. CommandOptions::nonNegativeInteger(const std::string& errmsg) const {
  467. try {
  468. int value = boost::lexical_cast<int>(optarg);
  469. check(value < 0, errmsg);
  470. return (value);
  471. } catch (boost::bad_lexical_cast&) {
  472. isc_throw(InvalidParameter, errmsg);
  473. }
  474. }
  475. std::string
  476. CommandOptions::nonEmptyString(const std::string& errmsg) const {
  477. std::string sarg = optarg;
  478. if (sarg.length() == 0) {
  479. isc_throw(isc::InvalidParameter, errmsg);
  480. }
  481. return sarg;
  482. }
  483. void
  484. CommandOptions::usage() const {
  485. fprintf(stdout, "%s",
  486. "perfdhcp [-hv] [-4|-6] [-r<rate>] [-t<report>] [-R<range>] [-b<base>]\n"
  487. " [-n<num-request>] [-p<test-period>] [-d<drop-time>] [-D<max-drop>]\n"
  488. " [-l<local-addr|interface>] [-P<preload>] [-a<aggressivity>]\n"
  489. " [-L<local-port>] [-s<seed>] [-i] [-B] [-c] [-1]\n"
  490. " [-T<template-file>] [-X<xid-offset>] [-O<random-offset]\n"
  491. " [-E<time-offset>] [-S<srvid-offset>] [-I<ip-offset>]\n"
  492. " [-x<diagnostic-selector>] [-w<wrapped>] [server]\n"
  493. "\n"
  494. "The [server] argument is the name/address of the DHCP server to\n"
  495. "contact. For DHCPv4 operation, exchanges are initiated by\n"
  496. "transmitting a DHCP DISCOVER to this address.\n"
  497. "\n"
  498. "For DHCPv6 operation, exchanges are initiated by transmitting a DHCP\n"
  499. "SOLICIT to this address. In the DHCPv6 case, the special name 'all'\n"
  500. "can be used to refer to All_DHCP_Relay_Agents_and_Servers (the\n"
  501. "multicast address FF02::1:2), or the special name 'servers' to refer\n"
  502. "to All_DHCP_Servers (the multicast address FF05::1:3). The [server]\n"
  503. "argument is optional only in the case that -l is used to specify an\n"
  504. "interface, in which case [server] defaults to 'all'.\n"
  505. "\n"
  506. "The default is to perform a single 4-way exchange, effectively pinging\n"
  507. "the server.\n"
  508. "The -r option is used to set up a performance test, without\n"
  509. "it exchanges are initiated as fast as possible.\n"
  510. "\n"
  511. "Options:\n"
  512. "-1: Take the server-ID option from the first received message.\n"
  513. "-4: DHCPv4 operation (default). This is incompatible with the -6 option.\n"
  514. "-6: DHCPv6 operation. This is incompatible with the -4 option.\n"
  515. "-a<aggressivity>: When the target sending rate is not yet reached,\n"
  516. " control how many exchanges are initiated before the next pause.\n"
  517. "-b<base>: The base mac, duid, IP, etc, used to simulate different\n"
  518. " clients. This can be specified multiple times, each instance is\n"
  519. " in the <type>=<value> form, for instance:\n"
  520. " (and default) mac=00:0c:01:02:03:04.\n"
  521. "-d<drop-time>: Specify the time after which a request is treated as\n"
  522. " having been lost. The value is given in seconds and may contain a\n"
  523. " fractional component. The default is 1 second.\n"
  524. "-E<time-offset>: Offset of the (DHCPv4) secs field / (DHCPv6)\n"
  525. " elapsed-time option in the (second/request) template.\n"
  526. " The value 0 disables it.\n"
  527. "-h: Print this help.\n"
  528. "-i: Do only the initial part of an exchange: DO or SA, depending on\n"
  529. " whether -6 is given.\n"
  530. "-I<ip-offset>: Offset of the (DHCPv4) IP address in the requested-IP\n"
  531. " option / (DHCPv6) IA_NA option in the (second/request) template.\n"
  532. "-l<local-addr|interface>: For DHCPv4 operation, specify the local\n"
  533. " hostname/address to use when communicating with the server. By\n"
  534. " default, the interface address through which traffic would\n"
  535. " normally be routed to the server is used.\n"
  536. " For DHCPv6 operation, specify the name of the network interface\n"
  537. " via which exchanges are initiated.\n"
  538. "-L<local-port>: Specify the local port to use\n"
  539. " (the value 0 means to use the default).\n"
  540. "-O<random-offset>: Offset of the last octet to randomize in the template.\n"
  541. "-P<preload>: Initiate first <preload> exchanges back to back at startup.\n"
  542. "-r<rate>: Initiate <rate> DORA/SARR (or if -i is given, DO/SA)\n"
  543. " exchanges per second. A periodic report is generated showing the\n"
  544. " number of exchanges which were not completed, as well as the\n"
  545. " average response latency. The program continues until\n"
  546. " interrupted, at which point a final report is generated.\n"
  547. "-R<range>: Specify how many different clients are used. With 1\n"
  548. " (the default), all requests seem to come from the same client.\n"
  549. "-s<seed>: Specify the seed for randomization, making it repeatable.\n"
  550. "-S<srvid-offset>: Offset of the server-ID option in the\n"
  551. " (second/request) template.\n"
  552. "-T<template-file>: The name of a file containing the template to use\n"
  553. " as a stream of hexadecimal digits.\n"
  554. "-v: Report the version number of this program.\n"
  555. "-w<wrapped>: Command to call with start/stop at the beginning/end of\n"
  556. " the program.\n"
  557. "-x<diagnostic-selector>: Include extended diagnostics in the output.\n"
  558. " <diagnostic-selector> is a string of single-keywords specifying\n"
  559. " the operations for which verbose output is desired. The selector\n"
  560. " keyletters are:\n"
  561. " * 'a': print the decoded command line arguments\n"
  562. " * 'e': print the exit reason\n"
  563. " * 'i': print rate processing details\n"
  564. " * 'r': print randomization details\n"
  565. " * 's': print first server-id\n"
  566. " * 't': when finished, print timers of all successful exchanges\n"
  567. " * 'T': when finished, print templates\n"
  568. "-X<xid-offset>: Transaction ID (aka. xid) offset in the template.\n"
  569. "\n"
  570. "DHCPv4 only options:\n"
  571. "-B: Force broadcast handling.\n"
  572. "\n"
  573. "DHCPv6 only options:\n"
  574. "-c: Add a rapid commit option (exchanges will be SA).\n"
  575. "\n"
  576. "The remaining options are used only in conjunction with -r:\n"
  577. "\n"
  578. "-D<max-drop>: Abort the test if more than <max-drop> requests have\n"
  579. " been dropped. Use -D0 to abort if even a single request has been\n"
  580. " dropped. If <max-drop> includes the suffix '%', it specifies a\n"
  581. " maximum percentage of requests that may be dropped before abort.\n"
  582. " In this case, testing of the threshold begins after 10 requests\n"
  583. " have been expected to be received.\n"
  584. "-n<num-request>: Initiate <num-request> transactions. No report is\n"
  585. " generated until all transactions have been initiated/waited-for,\n"
  586. " after which a report is generated and the program terminates.\n"
  587. "-p<test-period>: Send requests for the given test period, which is\n"
  588. " specified in the same manner as -d. This can be used as an\n"
  589. " alternative to -n, or both options can be given, in which case the\n"
  590. " testing is completed when either limit is reached.\n"
  591. "-t<report>: Delay in seconds between two periodic reports.\n"
  592. "\n"
  593. "Errors:\n"
  594. "- tooshort: received a too short message\n"
  595. "- orphans: received a message which doesn't match an exchange\n"
  596. " (duplicate, late or not related)\n"
  597. "- locallimit: reached to local system limits when sending a message.\n"
  598. "\n"
  599. "Exit status:\n"
  600. "The exit status is:\n"
  601. "0 on complete success.\n"
  602. "1 for a general error.\n"
  603. "2 if an error is found in the command line arguments.\n"
  604. "3 if there are no general failures in operation, but one or more\n"
  605. " exchanges are not successfully completed.\n");
  606. }
  607. void
  608. CommandOptions::version() const {
  609. fprintf(stdout, "version 0.01\n");
  610. }
  611. } // namespace perfdhcp
  612. } // namespace isc