command_options.cc 7.7 KB

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