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  : tsftHistogram(false),
28  verbose(false),
29  csvMode(false),
30  reorderPackets(true),
31  promisc(true),
32  clockDrift(0.0f),
33  reorderTimeout(senf::ClockService::milliseconds(0)), // NetEmu default
34  reportingInterval(senf::ClockService::milliseconds(1000)),
35  duration(senf::ClockService::milliseconds(0)),
36  maxWait(senf::ClockService::milliseconds(0)),
37  device("mon0"),
38  numPackets(0)
39 {
40  namespace fty = senf::console::factory;
41  senf::console::DirectoryNode & initDir (senf::console::root().add("init", fty::Directory()));
42  initDir.add("help", fty::Command( &Configuration::help, this));
43  initDir.add("version", fty::Command( &Configuration::version, this));
44  initDir.add("realtime-scheduling", fty::Command( &Configuration::enableRealtimeScheduling, this));
45 
46  initDir.add("log-destination", fty::Variable( logDestination));
47  initDir.add("tsft-histogram", fty::Variable( tsftHistogram));
48  initDir.add("verbose", fty::Variable( verbose));
49  initDir.add("csv-mode", fty::Variable( csvMode));
50  initDir.add("clockDrift", fty::Variable( clockDrift)
51  .doc("Clock Drift between the nodes in ms/s (in MGEN mode). Defaults to 0."));
52  initDir.add("reporting-interval", fty::Variable( reportingInterval)
53  .parser(senf::parseClockServiceInterval) );
54  initDir.add("duration", fty::Variable( duration)
55  .parser(senf::parseClockServiceInterval) );
56  initDir.add("max-wait", fty::Variable( maxWait)
57  .parser(senf::parseClockServiceInterval) );
58  initDir.add("num-packets", fty::Variable( numPackets));
59  initDir.add("device", fty::Command( &Configuration::dev, this));
60  initDir.add("reorder-packets", fty::Variable( reorderPackets));
61  initDir.add("reorder-timeout", fty::Variable( reorderTimeout)
62  .parser(senf::parseClockServiceInterval) );
63  initDir.add("promisc", fty::Variable( promisc));
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 << "2.0" << std::endl;
85  exit(0);
86 }
87 
88 prefix_ void Configuration::dev(std::string const & d)
89 {
90  device = d;
91 }
92 
94 {
95  // switching to scheduler highres timer
96  if (senf::scheduler::haveScalableHiresTimers())
97  SENF_LOG((senf::log::IMPORTANT)("using 'timerfd' hi-res timer."));
98  else
99  SENF_LOG((senf::log::IMPORTANT)("using 'posix' hi-res timer."));
100  senf::scheduler::hiresTimers();
101 }
102 
104 {
105  // switching to kernel realtime scheduling
106  struct sched_param param;
107  param.sched_priority = sched_get_priority_max(SCHED_FIFO);
108  if (sched_setscheduler(0, SCHED_FIFO, &param) != 0) {
109  SENF_LOG((senf::log::IMPORTANT)("WARNING: unable to switch to realtime mode "));
110  } else {
111  mlockall(MCL_FUTURE);
112  SENF_LOG((senf::log::IMPORTANT) ("switching to realtime mode (SCHED_FIFO)"));
113  }
114 }
115 
116 prefix_ bool Configuration::parse(int argc, char const *argv[])
117 {
118  namespace fty = senf::console::factory;
119  namespace kw = senf::console::kw;
120  senf::console::DirectoryNode & initDir (senf::console::root()["init"]);
121 
122  senf::console::ProgramOptions cmdlineOptions ( argc, argv, initDir);
123 
124  try {
125  // now we parse the filled up configBundle
126  cmdlineOptions.parse( initDir);
127  } catch (senf::console::SyntaxErrorException const & e) {
128  std::cerr << e.message() << std::endl;
129  return false;
130  }
131  catch (senf::ExceptionMixin & ex) {
132  std::cerr << "Exception occurred during configuration parsing: "
133  << ex.message() << std::endl
134  << ex.backtrace() << std::endl;
135  return false;
136  }
137 
138  return true;
139 }
#define prefix_
unspecified_keyword_type parser
void dev(std::string const &d)
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)
std::string device
void enableRealtimeScheduling()