Kea 3.2.0-git
perfdhcp/main.cc
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#include <config.h>
8
10#include <log/logger_support.h>
12#include <perfdhcp/basic_scen.h>
14#include <util/filesystem.h>
15
16#include <iostream>
17#include <stdint.h>
18
19using namespace isc::perfdhcp;
20
21int
22main(int argc, char* argv[]) {
24
25 int ret_code = 0;
26 std::string diags;
27 bool parser_error = true;
28 try {
29 CommandOptions command_options;
30 diags = command_options.getDiags();
31 // If parser returns true it means that user specified
32 // 'h' or 'v' command line option. Program shows the
33 // help or version message and exits here.
34 // The third argument indicates that the command line
35 // should be printed when it gets parsed. This is useful
36 // in particular when the command line needs to be
37 // extracted from the log file.
38 if (command_options.parse(argc, argv, true)) {
39 return (ret_code);
40 }
41 isc::log::initLogger("perfdhcp");
42 parser_error = false;
43 auto scenario = command_options.getScenario();
44 PerfSocket socket(command_options);
45 if (scenario == Scenario::BASIC) {
46 BasicScen scen(command_options, socket);
47 ret_code = scen.run();
48 } else if (scenario == Scenario::AVALANCHE) {
49 AvalancheScen scen(command_options, socket);
50 ret_code = scen.run();
51 }
52 } catch (const std::exception& e) {
53 ret_code = 1;
54 if (!parser_error) {
55 std::cerr << std::endl << "ERROR: running perfdhcp: "
56 << e.what() << std::endl;
57 } else {
59 std::cerr << std::endl << "ERROR: parsing command line options: "
60 << e.what() << std::endl;
61 }
62 if (diags.find('e') != std::string::npos) {
63 std::cerr << "Fatal error" << std::endl;
64 }
65 } catch (...) {
66 ret_code = 1;
67 if (!parser_error) {
68 std::cerr << std::endl << "ERROR: running perfdhcp"
69 << std::endl;
70 } else {
72 std::cerr << std::endl << "ERROR: parsing command line options"
73 << std::endl;
74 }
75 if (diags.find('e') != std::string::npos) {
76 std::cerr << "Fatal error" << std::endl;
77 }
78 }
79 return (ret_code);
80}
Avalanche Scenario class.
int run() override
brief\ Run performance test.
Basic Scenario class.
Definition basic_scen.h:23
int run() override
brief\ Run performance test.
Scenario getScenario() const
Returns selected scenario.
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.
Socket wrapper structure.
Definition perf_socket.h:64
Logging initialization functions.
void initLogger(const string &root, isc::log::Severity severity, int dbglevel, const char *file, bool buffer)
Run-time initialization.
void setUmask()
Set umask (at least 0027 i.e. no group write and no other access).
Definition filesystem.cc:98
int main(int argc, char *argv[])