blob: 761365d083f3a03190bb803f91e454c4a1312a7a [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#include <ndn-cpp-dev/face.hpp>
2#include <ndn-cpp-dev/security/key-chain.hpp>
3#include <ndn-cpp-dev/util/scheduler.hpp>
4
5#include <cstdlib>
akmhoque92afde42014-02-18 14:04:07 -06006#include <string>
akmhoque298385a2014-02-13 14:13:09 -06007#include <sstream>
8
9#include "nlsr.hpp"
10#include "nlsr_conf_param.hpp"
11#include "nlsr_conf_processor.hpp"
12#include "nlsr_lsdb.hpp"
akmhoque92afde42014-02-18 14:04:07 -060013#include "nlsr_logger.hpp"
akmhoque298385a2014-02-13 14:13:09 -060014//test purpose of NLSR
15#include "nlsr_test.hpp"
16
akmhoqueb1710aa2014-02-19 17:13:36 -060017namespace nlsr {
18
akmhoque298385a2014-02-13 14:13:09 -060019using namespace ndn;
20using namespace std;
21
22void
akmhoque1a481092014-02-19 16:34:22 -060023Nlsr::nlsrRegistrationFailed(const ndn::Name& name)
akmhoque298385a2014-02-13 14:13:09 -060024{
25 cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
26 getNlsrFace().shutdown();
27}
28
29
30void
akmhoque1a481092014-02-19 16:34:22 -060031Nlsr::setInterestFilterNlsr(const string& name)
akmhoque298385a2014-02-13 14:13:09 -060032{
33 getNlsrFace().setInterestFilter(name,
34 func_lib::bind(&interestManager::processInterest, &im,
35 boost::ref(*this), _1, _2),
akmhoque1a481092014-02-19 16:34:22 -060036 func_lib::bind(&Nlsr::nlsrRegistrationFailed, this, _1));
akmhoque298385a2014-02-13 14:13:09 -060037}
38
39
40void
akmhoque1a481092014-02-19 16:34:22 -060041Nlsr::startEventLoop()
akmhoque298385a2014-02-13 14:13:09 -060042{
43 getNlsrFace().processEvents();
44}
45
46int
akmhoque1a481092014-02-19 16:34:22 -060047Nlsr::usage(const string& progname)
akmhoque298385a2014-02-13 14:13:09 -060048{
49
50 cout << "Usage: " << progname << " [OPTIONS...]"<<endl;
51 cout << " NDN routing...." << endl;
52 cout << " -d, --daemon Run in daemon mode" << endl;
53 cout << " -f, --config_file Specify configuration file name" <<endl;
54 cout << " -p, --api_port port where api client will connect" <<endl;
55 cout << " -h, --help Display this help message" << endl;
56
57 exit(EXIT_FAILURE);
58}
59
akmhoqueb1710aa2014-02-19 17:13:36 -060060
61} // namespace nlsr
62
63using namespace nlsr;
64
akmhoque298385a2014-02-13 14:13:09 -060065int
66main(int argc, char **argv){
akmhoqueb1710aa2014-02-19 17:13:36 -060067 nlsr::Nlsr nlsr_;
akmhoque298385a2014-02-13 14:13:09 -060068 string programName(argv[0]);
akmhoque1a481092014-02-19 16:34:22 -060069 nlsr_.setConfFileName("nlsr.conf");
akmhoque298385a2014-02-13 14:13:09 -060070
71 int opt;
72 while ((opt = getopt(argc, argv, "df:p:h")) != -1) {
73 switch (opt) {
74 case 'f':
akmhoque1a481092014-02-19 16:34:22 -060075 nlsr_.setConfFileName(optarg);
akmhoque298385a2014-02-13 14:13:09 -060076 break;
77 case 'd':
akmhoque1a481092014-02-19 16:34:22 -060078 nlsr_.setIsDaemonProcess(optarg);
akmhoque298385a2014-02-13 14:13:09 -060079 break;
80 case 'p':
81 {
82 stringstream sst(optarg);
83 int ap;
84 sst>>ap;
akmhoque1a481092014-02-19 16:34:22 -060085 nlsr_.setApiPort(ap);
akmhoque298385a2014-02-13 14:13:09 -060086 }
87 break;
88 case 'h':
89 default:
akmhoque1a481092014-02-19 16:34:22 -060090 nlsr_.usage(programName);
akmhoque298385a2014-02-13 14:13:09 -060091 return EXIT_FAILURE;
92 }
93 }
94
95
akmhoque1a481092014-02-19 16:34:22 -060096 ConfFileProcessor cfp(nlsr_.getConfFileName());
97 int res=cfp.processConfFile(nlsr_);
akmhoque298385a2014-02-13 14:13:09 -060098 if ( res < 0 )
99 {
100 return EXIT_FAILURE;
101 }
102
akmhoque1a481092014-02-19 16:34:22 -0600103 nlsr_.getConfParameter().buildRouterPrefix();
104 nlsr_.getNlsrLogger().initNlsrLogger(nlsr_.getConfParameter().getLogDir());
akmhoque92afde42014-02-18 14:04:07 -0600105 //src::logger lg;
106 //BOOST_LOG(lg) << "Some log record from nlsr.cpp";
107 //for(int j=0; j< 1000; j++)
108 //{
109 // BOOST_LOG(lg) << "Some log record from nlsr.cpp "<<j;
110 //}
akmhoque1a481092014-02-19 16:34:22 -0600111 nlsr_.getLsdb().setLsaRefreshTime(nlsr_.getConfParameter().getLsaRefreshTime());
112 nlsr_.getFib().setFibEntryRefreshTime(2*nlsr_.getConfParameter().getLsaRefreshTime());
113 nlsr_.getLsdb().setThisRouterPrefix(nlsr_.getConfParameter().getRouterPrefix());
akmhoque298385a2014-02-13 14:13:09 -0600114
115 /* debugging purpose start */
akmhoque1a481092014-02-19 16:34:22 -0600116 cout << nlsr_.getConfParameter();
117 nlsr_.getAdl().printAdl();
118 nlsr_.getNpl().printNpl();
akmhoque298385a2014-02-13 14:13:09 -0600119 /* debugging purpose end */
120
akmhoque1a481092014-02-19 16:34:22 -0600121 nlsr_.getLsdb().buildAndInstallOwnNameLsa(nlsr_);
122 nlsr_.getLsdb().buildAndInstallOwnCorLsa(nlsr_);
akmhoque298385a2014-02-13 14:13:09 -0600123
akmhoque92afde42014-02-18 14:04:07 -0600124
125
akmhoque298385a2014-02-13 14:13:09 -0600126
akmhoque1a481092014-02-19 16:34:22 -0600127 nlsr_.setInterestFilterNlsr(nlsr_.getConfParameter().getRouterPrefix());
128 nlsr_.getIm().scheduleInfoInterest(nlsr_,1);
akmhoque92afde42014-02-18 14:04:07 -0600129 //testing purpose
akmhoque1a481092014-02-19 16:34:22 -0600130 nlsr_.getNlsrTesting().schedlueAddingLsas(nlsr_);
akmhoque298385a2014-02-13 14:13:09 -0600131
132
133
134
135 try{
akmhoque1a481092014-02-19 16:34:22 -0600136 nlsr_.startEventLoop();
akmhoque298385a2014-02-13 14:13:09 -0600137 }catch(std::exception &e) {
138 std::cerr << "ERROR: " << e.what() << std::endl;
139 }
140
141 return EXIT_SUCCESS;
142}