command_options.cc 27 KB

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