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  phyName("phy0"),
29  debugFS("/sys/kernel/debug"),
30  reportingInterval(senf::ClockService::milliseconds(1000)),
31  duration(senf::ClockService::seconds(10)),
32  frequency(5180),
33  ht40(false),
34  spectralPeriod(0x08),
35  spectralFFTPeriod(0x02),
36  spectralCount(0),
37  spectralBins(64),
38  spectralEndless(false),
39  spectralShortRepeat(true)
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  initDir.add("phy-name", fty::Variable(phyName));
49  initDir.add("debug-fs", fty::Variable(debugFS));
50  initDir.add("reporting-interval", fty::Variable( reportingInterval)
51  .parser(senf::parseClockServiceInterval));
52  initDir.add("duration", fty::Variable(duration)
53  .parser(senf::parseClockServiceInterval));
54 
55  initDir.add("frequency", fty::Variable(frequency));
56  initDir.add("ht40", fty::Variable(ht40));
57 
58  initDir.add("spectral-period", fty::Variable(spectralPeriod));
59  initDir.add("spectral-fft-period", fty::Variable(spectralFFTPeriod));
60  initDir.add("spectral-bins", fty::Variable(spectralBins));
61  initDir.add("spectral-count", fty::Variable(spectralCount));
62  initDir.add("spectral-endless", fty::Variable(spectralEndless));
63  initDir.add("spectral-short-repeat", fty::Variable(spectralShortRepeat));
64 
65  // always turn those on, where available
66  enableHighresTimers();
67 }
68 
70 {
71  senf::console::DirectoryNode::ChildrenRange range (senf::console::root()["init"].children());
72 
73  senf::console::DirectoryNode::ChildrenRange::iterator it;
74  for (it = range.begin(); it != range.end(); it++) {
75  std::cerr << it->first << ": ";
76  it->second->help( std::cout);
77  }
78 
79  exit(0);
80 }
81 
83 {
84  std::cerr << "1.2" << std::endl;
85  exit(0);
86 }
87 
89 {
90  // switching to scheduler highres timer
91  if (senf::scheduler::haveScalableHiresTimers())
92  SENF_LOG((senf::log::IMPORTANT)("using 'timerfd' hi-res timer."));
93  else
94  SENF_LOG((senf::log::IMPORTANT)("using 'posix' hi-res timer."));
95  senf::scheduler::hiresTimers();
96 }
97 
99 {
100  // switching to kernel realtime scheduling
101  struct sched_param param;
102  param.sched_priority = sched_get_priority_max(SCHED_FIFO);
103  if (sched_setscheduler(0, SCHED_FIFO, &param) != 0) {
104  SENF_LOG((senf::log::IMPORTANT)("WARNING: unable to switch to realtime mode "));
105  } else {
106  mlockall(MCL_FUTURE);
107  SENF_LOG((senf::log::IMPORTANT) ("switching to realtime mode (SCHED_FIFO)"));
108  }
109 }
110 
111 prefix_ bool Configuration::parse(int argc, char const *argv[])
112 {
113  namespace fty = senf::console::factory;
114  namespace kw = senf::console::kw;
115  senf::console::DirectoryNode & initDir (senf::console::root()["init"]);
116 
117  senf::console::ProgramOptions cmdlineOptions ( argc, argv, initDir);
118 
119  try {
120  // now we parse the filled up configBundle
121  cmdlineOptions.parse( initDir);
122  } catch (senf::console::SyntaxErrorException const & e) {
123  std::cerr << e.message() << std::endl;
124  return false;
125  }
126  catch (senf::ExceptionMixin & ex) {
127  std::cerr << "Exception occurred during configuration parsing: "
128  << ex.message() << std::endl
129  << ex.backtrace() << std::endl;
130  return false;
131  }
132 
133  return true;
134 }
unspecified_keyword_type parser
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()