nlsr-runner.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "nlsr-runner.hpp"
23 
24 #include "conf-file-processor.hpp"
25 #include "logger.hpp"
26 
27 namespace nlsr {
28 
29 INIT_LOGGER("NlsrRunner");
30 
31 NlsrRunner::NlsrRunner(std::string& configFileName, bool isDaemonProcess)
32  : m_scheduler(m_ioService)
33  , m_face(m_ioService)
34  , m_nlsr(m_ioService, m_scheduler, m_face, m_keyChain)
35 {
36  m_nlsr.setConfFileName(configFileName);
37  m_nlsr.setIsDaemonProcess(isDaemonProcess);
38 }
39 
40 void
42 {
43  ConfFileProcessor configProcessor(m_nlsr, m_nlsr.getConfFileName());
44 
45  if (!configProcessor.processConfFile()) {
46  BOOST_THROW_EXCEPTION(Error("Error in configuration file processing! Exiting from NLSR"));
47  }
48 
51  }
52  else {
54  }
55 
56  if (m_nlsr.getIsSetDaemonProcess()) {
57  m_nlsr.daemonize();
58  }
59 
64  m_nlsr.canonizeNeighborUris(m_nlsr.getAdjacencyList().getAdjList().begin(),
65  [this] (std::list<Adjacent>::iterator iterator) {
66  m_nlsr.canonizeContinuation(iterator, [this] {
67  m_nlsr.initialize();
68  });
69  },
70  [this] {
71  m_nlsr.initialize();
72  });
73  try {
74  m_nlsr.startEventLoop();
75  }
76  catch (const std::exception& e) {
77  NLSR_LOG_FATAL("ERROR: " << e.what());
78  std::cerr << "ERROR: " << e.what() << std::endl;
79 
80  m_nlsr.getFib().clean();
81  }
82 }
83 
84 void
85 NlsrRunner::printUsage(const std::string& programName)
86 {
87  std::cout << "Usage: " << programName << " [OPTIONS...]" << std::endl;
88  std::cout << " NDN routing...." << std::endl;
89  std::cout << " -d Run in daemon mode" << std::endl;
90  std::cout << " -f <FILE> Specify configuration file name" << std::endl;
91  std::cout << " -V Display version information" << std::endl;
92  std::cout << " -h Display this help message" << std::endl;
93 }
94 
95 } // namespace nlsr
std::string getConfFileName() const
Definition: nlsr.hpp:109
void initialize()
Definition: nlsr.cpp:235
void INIT_LOG4CXX(const std::string &log4cxxConfPath)
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
Definition: logger.cpp:36
ConfParameter & getConfParameter()
Definition: nlsr.hpp:133
void setIsDaemonProcess(bool value)
Definition: nlsr.hpp:127
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
bool getIsSetDaemonProcess()
Definition: nlsr.hpp:121
const std::string & getLogLevel() const
const std::string & getLog4CxxConfPath() const
#define INIT_LOGGER(name)
Definition: logger.hpp:35
void canonizeNeighborUris(std::list< Adjacent >::iterator currentNeighbor, std::function< void(std::list< Adjacent >::iterator)> then, std::function< void(void)> finally)
Canonize the URI for this and all proceeding neighbors in a list.
Definition: nlsr.cpp:196
AdjacencyList & getAdjacencyList()
Definition: nlsr.hpp:139
void daemonize()
Definition: nlsr.cpp:160
void clean()
Remove all entries from the FIB.
Definition: fib.cpp:154
void setConfFileName(const std::string &fileName)
Definition: nlsr.hpp:115
A class containing methods to parse an NLSR configuration file.
NlsrRunner(std::string &configFileName, bool isDaemonProcess)
Definition: nlsr-runner.cpp:31
bool isLog4CxxConfAvailable() const
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
void run()
Instantiate, configure, and start the NLSR process.
Definition: nlsr-runner.cpp:41
void startEventLoop()
Definition: nlsr.cpp:655
static void printUsage(const std::string &programName)
Definition: nlsr-runner.cpp:85
void INIT_LOGGERS(const std::string &logDir, const std::string &logLevel)
Definition: logger.cpp:47
#define NLSR_LOG_FATAL(x)
Definition: logger.hpp:53
Fib & getFib()
Definition: nlsr.hpp:175
const std::string & getLogDir() const
std::list< Adjacent > & getAdjList()