Kea  2.5.3
command_options.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2023 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef COMMAND_OPTIONS_H
8 #define COMMAND_OPTIONS_H
9 
10 #include <dhcp/option.h>
11 
12 #include <boost/noncopyable.hpp>
13 #include <stdint.h>
14 #include <string>
15 #include <vector>
16 
17 namespace isc {
18 namespace perfdhcp {
19 
20 enum class Scenario {
21  BASIC,
22  AVALANCHE
23 };
24 
30 class CommandOptions : public boost::noncopyable {
31 public:
32 
38  reset();
39  }
40 
42  typedef std::vector<std::vector<uint8_t> > MacAddrsVector;
43 
45  const static uint8_t RELAY_OPTIONS_MAX_ENCAPSULATION = 1;
46 
53  class LeaseType {
54  public:
55 
57  enum Type {
61  };
62 
63  LeaseType();
64 
68  LeaseType(const Type lease_type);
69 
75  bool is(const Type lease_type) const;
76 
92  bool includes(const Type lease_type) const;
93 
97  void set(const Type lease_type);
98 
107  void fromCommandLine(const std::string& cmd_line_arg);
108 
112  std::string toText() const;
113 
114  private:
115  Type type_;
116 
117  };
118 
122  DORA_SARR
123  };
124 
130  void reset();
131 
142  bool parse(int argc, char** const argv, bool print_cmd_line = false);
143 
147  uint8_t getIpVersion() const { return ipversion_; }
148 
152  ExchangeMode getExchangeMode() const { return exchange_mode_; }
153 
157  LeaseType getLeaseType() const { return (lease_type_); }
158 
162  int getRate() const { return rate_; }
163 
167  int getRenewRate() const { return (renew_rate_); }
168 
172  int getReleaseRate() const { return (release_rate_); }
173 
177  int getReportDelay() const { return report_delay_; }
178 
182  int getCleanReport() const { return clean_report_; }
183 
187  std::string getCleanReportSeparator() const { return clean_report_separator_; }
188 
192  uint32_t getClientsNum() const { return clients_num_; }
193 
197  std::vector<uint8_t> getMacTemplate() const { return mac_template_; }
198 
202  std::vector<uint8_t> getDuidTemplate() const { return duid_template_; }
203 
207  std::vector<std::string> getBase() const { return base_; }
208 
212  bool getAddrUnique() const { return addr_unique_; }
213 
217  std::vector<int> getNumRequests() const { return num_request_; }
218 
222  int getPeriod() const { return period_; }
223 
228  int getWaitForElapsedTime() const { return wait_for_elapsed_time_; }
229 
234  int getIncreaseElapsedTime() const { return increased_elapsed_time_; }
235 
242  std::vector<double> getDropTime() const { return drop_time_; }
243 
250  std::vector<int> getMaxDrop() const { return max_drop_; }
251 
258  std::vector<double> getMaxDropPercentage() const { return max_pdrop_; }
259 
263  std::string getLocalName() const { return localname_; }
264 
271  bool isInterface() const { return is_interface_; }
272 
276  int getPreload() const { return preload_; }
277 
281  int getLocalPort() const { return local_port_; }
282 
286  int getRemotePort() const { return remote_port_; }
287 
291  int getExitWaitTime() const { return exit_wait_time_; }
292 
296  bool isSeeded() const { return seeded_; }
297 
301  uint32_t getSeed() const { return seed_; }
302 
306  bool isBroadcast() const { return broadcast_; }
307 
311  bool isRapidCommit() const { return rapid_commit_; }
312 
316  bool isUseFirst() const { return use_first_; }
317 
321  bool isUseRelayedV6() const { return (v6_relay_encapsulation_level_ > 0); }
322 
326  std::vector<std::string> getTemplateFiles() const { return template_file_; }
327 
334  std::string getMacListFile() const { return mac_list_file_; }
335 
341  const MacAddrsVector& getMacsFromFile() const { return mac_list_; }
342 
346  std::vector<int> getTransactionIdOffset() const { return xid_offset_; }
347 
351  std::vector<int> getRandomOffset() const { return rnd_offset_; }
352 
356  int getElapsedTimeOffset() const { return elp_offset_; }
357 
361  int getServerIdOffset() const { return sid_offset_; }
362 
366  int getRequestedIpOffset() const { return rip_offset_; }
367 
371  std::string getDiags() const { return diags_; }
372 
376  std::string getWrapped() const { return wrapped_; }
377 
381  const isc::dhcp::OptionCollection& getExtraOpts() const { return extra_opts_; }
382 
391  const isc::dhcp::OptionCollection& getRelayOpts(uint8_t encapsulation_level = 1) const;
392 
396  bool isSingleThreaded() const { return single_thread_mode_; }
397 
401  Scenario getScenario() const { return scenario_; }
402 
406  std::string getServerName() const { return server_name_; }
407 
411  std::string getRelayAddrListFile() const { return relay_addr_list_file_; }
412 
416  std::vector<std::string> getRelayAddrList() const { return relay_addr_list_; }
417 
421  std::string getRandRelayAddr() { return relay_addr_list_[rand() % relay_addr_list_.size()]; }
422 
426  bool checkMultiSubnet() { return multi_subnet_; }
427 
432  bool testDiags(const char diag) {
433  if (getDiags().find(diag) != std::string::npos) {
434  return (true);
435  }
436  return (false);
437  }
438 
440  void printCommandLine() const;
441 
445  static void usage();
446 
450  void version() const;
451 
452 private:
462  bool initialize(int argc, char** argv, bool print_cmd_line);
463 
470  void validate();
471 
480  inline void check(bool condition, const std::string& errmsg) const;
481 
486  int positiveInteger(const std::string& errmsg) const;
487 
492  int nonNegativeInteger(const std::string& errmsg) const;
493 
498  std::string nonEmptyString(const std::string& errmsg) const;
499 
503  void initLeaseType();
504 
511  void initClientsNum();
512 
518  void initIsInterface();
519 
529  // Function will decode 00:01:02:03:04:05 and/or
535  void decodeBase(const std::string& base);
536 
546  void decodeMacBase(const std::string& base);
547 
557  void decodeDuid(const std::string& base);
558 
565  void generateDuidTemplate();
566 
571  uint8_t convertHexString(const std::string& hex_text) const;
572 
575  void loadMacs();
576 
579  bool decodeMacString(const std::string& line);
580 
582  void loadRelayAddr();
583 
588  bool validateIP(const std::string& line);
589 
592  uint8_t ipversion_;
593 
595  ExchangeMode exchange_mode_;
596 
598  LeaseType lease_type_;
599 
601  unsigned int rate_;
602 
604  unsigned int renew_rate_;
605 
607  unsigned int release_rate_;
608 
610  int report_delay_;
611 
613  bool clean_report_;
614 
616  std::string clean_report_separator_;
617 
619  uint32_t clients_num_;
620 
623  std::vector<uint8_t> mac_template_;
624 
627  std::vector<uint8_t> duid_template_;
628 
630  bool addr_unique_;
631 
634  std::vector<std::string> base_;
635 
637  int exit_wait_time_;
638 
640  std::vector<int> num_request_;
641 
643  int period_;
644 
645  // for how long perfdhcp will wait before start sending
646  // messages with increased elapsed time.
647  int wait_for_elapsed_time_;
648 
649  // Amount of time after which perfdhcp will send messages with
650  // elapsed time increased.
651  int increased_elapsed_time_;
652 
655  uint8_t drop_time_set_;
656 
660  std::vector<double> drop_time_;
661 
666  std::vector<int> max_drop_;
667 
671  std::vector<double> max_pdrop_;
672 
674  std::string localname_;
675 
678  bool is_interface_;
679 
683  int preload_;
684 
686  int local_port_;
687 
689  int remote_port_;
690 
692  uint32_t seed_;
693 
695  bool seeded_;
696 
698  bool broadcast_;
699 
701  bool rapid_commit_;
702 
704  bool use_first_;
705 
709  std::vector<std::string> template_file_;
710 
716  std::string mac_list_file_;
717 
719  std::vector<std::vector<uint8_t> > mac_list_;
720 
722  std::string relay_addr_list_file_;
723 
725  std::vector<std::string> relay_addr_list_;
726 
728  bool multi_subnet_;
729 
734  std::vector<int> xid_offset_;
735 
739  std::vector<int> rnd_offset_;
740 
742  int elp_offset_;
743 
745  int sid_offset_;
746 
748  int rip_offset_;
749 
752  std::string diags_;
753 
756  std::string wrapped_;
757 
759  std::string server_name_;
760 
762  uint8_t v6_relay_encapsulation_level_;
763 
765  isc::dhcp::OptionCollection extra_opts_;
766 
768  std::map<uint8_t, isc::dhcp::OptionCollection> relay_opts_;
769 
771  bool single_thread_mode_;
772 
774  Scenario scenario_;
775 };
776 
777 } // namespace perfdhcp
778 } // namespace isc
779 
780 #endif // COMMAND_OPTIONS_H
A class encapsulating the type of lease being requested from the server.
void set(const Type lease_type)
Sets the lease type code.
void fromCommandLine(const std::string &cmd_line_arg)
Sets the lease type from the command line argument.
bool is(const Type lease_type) const
Checks if lease type has the specified code.
std::string toText() const
Return textual representation of the lease type.
bool includes(const Type lease_type) const
Checks if lease type implies request for the address, prefix (or both) as specified by the function a...
bool testDiags(const char diag)
Find if diagnostic flag has been set.
std::string getRandRelayAddr()
Returns random relay address.
int getIncreaseElapsedTime() const
Returns increased elapsed time.
CommandOptions()
Default Constructor.
int getServerIdOffset() const
Returns template offset for server-ID.
std::string getWrapped() const
Returns wrapped command.
std::vector< std::string > getRelayAddrList() const
Returns list of relay addresses.
bool isSingleThreaded() const
Check if single-threaded mode is enabled.
int getRenewRate() const
Returns a rate at which DHCPv6 Renew messages are sent.
uint8_t getIpVersion() const
Returns IP version.
std::vector< int > getMaxDrop() const
Returns maximum drops number.
bool getAddrUnique() const
Returns address uniqueness value.
int getRate() const
Returns exchange rate.
void version() const
Print program version.
std::string getCleanReportSeparator() const
Returns clean report separator.
bool isRapidCommit() const
Check if rapid commit option used.
std::string getLocalName() const
Returns local address or interface name.
std::vector< int > getRandomOffset() const
Returns template offsets for rnd.
std::vector< double > getDropTime() const
Returns drop time.
bool checkMultiSubnet()
Check if multi subnet mode is enabled.
bool isUseFirst() const
Check if server-ID to be taken from first package.
std::string getRelayAddrListFile() const
Returns file location with set of relay addresses.
int getLocalPort() const
Returns local port number.
std::string getMacListFile() const
Returns location of the file containing list of MAC addresses.
int getReportDelay() const
Returns delay between two performance reports.
int getRemotePort() const
Returns remote port number.
Scenario getScenario() const
Returns selected scenario.
static const uint8_t RELAY_OPTIONS_MAX_ENCAPSULATION
Maximum allowed level of encapsulation of added relay options.
const isc::dhcp::OptionCollection & getExtraOpts() const
Returns extra options to be inserted.
int getWaitForElapsedTime() const
Returns time to wait for elapsed time increase.
ExchangeMode
2-way (cmd line param -i) or 4-way exchanges
bool isBroadcast() const
Checks if broadcast address is to be used.
std::vector< uint8_t > getDuidTemplate() const
Returns DUID template.
std::vector< uint8_t > getMacTemplate() const
Returns MAC address template.
std::vector< int > getNumRequests() const
Returns maximum number of exchanges.
std::vector< std::vector< uint8_t > > MacAddrsVector
A vector holding MAC addresses.
std::vector< int > getTransactionIdOffset() const
brief Returns template offsets for xid.
int getElapsedTimeOffset() const
Returns template offset for elapsed time.
std::string getServerName() const
Returns server name.
const isc::dhcp::OptionCollection & getRelayOpts(uint8_t encapsulation_level=1) const
Returns relay options to be inserted at given level of encapsulation.
const MacAddrsVector & getMacsFromFile() const
Returns reference to a vector of MAC addresses read from a file.
LeaseType getLeaseType() const
\ brief Returns the type of lease being requested.
bool isUseRelayedV6() const
Check if generated DHCPv6 messages should appear as relayed.
int getExitWaitTime() const
Returns the time in microseconds to delay the program by.
uint32_t getClientsNum() const
Returns number of simulated clients.
int getPreload() const
Returns number of preload exchanges.
std::vector< std::string > getBase() const
Returns base values.
bool isSeeded() const
Checks if seed provided.
void reset()
Reset to defaults.
int getPeriod() const
Returns test period.
std::vector< double > getMaxDropPercentage() const
Returns maximal percentage of drops.
static void usage()
Print usage.
bool parse(int argc, char **const argv, bool print_cmd_line=false)
Parse command line.
std::string getDiags() const
Returns diagnostic selectors.
int getReleaseRate() const
Returns a rate at which DHCPv6 Release messages are sent.
std::vector< std::string > getTemplateFiles() const
Returns template file names.
uint32_t getSeed() const
Returns random seed.
ExchangeMode getExchangeMode() const
Returns packet exchange mode.
void printCommandLine() const
Print command line arguments.
int getCleanReport() const
Returns clean report mode.
bool isInterface() const
Checks if interface name was used.
int getRequestedIpOffset() const
Returns template offset for requested IP.
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
Definition: option.h:40
Defines the logger used by the top-level component of kea-lfc.