Kea 3.3.3
command_options.h
Go to the documentation of this file.
1// Copyright (C) 2012-2026 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 <cstdint>
13#include <string>
14#include <vector>
15
16#include <boost/noncopyable.hpp>
17
18namespace isc {
19namespace perfdhcp {
20
21enum class Scenario {
24};
25
31class CommandOptions : public boost::noncopyable {
32public:
33
39 reset();
40 }
41
43 typedef std::vector<std::vector<uint8_t> > MacAddrsVector;
44
46 const static uint8_t RELAY_OPTIONS_MAX_ENCAPSULATION = 1;
47
54 class LeaseType {
55 public:
56
63
64 LeaseType();
65
69 LeaseType(const Type lease_type);
70
76 bool is(const Type lease_type) const;
77
93 bool includes(const Type lease_type) const;
94
98 void set(const Type lease_type);
99
108 void fromCommandLine(const std::string& cmd_line_arg);
109
113 std::string toText() const;
114
115 private:
116 Type type_;
117
118 };
119
121 enum ExchangeMode : uint16_t {
124 };
125
131 void reset();
132
143 bool parse(int argc, char** const argv, bool print_cmd_line = false);
144
148 uint8_t getIpVersion() const { return ipversion_; }
149
153 ExchangeMode getExchangeMode() const { return exchange_mode_; }
154
158 LeaseType getLeaseType() const { return (lease_type_); }
159
163 int getRate() const { return rate_; }
164
168 int getRenewRate() const { return (renew_rate_); }
169
173 int getReleaseRate() const { return (release_rate_); }
174
178 int getReportDelay() const { return report_delay_; }
179
183 int getCleanReport() const { return clean_report_; }
184
188 std::string getCleanReportSeparator() const { return clean_report_separator_; }
189
193 uint32_t getClientsNum() const { return clients_num_; }
194
198 std::vector<uint8_t> getMacTemplate() const { return mac_template_; }
199
203 std::vector<uint8_t> getDuidTemplate() const { return duid_template_; }
204
208 std::vector<std::string> getBase() const { return base_; }
209
213 bool getAddrUnique() const { return addr_unique_; }
214
218 std::vector<int> getNumRequests() const { return num_request_; }
219
223 int getPeriod() const { return period_; }
224
229 int getWaitForElapsedTime() const { return wait_for_elapsed_time_; }
230
235 int getIncreaseElapsedTime() const { return increased_elapsed_time_; }
236
243 std::vector<double> getDropTime() const { return drop_time_; }
244
251 std::vector<int> getMaxDrop() const { return max_drop_; }
252
259 std::vector<double> getMaxDropPercentage() const { return max_pdrop_; }
260
264 std::string getLocalName() const { return localname_; }
265
272 bool isInterface() const { return is_interface_; }
273
277 int getPreload() const { return preload_; }
278
282 int getLocalPort() const { return local_port_; }
283
287 int getRemotePort() const { return remote_port_; }
288
292 int getExitWaitTime() const { return exit_wait_time_; }
293
297 bool isSeeded() const { return seeded_; }
298
302 uint32_t getSeed() const { return seed_; }
303
307 bool isBroadcast() const { return broadcast_; }
308
312 bool isRapidCommit() const { return rapid_commit_; }
313
317 bool isUseFirst() const { return use_first_; }
318
322 bool isUseRelayedV6() const { return (v6_relay_encapsulation_level_ > 0); }
323
327 std::vector<std::string> getTemplateFiles() const { return template_file_; }
328
335 std::string getMacListFile() const { return mac_list_file_; }
336
342 const MacAddrsVector& getMacsFromFile() const { return mac_list_; }
343
347 std::vector<int> getTransactionIdOffset() const { return xid_offset_; }
348
352 std::vector<int> getRandomOffset() const { return rnd_offset_; }
353
357 int getElapsedTimeOffset() const { return elp_offset_; }
358
362 int getServerIdOffset() const { return sid_offset_; }
363
367 int getRequestedIpOffset() const { return rip_offset_; }
368
372 std::string getDiags() const { return diags_; }
373
377 std::string getWrapped() const { return wrapped_; }
378
382 const isc::dhcp::OptionCollection& getExtraOpts() const { return extra_opts_; }
383
392 const isc::dhcp::OptionCollection& getRelayOpts(uint8_t encapsulation_level = 1) const;
393
397 bool isSingleThreaded() const { return single_thread_mode_; }
398
402 Scenario getScenario() const { return scenario_; }
403
407 std::string getServerName() const { return server_name_; }
408
412 std::string getRelayAddrListFile() const { return relay_addr_list_file_; }
413
417 std::vector<std::string> getRelayAddrList() const { return relay_addr_list_; }
418
422 std::string getRandRelayAddr() { return relay_addr_list_[rand() % relay_addr_list_.size()]; }
423
427 bool checkMultiSubnet() { return multi_subnet_; }
428
433 bool testDiags(const char diag) {
434 if (getDiags().find(diag) != std::string::npos) {
435 return (true);
436 }
437 return (false);
438 }
439
441 void printCommandLine() const;
442
446 static void usage();
447
449 void version() const;
450
452 void extendedVersion() const;
453
454private:
464 bool initialize(int argc, char** argv, bool print_cmd_line);
465
472 void validate();
473
482 inline void check(bool condition, const std::string& errmsg) const;
483
488 int positiveInteger(const std::string& errmsg) const;
489
494 int nonNegativeInteger(const std::string& errmsg) const;
495
500 std::string nonEmptyString(const std::string& errmsg) const;
501
505 void initLeaseType();
506
513 void initClientsNum();
514
520 void initIsInterface();
521
531 // Function will decode 00:01:02:03:04:05 and/or
537 void decodeBase(const std::string& base);
538
548 void decodeMacBase(const std::string& base);
549
559 void decodeDuid(const std::string& base);
560
567 void generateDuidTemplate();
568
573 uint8_t convertHexString(const std::string& hex_text) const;
574
577 void loadMacs();
578
581 bool decodeMacString(const std::string& line);
582
584 void loadRelayAddr();
585
590 bool validateIP(const std::string& line);
591
594 uint8_t ipversion_;
595
597 ExchangeMode exchange_mode_;
598
600 LeaseType lease_type_;
601
603 unsigned int rate_;
604
606 unsigned int renew_rate_;
607
609 unsigned int release_rate_;
610
612 int report_delay_;
613
615 bool clean_report_;
616
618 std::string clean_report_separator_;
619
621 uint32_t clients_num_;
622
625 std::vector<uint8_t> mac_template_;
626
629 std::vector<uint8_t> duid_template_;
630
632 bool addr_unique_;
633
636 std::vector<std::string> base_;
637
639 int exit_wait_time_;
640
642 std::vector<int> num_request_;
643
645 int period_;
646
647 // for how long perfdhcp will wait before start sending
648 // messages with increased elapsed time.
649 int wait_for_elapsed_time_;
650
651 // Amount of time after which perfdhcp will send messages with
652 // elapsed time increased.
653 int increased_elapsed_time_;
654
657 uint8_t drop_time_set_;
658
662 std::vector<double> drop_time_;
663
668 std::vector<int> max_drop_;
669
673 std::vector<double> max_pdrop_;
674
676 std::string localname_;
677
680 bool is_interface_;
681
685 int preload_;
686
688 int local_port_;
689
691 int remote_port_;
692
694 uint32_t seed_;
695
697 bool seeded_;
698
700 bool broadcast_;
701
703 bool rapid_commit_;
704
706 bool use_first_;
707
711 std::vector<std::string> template_file_;
712
718 std::string mac_list_file_;
719
721 std::vector<std::vector<uint8_t> > mac_list_;
722
724 std::string relay_addr_list_file_;
725
727 std::vector<std::string> relay_addr_list_;
728
730 bool multi_subnet_;
731
736 std::vector<int> xid_offset_;
737
741 std::vector<int> rnd_offset_;
742
744 int elp_offset_;
745
747 int sid_offset_;
748
750 int rip_offset_;
751
754 std::string diags_;
755
758 std::string wrapped_;
759
761 std::string server_name_;
762
764 uint8_t v6_relay_encapsulation_level_;
765
767 isc::dhcp::OptionCollection extra_opts_;
768
770 std::map<uint8_t, isc::dhcp::OptionCollection> relay_opts_;
771
773 bool single_thread_mode_;
774
776 Scenario scenario_;
777};
778
779} // namespace perfdhcp
780} // namespace isc
781
782#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.
std::vector< std::string > getBase() const
Returns base values.
int getServerIdOffset() const
Returns template offset for server-ID.
std::string getWrapped() const
Returns wrapped command.
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< uint8_t > getDuidTemplate() const
Returns DUID template.
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.
bool checkMultiSubnet()
Check if multi subnet mode is enabled.
const isc::dhcp::OptionCollection & getExtraOpts() const
Returns extra options to be inserted.
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.
void extendedVersion() const
Print extended program version.
std::string getMacListFile() const
Returns location of the file containing list of MAC addresses.
int getReportDelay() const
Returns delay between two performance reports.
std::vector< int > getRandomOffset() const
Returns template offsets for rnd.
std::vector< double > getMaxDropPercentage() const
Returns maximal percentage of drops.
int getRemotePort() const
Returns remote port number.
Scenario getScenario() const
Returns selected scenario.
std::vector< std::string > getRelayAddrList() const
Returns list of relay addresses.
static const uint8_t RELAY_OPTIONS_MAX_ENCAPSULATION
Maximum allowed level of encapsulation of added relay options.
int getWaitForElapsedTime() const
Returns time to wait for elapsed time increase.
const MacAddrsVector & getMacsFromFile() const
Returns reference to a vector of MAC addresses read from a file.
bool isBroadcast() const
Checks if broadcast address is to be used.
std::vector< std::string > getTemplateFiles() const
Returns template file names.
std::vector< int > getTransactionIdOffset() const
brief Returns template offsets for xid.
std::vector< std::vector< uint8_t > > MacAddrsVector
A vector holding MAC addresses.
ExchangeMode
2-way (cmd line param -i) or 4-way exchanges
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.
std::vector< int > getNumRequests() const
Returns maximum number of exchanges.
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.
bool isSeeded() const
Checks if seed provided.
void reset()
Reset to defaults.
std::vector< double > getDropTime() const
Returns drop time.
std::vector< int > getMaxDrop() const
Returns maximum drops number.
int getPeriod() const
Returns test period.
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.
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.
std::vector< uint8_t > getMacTemplate() const
Returns MAC address template.
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:41
Defines the logger used by the top-level component of kea-lfc.