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 #include "conf-file-processor.hpp"
24 #include "logger.hpp"
25 
26 namespace nlsr {
27 
28 INIT_LOGGER(NlsrRunner);
29 
30 NlsrRunner::NlsrRunner(std::string& configFileName)
31  : m_scheduler(m_ioService)
32  , m_face(m_ioService)
33  , m_nlsr(m_ioService, m_scheduler, m_face, m_keyChain)
34 {
35  m_nlsr.setConfFileName(configFileName);
36 }
37 
38 void
40 {
41  ConfFileProcessor configProcessor(m_nlsr, m_nlsr.getConfFileName());
42 
43  if (!configProcessor.processConfFile()) {
44  BOOST_THROW_EXCEPTION(Error("Error in configuration file processing! Exiting from NLSR"));
45  }
46 
51  m_nlsr.canonizeNeighborUris(m_nlsr.getAdjacencyList().getAdjList().begin(),
52  [this] (std::list<Adjacent>::iterator iterator) {
53  m_nlsr.canonizeContinuation(iterator, [this] {
54  m_nlsr.initialize();
55  });
56  },
57  [this] {
58  m_nlsr.initialize();
59  });
60  try {
61  m_nlsr.startEventLoop();
62  }
63  catch (const std::exception& e) {
64  NLSR_LOG_FATAL("ERROR: " << e.what());
65  std::cerr << "ERROR: " << e.what() << std::endl;
66 
67  m_nlsr.getFib().clean();
68  }
69 }
70 
71 void
72 NlsrRunner::printUsage(const std::string& programName)
73 {
74  std::cout << "Usage: " << programName << " [OPTIONS...]" << std::endl;
75  std::cout << " NDN routing...." << std::endl;
76  std::cout << " -f <FILE> Specify configuration file name" << std::endl;
77  std::cout << " -V Display version information" << std::endl;
78  std::cout << " -h Display this help message" << std::endl;
79 }
80 
81 } // namespace nlsr
std::string getConfFileName() const
Definition: nlsr.hpp:109
void initialize()
Definition: nlsr.cpp:250
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#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:162
AdjacencyList & getAdjacencyList()
Definition: nlsr.hpp:133
NlsrRunner(std::string &configFileName)
Definition: nlsr-runner.cpp:30
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.
Copyright (c) 2014-2018, 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:39
void startEventLoop()
Definition: nlsr.cpp:679
static void printUsage(const std::string &programName)
Definition: nlsr-runner.cpp:72
#define NLSR_LOG_FATAL(x)
Definition: logger.hpp:42
Fib & getFib()
Definition: nlsr.hpp:181
std::list< Adjacent > & getAdjList()