Kea 3.1.0
perfdhcp/main.cc
Go to the documentation of this file.
1// Copyright (C) 2012-2025 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
9#include <util/filesystem.h>
11#include <perfdhcp/basic_scen.h>
13
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 parser_error = false;
42 auto scenario = command_options.getScenario();
43 PerfSocket socket(command_options);
44 if (scenario == Scenario::BASIC) {
45 BasicScen scen(command_options, socket);
46 ret_code = scen.run();
47 } else if (scenario == Scenario::AVALANCHE) {
48 AvalancheScen scen(command_options, socket);
49 ret_code = scen.run();
50 }
51 } catch (const std::exception& e) {
52 ret_code = 1;
53 if (!parser_error) {
54 std::cerr << std::endl << "ERROR: running perfdhcp: "
55 << e.what() << std::endl;
56 } else {
58 std::cerr << std::endl << "ERROR: parsing command line options: "
59 << e.what() << std::endl;
60 }
61 if (diags.find('e') != std::string::npos) {
62 std::cerr << "Fatal error" << std::endl;
63 }
64 } catch (...) {
65 ret_code = 1;
66 if (!parser_error) {
67 std::cerr << std::endl << "ERROR: running perfdhcp"
68 << std::endl;
69 } else {
71 std::cerr << std::endl << "ERROR: parsing command line options"
72 << std::endl;
73 }
74 if (diags.find('e') != std::string::npos) {
75 std::cerr << "Fatal error" << std::endl;
76 }
77 }
78 return (ret_code);
79}
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
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[])