Kea  1.9.9-git
perfdhcp/main.cc
Go to the documentation of this file.
1 // Copyright (C) 2012-2020 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 #include <config.h>
8 
10 #include <perfdhcp/basic_scen.h>
12 
13 #include <exceptions/exceptions.h>
14 
15 #include <iostream>
16 #include <stdint.h>
17 
18 using namespace isc::perfdhcp;
19 
20 int
21 main(int argc, char* argv[]) {
22  CommandOptions command_options;
23  std::string diags(command_options.getDiags());
24  int ret_code = 0;
25  try {
26  // If parser returns true it means that user specified
27  // 'h' or 'v' command line option. Program shows the
28  // help or version message and exits here.
29  // The third argument indicates that the command line
30  // should be printed when it gets parsed. This is useful
31  // in particular when the command line needs to be
32  // extracted from the log file.
33  if (command_options.parse(argc, argv, true)) {
34  return (ret_code);
35  }
36  } catch (const isc::Exception& e) {
37  ret_code = 1;
38  command_options.usage();
39  std::cerr << "\nERROR: parsing command line options: "
40  << e.what() << std::endl;
41  if (diags.find('e') != std::string::npos) {
42  std::cerr << "Fatal error" << std::endl;
43  }
44  return (ret_code);
45  }
46  try{
47  auto scenario = command_options.getScenario();
48  PerfSocket socket(command_options);
49  if (scenario == Scenario::BASIC) {
50  BasicScen scen(command_options, socket);
51  ret_code = scen.run();
52  } else if (scenario == Scenario::AVALANCHE) {
53  AvalancheScen scen(command_options, socket);
54  ret_code = scen.run();
55  }
56  } catch (const std::exception& e) {
57  ret_code = 1;
58  std::cerr << "\nERROR: running perfdhcp: " << e.what() << std::endl;
59  if (diags.find('e') != std::string::npos) {
60  std::cerr << "Fatal error" << std::endl;
61  }
62  }
63  return (ret_code);
64 }
bool parse(int argc, char **const argv, bool print_cmd_line=false)
Parse command line.
Scenario getScenario() const
Returns selected scenario.
Socket wrapper structure.
Definition: perf_socket.h:64
Basic Scenario class.
Definition: basic_scen.h:23
std::string getDiags() const
Returns diagnostic selectors.
int main(int argc, char *argv[])
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
int run() override
brief\ Run performance test.
This is a base class for exceptions thrown from the DNS library module.
int run() override
brief\ Run performance test.
Definition: basic_scen.cc:126
void usage() const
Print usage.
Avalanche Scenario class.