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 extern "C" {
15  #include <sched.h>
16  #include <sys/mman.h>
17  #include <sys/utsname.h>
18 }
19 
20 // Custom includes
21 #include <senf/Utils/membind.hh>
22 #include <senf/Utils/hexdump.hh>
23 #include <senf/Utils/Logger.hh>
24 #include <senf/Utils/Console.hh>
26 #include "Configuration.hh"
27 
28 #define prefix_
29 //-/////////////////////////////////////////////////////////////////////////////////////////////////
30 
32  verbose( false),
33  numBuffers(128),
34  interface( "mon0"),
35  logSeqNoErrors(false)
36 {
37  namespace fty = senf::console::factory;
38  namespace kw = senf::console::kw;
39  senf::console::DirectoryNode & initDir (senf::console::root().add("init", fty::Directory()));
40  initDir.add("help", fty::Command( &Configuration::help, this));
41  initDir.add("version", fty::Command( &Configuration::version, this));
42  initDir.add("realtime-scheduling", fty::Command( &Configuration::enableRealtimeScheduling, this));
43  initDir.add("verbose", fty::Variable( verbose));
44  initDir.add("num-buffers", fty::Variable( numBuffers));
45  initDir.add("interface", fty::Variable( interface));
46  initDir.add("monitor-interface", fty::Variable( monitorInterface));
47  initDir.add("output-interface", fty::Variable( outputInterface));
48  initDir.add("log-seqno-errors", fty::Variable( logSeqNoErrors));
49 
50  // always turn those on, where available
51  enableHighresTimers();
52 }
53 
55 {
56  senf::console::DirectoryNode::ChildrenRange range(senf::console::root()["init"].children());
57 
58  senf::console::DirectoryNode::ChildrenRange::iterator it;
59  for (it = range.begin(); it != range.end(); it++) {
60  std::cerr << it->first << ": ";
61  it->second->help( std::cout);
62  }
63 
64  exit(0);
65 }
66 
68 {
69  std::cerr << "0.1" << std::endl;
70  exit(0);
71 }
72 
74 {
75  // switching to scheduler highres timer
76  if (senf::scheduler::haveScalableHiresTimers())
77  SENF_LOG((senf::log::IMPORTANT)("using 'timerfd' hi-res timer."));
78  else
79  SENF_LOG((senf::log::IMPORTANT)("using 'posix' hi-res timer."));
80  senf::scheduler::hiresTimers();
81 }
82 
84 {
85  // switching to kernel realtime scheduling
86  struct sched_param param;
87  param.sched_priority = sched_get_priority_max(SCHED_FIFO);
88  if (sched_setscheduler(0, SCHED_FIFO, &param) !=0 ) {
89  SENF_LOG((senf::log::IMPORTANT)("WARNING: unable to switch to realtime mode "));
90  } else {
91  mlockall(MCL_FUTURE);
92  SENF_LOG((senf::log::IMPORTANT) ("switching to realtime mode (SCHED_FIFO)"));
93  }
94 }
95 
96 prefix_ bool Configuration::parse( int argc, char const *argv[])
97 {
98  namespace fty = senf::console::factory;
99  namespace kw = senf::console::kw;
100  senf::console::DirectoryNode & initDir (senf::console::root()["init"]);
101 
102  senf::console::ProgramOptions cmdlineOptions ( argc, argv, initDir);
103 
104  try {
105  // now we parse the filled up configBundle
106  cmdlineOptions.parse( initDir);
107  } catch (senf::console::SyntaxErrorException const & e) {
108  std::cerr << e.message() << std::endl;
109  return false;
110  }
111  catch (senf::ExceptionMixin & ex) {
112  std::cerr << "Exception occurred during configuration parsing: "
113  << ex.message() << std::endl
114  << ex.backtrace() << std::endl;
115  return false;
116  }
117 
118  return true;
119 }
std::string backtrace() const
boost::iterator_range< ChildMap::const_iterator > ChildrenRange
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)
#define prefix_
bool parse(int argc, char const *argv[])
void enableHighresTimers()
std::string message() const
#define SENF_LOG(args)
void enableRealtimeScheduling()