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  : mgenMode(false),
28  iperfMode(false),
29  bindSocket(true),
30  tsftHistogram(false),
31  verbose(false),
32  csvMode(false),
33  reorderPackets(true),
34  promisc(false),
35  clockDrift(0.0f),
36  reorderTimeout(senf::ClockService::milliseconds(0)), // NetEmu default
37  reportingInterval(senf::ClockService::milliseconds(1000)),
38  duration(senf::ClockService::milliseconds(0)),
39  maxWait(senf::ClockService::milliseconds(0)),
40  device("mon0"),
41  monitorMode(true),
42  analyzeTx(false),
43  destination(5001),
44  numPackets(0)
45 {
46  namespace fty = senf::console::factory;
47  senf::console::DirectoryNode & initDir (senf::console::root().add("init", fty::Directory()));
48  initDir.add("help", fty::Command( &Configuration::help, this));
49  initDir.add("version", fty::Command( &Configuration::version, this));
50  initDir.add("realtime-scheduling", fty::Command( &Configuration::enableRealtimeScheduling, this));
51 
52  initDir.add("source", fty::Variable( source));
53  initDir.add("destination", fty::Variable( destination));
54  initDir.add("log-destination", fty::Variable( logDestination));
55  initDir.add("mgen-mode", fty::Variable( mgenMode));
56  initDir.add("iperf-mode", fty::Variable( iperfMode));
57  initDir.add("bind-socket", fty::Variable( bindSocket));
58  initDir.add("tsft-histogram", fty::Variable( tsftHistogram));
59  initDir.add("verbose", fty::Variable( verbose));
60  initDir.add("csv-mode", fty::Variable( csvMode));
61  initDir.add("clockDrift", fty::Variable( clockDrift)
62  .doc("Clock Drift between the nodes in ms/s (in MGEN mode). Defaults to 0."));
63  initDir.add("reporting-interval", fty::Variable( reportingInterval)
64  .parser(senf::parseClockServiceInterval) );
65  initDir.add("duration", fty::Variable( duration)
66  .parser(senf::parseClockServiceInterval) );
67  initDir.add("max-wait", fty::Variable( maxWait)
68  .parser(senf::parseClockServiceInterval) );
69  initDir.add("num-packets", fty::Variable( numPackets));
70  initDir.add("monitor-device", fty::Command( &Configuration::monDev, this));
71  initDir.add("device", fty::Command( &Configuration::dev, this));
72  initDir.add("analyze-tx", fty::Variable(analyzeTx));
73  initDir.add("reorder-packets", fty::Variable( reorderPackets));
74  initDir.add("reorder-timeout", fty::Variable( reorderTimeout)
75  .parser(senf::parseClockServiceInterval) );
76  initDir.add("promisc", fty::Variable( promisc));
77 
78  // always turn those on, where available
80 }
81 
83 {
84  senf::console::DirectoryNode::ChildrenRange range (senf::console::root()["init"].children());
85 
86  senf::console::DirectoryNode::ChildrenRange::iterator it;
87  for (it = range.begin(); it != range.end(); it++) {
88  std::cerr << it->first << ": ";
89  it->second->help( std::cout);
90  }
91 
92  exit(0);
93 }
94 
96 {
97  std::cerr << "2.0" << std::endl;
98  exit(0);
99 }
100 
101 prefix_ void Configuration::dev(std::string const & d)
102 {
103  device = d;
104  monitorMode = false;
105 }
106 
107 prefix_ void Configuration::monDev(std::string const & d)
108 {
109  device = d;
110  monitorMode = true;
111 }
112 
114 {
115  // switching to scheduler highres timer
116  if (senf::scheduler::haveScalableHiresTimers())
117  SENF_LOG((senf::log::IMPORTANT)("using 'timerfd' hi-res timer."));
118  else
119  SENF_LOG((senf::log::IMPORTANT)("using 'posix' hi-res timer."));
120  senf::scheduler::hiresTimers();
121 }
122 
124 {
125  // switching to kernel realtime scheduling
126  struct sched_param param;
127  param.sched_priority = sched_get_priority_max(SCHED_FIFO);
128  if (sched_setscheduler(0, SCHED_FIFO, &param) != 0) {
129  SENF_LOG((senf::log::IMPORTANT)("WARNING: unable to switch to realtime mode "));
130  } else {
131  mlockall(MCL_FUTURE);
132  SENF_LOG((senf::log::IMPORTANT) ("switching to realtime mode (SCHED_FIFO)"));
133  }
134 }
135 
136 prefix_ bool Configuration::parse(int argc, char const *argv[])
137 {
138  namespace fty = senf::console::factory;
139  namespace kw = senf::console::kw;
140  senf::console::DirectoryNode & initDir (senf::console::root()["init"]);
141 
142  senf::console::ProgramOptions cmdlineOptions ( argc, argv, initDir);
143 
144  try {
145  // now we parse the filled up configBundle
146  cmdlineOptions.parse( initDir);
147  } catch (senf::console::SyntaxErrorException const & e) {
148  std::cerr << e.message() << std::endl;
149  return false;
150  }
151  catch (senf::ExceptionMixin & ex) {
152  std::cerr << "Exception occurred during configuration parsing: "
153  << ex.message() << std::endl
154  << ex.backtrace() << std::endl;
155  return false;
156  }
157 
158  return true;
159 }
senf::ClockService::clock_type duration
senf::INet4SocketAddress destination
#define prefix_
senf::ClockService::clock_type maxWait
senf::INet4SocketAddress logDestination
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)
senf::ClockService::clock_type reorderTimeout
std::uint64_t numPackets
senf::ClockService::clock_type reportingInterval
bool parse(int argc, char const *argv[])
senf::INet4SocketAddress source
void enableHighresTimers()
std::string message() const
#define SENF_LOG(args)
std::string device
void enableRealtimeScheduling()
void monDev(std::string const &d)