command_options.cc 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 <inttypes.h>
  15. #include <stdio.h>
  16. #include <unistd.h>
  17. #include "command_options.h"
  18. using namespace std;
  19. using namespace isc;
  20. namespace isc {
  21. namespace perfdhcp {
  22. // Reset stored values to the defaults.
  23. void
  24. CommandOptions::reset() {
  25. uint8_t mac[6] = { 0x0, 0xC, 0x1, 0x2, 0x3, 0x4 };
  26. double lt[2] = { 1., 1. };
  27. ipversion_ = 4;
  28. exchange_mode_ = DORR_SARR;
  29. rate_ = 0;
  30. report_delay_ = 0;
  31. random_range_ = 0;
  32. max_random_ = 0;
  33. mac_prefix_.assign(mac, mac+6);
  34. base_.resize(0);
  35. num_request_.resize(0);
  36. period_ = 0;
  37. lost_time_set_ = 0;
  38. lost_time_.assign(lt, lt+2);
  39. max_drop_set_ = 0;
  40. max_drop_.push_back(0);
  41. max_drop_.push_back(0);
  42. max_pdrop_.push_back(0.);
  43. max_pdrop_.push_back(0.);
  44. localname_.resize(0);
  45. is_interface_ = false;
  46. preload_ = 0;
  47. aggressivity_ = 1;
  48. local_port_ = 0;
  49. seeded_ = false;
  50. seed_ = 0;
  51. broadcast_ = false;
  52. rapid_commit_ = false;
  53. use_first_ = false;
  54. template_file_.resize(0);
  55. xid_offset_.resize(0);
  56. rnd_offset_.resize(0);
  57. elp_offset_ = -1;
  58. sid_offset_ = -1;
  59. rip_offset_ = -1;
  60. diags_.resize(0);
  61. wrapped_.resize(0);
  62. server_name_.resize(0);
  63. }
  64. int
  65. CommandOptions::parse(int argc, char** argv, bool force_reset /*=false */) {
  66. int ch;
  67. if (force_reset) {
  68. reset();
  69. }
  70. // Reset internal variable used by getopt to index elements
  71. optind = 1;
  72. while((ch = 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) {
  73. switch (ch) {
  74. case 'h':
  75. usage();
  76. break;
  77. default:
  78. ;
  79. }
  80. }
  81. return(0);
  82. }
  83. void
  84. CommandOptions::usage(void)
  85. {
  86. fprintf(stderr, "%s",
  87. "perfdhcp [-hv] [-4|-6] [-r<rate>] [-t<report>] [-R<range>] [-b<base>]\n"
  88. " [-n<num-request>] [-p<test-period>] [-d<drop-time>] [-D<max-drop>]\n"
  89. " [-l<local-addr|interface>] [-P<preload>] [-a<aggressivity>]\n"
  90. " [-L<local-port>] [-s<seed>] [-i] [-B] [-c] [-1]\n"
  91. " [-T<template-file>] [-X<xid-offset>] [-O<random-offset]\n"
  92. " [-E<time-offset>] [-S<srvid-offset>] [-I<ip-offset>]\n"
  93. " [-x<diagnostic-selector>] [-w<wrapped>] [server]\n"
  94. "\f\n"
  95. "The [server] argument is the name/address of the DHCP server to\n"
  96. "contact. For DHCPv4 operation, exchanges are initiated by\n"
  97. "transmitting a DHCP DISCOVER to this address.\n"
  98. "\n"
  99. "For DHCPv6 operation, exchanges are initiated by transmitting a DHCP\n"
  100. "SOLICIT to this address. In the DHCPv6 case, the special name 'all'\n"
  101. "can be used to refer to All_DHCP_Relay_Agents_and_Servers (the\n"
  102. "multicast address FF02::1:2), or the special name 'servers' to refer\n"
  103. "to All_DHCP_Servers (the multicast address FF05::1:3). The [server]\n"
  104. "argument is optional only in the case that -l is used to specify an\n"
  105. "interface, in which case [server] defaults to 'all'.\n"
  106. "\n"
  107. "The default is to perform a single 4-way exchange, effectively pinging\n"
  108. "the server.\n"
  109. "The -r option is used to set up a performance test, without\n"
  110. "it exchanges are initiated as fast as possible.\n"
  111. "\n"
  112. "Options:\n"
  113. "-1: Take the server-ID option from the first received message.\n"
  114. "-4: DHCPv4 operation (default). This is incompatible with the -6 option.\n"
  115. "-6: DHCPv6 operation. This is incompatible with the -4 option.\n"
  116. "-a<aggressivity>: When the target sending rate is not yet reached,\n"
  117. " control how many exchanges are initiated before the next pause.\n"
  118. "-b<base>: The base MAC, DUID, IP, etc, used to simulate different\n"
  119. " clients. This can be specified multiple times, each instance is\n"
  120. " in the <type>=<value> form, for instance:\n"
  121. " (and default) MAC=00:0c:01:02:03:04.\n"
  122. "-d<drop-time>: Specify the time after which a request is treated as\n"
  123. " having been lost. The value is given in seconds and may contain a\n"
  124. " fractional component. The default is 1 second.\n"
  125. "-E<time-offset>: Offset of the (DHCPv4) secs field / (DHCPv6)\n"
  126. " elapsed-time option in the (second/request) template.\n"
  127. " The value 0 disables it.\n"
  128. "-h: Print this help.\n"
  129. "-i: Do only the initial part of an exchange: DO or SA, depending on\n"
  130. " whether -6 is given.\n"
  131. "-I<ip-offset>: Offset of the (DHCPv4) IP address in the requested-IP\n"
  132. " option / (DHCPv6) IA_NA option in the (second/request) template.\n"
  133. "-l<local-addr|interface>: For DHCPv4 operation, specify the local\n"
  134. " hostname/address to use when communicating with the server. By\n"
  135. " default, the interface address through which traffic would\n"
  136. " normally be routed to the server is used.\n"
  137. " For DHCPv6 operation, specify the name of the network interface\n"
  138. " via which exchanges are initiated.\n"
  139. "-L<local-port>: Specify the local port to use\n"
  140. " (the value 0 means to use the default).\n"
  141. "-O<random-offset>: Offset of the last octet to randomize in the template.\n"
  142. "-P<preload>: Initiate first <preload> exchanges back to back at startup.\n"
  143. "-r<rate>: Initiate <rate> DORA/SARR (or if -i is given, DO/SA)\n"
  144. " exchanges per second. A periodic report is generated showing the\n"
  145. " number of exchanges which were not completed, as well as the\n"
  146. " average response latency. The program continues until\n"
  147. " interrupted, at which point a final report is generated.\n"
  148. "-R<range>: Specify how many different clients are used. With 1\n"
  149. " (the default), all requests seem to come from the same client.\n"
  150. "-s<seed>: Specify the seed for randomization, making it repeatable.\n"
  151. "-S<srvid-offset>: Offset of the server-ID option in the\n"
  152. " (second/request) template.\n"
  153. "-T<template-file>: The name of a file containing the template to use\n"
  154. " as a stream of hexadecimal digits.\n"
  155. "-v: Report the version number of this program.\n"
  156. "-w<wrapped>: Command to call with start/stop at the beginning/end of\n"
  157. " the program.\n"
  158. "-x<diagnostic-selector>: Include extended diagnostics in the output.\n"
  159. " <diagnostic-selector> is a string of single-keywords specifying\n"
  160. " the operations for which verbose output is desired. The selector\n"
  161. " keyletters are:\n"
  162. " * 'a': print the decoded command line arguments\n"
  163. " * 'e': print the exit reason\n"
  164. " * 'i': print rate processing details\n"
  165. " * 'r': print randomization details\n"
  166. " * 's': print first server-id\n"
  167. " * 't': when finished, print timers of all successful exchanges\n"
  168. " * 'T': when finished, print templates\n"
  169. "-X<xid-offset>: Transaction ID (aka. xid) offset in the template.\n"
  170. "\n"
  171. "DHCPv4 only options:\n"
  172. "-B: Force broadcast handling.\n"
  173. "\n"
  174. "DHCPv6 only options:\n"
  175. "-c: Add a rapid commit option (exchanges will be SA).\n"
  176. "\n"
  177. "The remaining options are used only in conjunction with -r:\n"
  178. "\n"
  179. "-D<max-drop>: Abort the test if more than <max-drop> requests have\n"
  180. " been dropped. Use -D0 to abort if even a single request has been\n"
  181. " dropped. If <max-drop> includes the suffix '%', it specifies a\n"
  182. " maximum percentage of requests that may be dropped before abort.\n"
  183. " In this case, testing of the threshold begins after 10 requests\n"
  184. " have been expected to be received.\n"
  185. "-n<num-request>: Initiate <num-request> transactions. No report is\n"
  186. " generated until all transactions have been initiated/waited-for,\n"
  187. " after which a report is generated and the program terminates.\n"
  188. "-p<test-period>: Send requests for the given test period, which is\n"
  189. " specified in the same manner as -d. This can be used as an\n"
  190. " alternative to -n, or both options can be given, in which case the\n"
  191. " testing is completed when either limit is reached.\n"
  192. "-t<report>: Delay in seconds between two periodic reports.\n"
  193. "\n"
  194. "Errors:\n"
  195. "- tooshort: received a too short message\n"
  196. "- orphans: received a message which doesn't match an exchange\n"
  197. " (duplicate, late or not related)\n"
  198. "- locallimit: reached to local system limits when sending a message.\n"
  199. "\n"
  200. "Exit status:\n"
  201. "The exit status is:\n"
  202. "0 on complete success.\n"
  203. "1 for a general error.\n"
  204. "2 if an error is found in the command line arguments.\n"
  205. "3 if there are no general failures in operation, but one or more\n"
  206. " exchanges are not successfully completed.\n");
  207. }
  208. } // namespace perfdhcp
  209. } // namespace isc