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  reportingInterval(senf::ClockService::milliseconds(1000)),
30  duration(senf::ClockService::seconds(10)),
31  frequency(5180),
32  ht40(false),
33  rateIdx(0),
34  destination(senf::MACAddress::Broadcast),
35  txPeriod(senf::ClockService::microseconds(0)),
36  txDuration(senf::ClockService::microseconds(0)),
37  txPower(10),
38  txFrameLength(2304),
39  sndBuf(txFrameLength * 8)
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("reporting-interval", fty::Variable( reportingInterval)
50  .parser(senf::parseClockServiceInterval));
51  initDir.add("duration", fty::Variable(duration)
52  .parser(senf::parseClockServiceInterval));
53 
54  initDir.add("frequency", fty::Variable(frequency));
55  initDir.add("ht40", fty::Variable(ht40));
56  initDir.add("rateIdx", fty::Variable(rateIdx));
57 
58  initDir.add("destination", fty::Variable(destination));
59 
60  initDir.add("tx-period", fty::Variable(txPeriod)
61  .parser(senf::parseClockServiceInterval));
62  initDir.add("tx-duration", fty::Variable(txDuration)
63  .parser(senf::parseClockServiceInterval));
64  initDir.add("tx-power", fty::Variable(txPower));
65  initDir.add("tx-frame-length", fty::Variable(txFrameLength));
66 
67  initDir.add("sndBuf", fty::Variable(sndBuf));
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.2" << 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 }
#define prefix_
unspecified_keyword_type parser
std::string backtrace() const
boost::iterator_range< ChildMap::const_iterator > ChildrenRange
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()