Kea 1.5.0
command_options.h
Go to the documentation of this file.
1// Copyright (C) 2012-2018 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 <boost/noncopyable.hpp>
11
12#include <dhcp/option.h>
13#include <stdint.h>
14#include <string>
15#include <vector>
16
17namespace isc {
18namespace perfdhcp {
19
25class CommandOptions : public boost::noncopyable {
26public:
27
29 typedef std::vector<std::vector<uint8_t> > MacAddrsVector;
30
37 class LeaseType {
38 public:
39
41 enum Type {
45 };
46
47 LeaseType();
48
52 LeaseType(const Type lease_type);
53
59 bool is(const Type lease_type) const;
60
76 bool includes(const Type lease_type) const;
77
81 void set(const Type lease_type);
82
91 void fromCommandLine(const std::string& cmd_line_arg);
92
96 std::string toText() const;
97
98 private:
99 Type type_;
100
101 };
102
107 };
108
113 static CommandOptions& instance();
114
120 void reset();
121
132 bool parse(int argc, char** const argv, bool print_cmd_line = false);
133
137 uint8_t getIpVersion() const { return ipversion_; }
138
142 ExchangeMode getExchangeMode() const { return exchange_mode_; }
143
147 LeaseType getLeaseType() const { return (lease_type_); }
148
152 int getRate() const { return rate_; }
153
157 int getRenewRate() const { return (renew_rate_); }
158
162 int getReleaseRate() const { return (release_rate_); }
163
167 int getReportDelay() const { return report_delay_; }
168
172 uint32_t getClientsNum() const { return clients_num_; }
173
177 std::vector<uint8_t> getMacTemplate() const { return mac_template_; }
178
182 std::vector<uint8_t> getDuidTemplate() const { return duid_template_; }
183
187 std::vector<std::string> getBase() const { return base_; }
188
192 std::vector<int> getNumRequests() const { return num_request_; }
193
197 int getPeriod() const { return period_; }
198
205 std::vector<double> getDropTime() const { return drop_time_; }
206
213 std::vector<int> getMaxDrop() const { return max_drop_; }
214
221 std::vector<double> getMaxDropPercentage() const { return max_pdrop_; }
222
226 std::string getLocalName() const { return localname_; }
227
234 bool isInterface() const { return is_interface_; }
235
239 int getPreload() const { return preload_; }
240
244 int getAggressivity() const { return aggressivity_; }
245
249 int getLocalPort() const { return local_port_; }
250
254 int getExitWaitTime() const { return exit_wait_time_; }
255
259 bool isSeeded() const { return seeded_; }
260
264 uint32_t getSeed() const { return seed_; }
265
269 bool isBroadcast() const { return broadcast_; }
270
274 bool isRapidCommit() const { return rapid_commit_; }
275
279 bool isUseFirst() const { return use_first_; }
280
284 bool isUseRelayedV6() const { return (v6_relay_encapsulation_level_ > 0); }
285
289 std::vector<std::string> getTemplateFiles() const { return template_file_; }
290
297 std::string getMacListFile() const { return mac_list_file_; }
298
304 const MacAddrsVector& getMacsFromFile() const { return mac_list_; }
305
309 std::vector<int> getTransactionIdOffset() const { return xid_offset_; }
310
314 std::vector<int> getRandomOffset() const { return rnd_offset_; }
315
319 int getElapsedTimeOffset() const { return elp_offset_; }
320
324 int getServerIdOffset() const { return sid_offset_; }
325
329 int getRequestedIpOffset() const { return rip_offset_; }
330
334 std::string getDiags() const { return diags_; }
335
339 std::string getWrapped() const { return wrapped_; }
340
344 const isc::dhcp::OptionCollection& getExtraOpts() const { return extra_opts_; }
345
349 std::string getServerName() const { return server_name_; }
350
352 void printCommandLine() const;
353
357 void usage() const;
358
362 void version() const;
363
364private:
365
371 reset();
372 }
373
383 bool initialize(int argc, char** argv, bool print_cmd_line);
384
388 void validate() const;
389
398 inline void check(bool condition, const std::string& errmsg) const;
399
404 int positiveInteger(const std::string& errmsg) const;
405
410 int nonNegativeInteger(const std::string& errmsg) const;
411
416 std::string nonEmptyString(const std::string& errmsg) const;
417
421 void initLeaseType();
422
429 void initClientsNum();
430
436 void initIsInterface();
437
447 // Function will decode 00:01:02:03:04:05 and/or
453 void decodeBase(const std::string& base);
454
464 void decodeMacBase(const std::string& base);
465
475 void decodeDuid(const std::string& base);
476
483 void generateDuidTemplate();
484
489 uint8_t convertHexString(const std::string& hex_text) const;
490
493 void loadMacs();
494
497 bool decodeMacString(const std::string& line);
498
501 uint8_t ipversion_;
502
504 ExchangeMode exchange_mode_;
505
507 LeaseType lease_type_;
508
510 int rate_;
511
513 int renew_rate_;
514
516 int release_rate_;
517
519 int report_delay_;
520
522 uint32_t clients_num_;
523
526 std::vector<uint8_t> mac_template_;
527
530 std::vector<uint8_t> duid_template_;
531
534 std::vector<std::string> base_;
535
537 int exit_wait_time_;
538
540 std::vector<int> num_request_;
541
543 int period_;
544
547 uint8_t drop_time_set_;
548
552 std::vector<double> drop_time_;
553
558 std::vector<int> max_drop_;
559
563 std::vector<double> max_pdrop_;
564
566 std::string localname_;
567
570 bool is_interface_;
571
575 int preload_;
576
578 int aggressivity_;
579
581 int local_port_;
582
584 uint32_t seed_;
585
587 bool seeded_;
588
590 bool broadcast_;
591
593 bool rapid_commit_;
594
596 bool use_first_;
597
601 std::vector<std::string> template_file_;
602
608 std::string mac_list_file_;
609
611 std::vector<std::vector<uint8_t> > mac_list_;
612
617 std::vector<int> xid_offset_;
618
622 std::vector<int> rnd_offset_;
623
625 int elp_offset_;
626
628 int sid_offset_;
629
631 int rip_offset_;
632
635 std::string diags_;
636
639 std::string wrapped_;
640
642 std::string server_name_;
643
645 uint8_t v6_relay_encapsulation_level_;
646
648 isc::dhcp::OptionCollection extra_opts_;
649};
650
651} // namespace perfdhcp
652} // namespace isc
653
654#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...
int getAggressivity() const
Returns aggressivity value.
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.
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.
int getRate() const
Returns exchange rate.
void version() const
Print program version.
bool isRapidCommit() const
Check if rapid commit option used.
std::string getLocalName() const
Returns local address or interface name.
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.
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.
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.
static CommandOptions & instance()
CommandOptions is a singleton class.
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.
void usage() const
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.
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-dhcp-ddns.