Configuration.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 #include "Configuration.hh"
15 
16 // Custom includes
17 extern "C" {
18  #include <sys/mman.h>
19 }
21 #include <senf/Utils/Console.hh>
22 
23 #define prefix_
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
27  : verbose(false),
28  iface("phy0"),
29  frequency(5180),
30  ht40(false),
31  peer(senf::MACAddress::None),
32  label((rand() % 0xffff) << 4),
33  txBuf(192000),
34  qlen(768),
35  maxBurst(48),
36  bitrate(0), // default mode is RX
37  reportingInterval(senf::ClockService::milliseconds(1000)),
38  duration(senf::ClockService::seconds(0)),
39  consolePort(23232)
40 {
41  namespace fty = senf::console::factory;
42  senf::console::DirectoryNode & initDir (senf::console::root().add("init", fty::Directory()));
43  initDir.add("help", fty::Command(&Configuration::help, this));
44  initDir.add("version", fty::Command(&Configuration::version, this));
45  initDir.add("realtime-scheduling", fty::Command(&Configuration::enableRealtimeScheduling, this));
46 
47  initDir.add("verbose", fty::Variable(verbose));
48 
49  initDir.add("iface", fty::Variable(iface));
50  initDir.add("frequency", fty::Variable(frequency));
51  initDir.add("ht40", fty::Variable(ht40));
52 
53  initDir.add("peer", fty::Variable(peer));
54  initDir.add("label", fty::Variable(label));
55 
56  initDir.add("txBuf", fty::Variable(txBuf));
57  initDir.add("qlen", fty::Variable(qlen));
58  initDir.add("maxBurst", fty::Variable(maxBurst));
59 
60  initDir.add("bitrate", fty::Variable(bitrate));
61 
62  initDir.add("reporting-interval", fty::Variable( reportingInterval)
63  .parser(senf::parseClockServiceInterval));
64  initDir.add("duration", fty::Variable(duration)
65  .parser(senf::parseClockServiceInterval));
66 
67  initDir.add("consolePort", fty::Variable(consolePort));
68 
69  // always turn those on, where available
70  enableHighresTimers();
71 }
72 
74 {
75  senf::console::DirectoryNode::ChildrenRange range (senf::console::root()["init"].children());
76 
77  senf::console::DirectoryNode::ChildrenRange::iterator it;
78  for (it = range.begin(); it != range.end(); it++) {
79  std::cerr << it->first << ": ";
80  it->second->help( std::cout);
81  }
82 
83  exit(0);
84 }
85 
87 {
88  std::cerr << "1.0" << std::endl;
89  exit(0);
90 }
91 
93 {
94  // switching to scheduler highres timer
95  if (senf::scheduler::haveScalableHiresTimers())
96  SENF_LOG((senf::log::IMPORTANT)("using 'timerfd' hi-res timer."));
97  else
98  SENF_LOG((senf::log::IMPORTANT)("using 'posix' hi-res timer."));
99  senf::scheduler::hiresTimers();
100 }
101 
103 {
104  // switching to kernel realtime scheduling
105  struct sched_param param;
106  param.sched_priority = sched_get_priority_max(SCHED_FIFO);
107  if (sched_setscheduler(0, SCHED_FIFO, &param) != 0) {
108  SENF_LOG((senf::log::IMPORTANT)("WARNING: unable to switch to realtime mode "));
109  } else {
110  mlockall(MCL_FUTURE);
111  SENF_LOG((senf::log::IMPORTANT) ("switching to realtime mode (SCHED_FIFO)"));
112  }
113 }
114 
115 prefix_ bool Configuration::parse(int argc, char const *argv[])
116 {
117  namespace fty = senf::console::factory;
118  namespace kw = senf::console::kw;
119  senf::console::DirectoryNode & initDir (senf::console::root()["init"]);
120 
121  senf::console::ProgramOptions cmdlineOptions ( argc, argv, initDir);
122 
123  try {
124  // now we parse the filled up configBundle
125  cmdlineOptions.parse( initDir);
126  } catch (senf::console::SyntaxErrorException const & e) {
127  std::cerr << e.message() << std::endl;
128  return false;
129  }
130  catch (senf::ExceptionMixin & ex) {
131  std::cerr << "Exception occurred during configuration parsing: "
132  << ex.message() << std::endl
133  << ex.backtrace() << std::endl;
134  return false;
135  }
136 
137  return true;
138 }
unspecified_keyword_type parser
StatsDataCollectorKernel bitrate
std::string backtrace() const
boost::iterator_range< ChildMap::const_iterator > ChildrenRange
#define prefix_
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)
bool parse(int argc, char const *argv[])
void enableHighresTimers()
std::string message() const
#define SENF_LOG(args)
void enableRealtimeScheduling()