command_options.cc 26 KB

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