bmv2
Designing your own switch target with bmv2
Loading...
Searching...
No Matches
options_parse.h
1/* Copyright 2013-present Barefoot Networks, Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/*
17 * Antonin Bas (antonin@barefootnetworks.com)
18 *
19 */
20
21/* TODO(antonin): does this code really belong in this module */
22
23#ifndef BM_BM_SIM_OPTIONS_PARSE_H_
24#define BM_BM_SIM_OPTIONS_PARSE_H_
25
26#include <iosfwd>
27#include <map>
28#include <string>
29#include <unordered_set>
30
31#include "device_id.h"
32#include "logger.h"
33#include "target_parser.h"
34
35namespace bm {
36
37class InterfaceList {
38 public:
39 using iterator = std::map<uint32_t, std::string>::iterator;
40 using const_iterator = std::map<uint32_t, std::string>::const_iterator;
41
42 public:
43 void add(uint32_t port, const std::string &iface) {
44 ifaces[port] = iface;
45 }
46 bool empty() { return ifaces.empty(); }
47 void clear() { ifaces.clear(); }
48 // iterators
49 iterator begin() { return ifaces.begin(); }
50 const_iterator begin() const { return ifaces.begin(); }
51 iterator end() { return ifaces.end(); }
52 const_iterator end() const { return ifaces.end(); }
53 iterator find(uint32_t port) { return ifaces.find(port); }
54 const_iterator find(uint32_t port) const { return ifaces.find(port); }
55
56 private:
57 std::map<uint32_t, std::string> ifaces{};
58};
59
60class OptionsParser {
61 public:
62 static constexpr int default_max_port_count = 512;
63
64 void parse(int argc, char *argv[], TargetParserIface *tp,
65 // NOLINTNEXTLINE(runtime/references)
66 std::ostream &outstream);
67
68 void parse(int argc, char *argv[], TargetParserIface *tp);
69
70 bool option_was_provided(const std::string &option) const;
71
72 std::string config_file_path{};
73 bool no_p4{false};
74 InterfaceList ifaces{};
75 bool pcap{false};
76 std::string pcap_dir{};
77 int thrift_port{0};
78 device_id_t device_id{};
79 // if true read/write packets from files instead of interfaces
80 bool use_files{false};
81 // time to wait (in seconds) before starting packet processing
82 int wait_time{0};
83 // if true read/write packets from nanomsg socket instead of interfaces
84 bool packet_in{false};
85 std::string packet_in_addr{};
86 std::string event_logger_addr{};
87 std::string file_logger{};
88 bool console_logging{false};
89 // by default everything is logged
90 Logger::LogLevel log_level{Logger::LogLevel::TRACE};
91 // by default file logs are not "force-flushed" to disk
92 bool log_flush{false};
93 // max size of a single log file (in bytes) before rotation
94 size_t log_max_size{1024 * 1024 * 5};
95 // number of rotated backup log files to keep
96 size_t log_max_files{3};
97 std::string notifications_addr{};
98 bool debugger{false};
99 std::string debugger_addr{};
100 std::string state_file_path{};
101 size_t dump_packet_data{0};
102 int max_port_count{default_max_port_count};
103 std::unordered_set<std::string> options_provided{};
104};
105
106} // namespace bm
107
108#endif // BM_BM_SIM_OPTIONS_PARSE_H_
LogLevel
Different log levels.
Definition logger.h:63