Kea 2.2.0
command_options.h
Go to the documentation of this file.
1// Copyright (C) 2012-2021 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
17namespace isc {
18namespace perfdhcp {
19
20enum class Scenario {
21 BASIC,
23};
24
30class CommandOptions : public boost::noncopyable {
31public:
32
38 reset();
39 }
40
42 typedef std::vector<std::vector<uint8_t> > MacAddrsVector;
43
50 class LeaseType {
51 public:
52
54 enum Type {
58 };
59
60 LeaseType();
61
65 LeaseType(const Type lease_type);
66
72 bool is(const Type lease_type) const;
73
89 bool includes(const Type lease_type) const;
90
94 void set(const Type lease_type);
95
104 void fromCommandLine(const std::string& cmd_line_arg);
105
109 std::string toText() const;
110
111 private:
112 Type type_;
113
114 };
115
120 };
121
127 void reset();
128
139 bool parse(int argc, char** const argv, bool print_cmd_line = false);
140
144 uint8_t getIpVersion() const { return ipversion_; }
145
149 ExchangeMode getExchangeMode() const { return exchange_mode_; }
150
154 LeaseType getLeaseType() const { return (lease_type_); }
155
159 int getRate() const { return rate_; }
160
164 int getRenewRate() const { return (renew_rate_); }
165
169 int getReleaseRate() const { return (release_rate_); }
170
174 int getReportDelay() const { return report_delay_; }
175
179 int getCleanReport() const { return clean_report_; }
180
184 std::string getCleanReportSeparator() const { return clean_report_separator_; }
185
189 uint32_t getClientsNum() const { return clients_num_; }
190
194 std::vector<uint8_t> getMacTemplate() const { return mac_template_; }
195
199 std::vector<uint8_t> getDuidTemplate() const { return duid_template_; }
200
204 std::vector<std::string> getBase() const { return base_; }
205
209 bool getAddrUnique() const { return addr_unique_; }
210
214 std::vector<int> getNumRequests() const { return num_request_; }
215
219 int getPeriod() const { return period_; }
220
225 int getWaitForElapsedTime() const { return wait_for_elapsed_time_; }
226
231 int getIncreaseElapsedTime() const { return increased_elapsed_time_; }
232
239 std::vector<double> getDropTime() const { return drop_time_; }
240
247 std::vector<int> getMaxDrop() const { return max_drop_; }
248
255 std::vector<double> getMaxDropPercentage() const { return max_pdrop_; }
256
260 std::string getLocalName() const { return localname_; }
261
268 bool isInterface() const { return is_interface_; }
269
273 int getPreload() const { return preload_; }
274
278 int getLocalPort() const { return local_port_; }
279
283 int getRemotePort() const { return remote_port_; }
284
288 int getExitWaitTime() const { return exit_wait_time_; }
289
293 bool isSeeded() const { return seeded_; }
294
298 uint32_t getSeed() const { return seed_; }
299
303 bool isBroadcast() const { return broadcast_; }
304
308 bool isRapidCommit() const { return rapid_commit_; }
309
313 bool isUseFirst() const { return use_first_; }
314
318 bool isUseRelayedV6() const { return (v6_relay_encapsulation_level_ > 0); }
319
323 std::vector<std::string> getTemplateFiles() const { return template_file_; }
324
331 std::string getMacListFile() const { return mac_list_file_; }
332
338 const MacAddrsVector& getMacsFromFile() const { return mac_list_; }
339
343 std::vector<int> getTransactionIdOffset() const { return xid_offset_; }
344
348 std::vector<int> getRandomOffset() const { return rnd_offset_; }
349
353 int getElapsedTimeOffset() const { return elp_offset_; }
354
358 int getServerIdOffset() const { return sid_offset_; }
359
363 int getRequestedIpOffset() const { return rip_offset_; }
364
368 std::string getDiags() const { return diags_; }
369
373 std::string getWrapped() const { return wrapped_; }
374
378 const isc::dhcp::OptionCollection& getExtraOpts() const { return extra_opts_; }
379
383 bool isSingleThreaded() const { return single_thread_mode_; }
384
388 Scenario getScenario() const { return scenario_; }
389
393 std::string getServerName() const { return server_name_; }
394
398 std::string getRelayAddrListFile() const { return relay_addr_list_file_; }
399
403 std::vector<std::string> getRelayAddrList() const { return relay_addr_list_; }
404
408 std::string getRandRelayAddr() { return relay_addr_list_[rand() % relay_addr_list_.size()]; }
409
413 bool checkMultiSubnet() { return multi_subnet_; }
414
419 bool testDiags(const char diag) {
420 if (getDiags().find(diag) != std::string::npos) {
421 return (true);
422 }
423 return (false);
424 }
425
427 void printCommandLine() const;
428
432 static void usage();
433
437 void version() const;
438
439private:
449 bool initialize(int argc, char** argv, bool print_cmd_line);
450
457 void validate();
458
467 inline void check(bool condition, const std::string& errmsg) const;
468
473 int positiveInteger(const std::string& errmsg) const;
474
479 int nonNegativeInteger(const std::string& errmsg) const;
480
485 std::string nonEmptyString(const std::string& errmsg) const;
486
490 void initLeaseType();
491
498 void initClientsNum();
499
505 void initIsInterface();
506
516 // Function will decode 00:01:02:03:04:05 and/or
522 void decodeBase(const std::string& base);
523
533 void decodeMacBase(const std::string& base);
534
544 void decodeDuid(const std::string& base);
545
552 void generateDuidTemplate();
553
558 uint8_t convertHexString(const std::string& hex_text) const;
559
562 void loadMacs();
563
566 bool decodeMacString(const std::string& line);
567
569 void loadRelayAddr();
570
575 bool validateIP(const std::string& line);
576
579 uint8_t ipversion_;
580
582 ExchangeMode exchange_mode_;
583
585 LeaseType lease_type_;
586
588 unsigned int rate_;
589
591 unsigned int renew_rate_;
592
594 unsigned int release_rate_;
595
597 int report_delay_;
598
600 bool clean_report_;
601
603 std::string clean_report_separator_;
604
606 uint32_t clients_num_;
607
610 std::vector<uint8_t> mac_template_;
611
614 std::vector<uint8_t> duid_template_;
615
617 bool addr_unique_;
618
621 std::vector<std::string> base_;
622
624 int exit_wait_time_;
625
627 std::vector<int> num_request_;
628
630 int period_;
631
632 // for how long perfdhcp will wait before start sending
633 // messages with increased elapsed time.
634 int wait_for_elapsed_time_;
635
636 // Amount of time after which perfdhcp will send messages with
637 // elapsed time increased.
638 int increased_elapsed_time_;
639
642 uint8_t drop_time_set_;
643
647 std::vector<double> drop_time_;
648
653 std::vector<int> max_drop_;
654
658 std::vector<double> max_pdrop_;
659
661 std::string localname_;
662
665 bool is_interface_;
666
670 int preload_;
671
673 int local_port_;
674
676 int remote_port_;
677
679 uint32_t seed_;
680
682 bool seeded_;
683
685 bool broadcast_;
686
688 bool rapid_commit_;
689
691 bool use_first_;
692
696 std::vector<std::string> template_file_;
697
703 std::string mac_list_file_;
704
706 std::vector<std::vector<uint8_t> > mac_list_;
707
709 std::string relay_addr_list_file_;
710
712 std::vector<std::string> relay_addr_list_;
713
715 bool multi_subnet_;
716
721 std::vector<int> xid_offset_;
722
726 std::vector<int> rnd_offset_;
727
729 int elp_offset_;
730
732 int sid_offset_;
733
735 int rip_offset_;
736
739 std::string diags_;
740
743 std::string wrapped_;
744
746 std::string server_name_;
747
749 uint8_t v6_relay_encapsulation_level_;
750
752 isc::dhcp::OptionCollection extra_opts_;
753
755 bool single_thread_mode_;
756
758 Scenario scenario_;
759};
760
761} // namespace perfdhcp
762} // namespace isc
763
764#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.
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.
int getWaitForElapsedTime() const
Returns time to wait for elapsed time increase.
ExchangeMode
2-way (cmd line param -i) or 4-way exchanges
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.
int getElapsedTimeOffset() const
Returns template offset for elapsed time.
std::string getServerName() const
Returns server name.
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:40
Defines the logger used by the top-level component of kea-lfc.