blob: a8b1cb8ab537a6c2c8e0204e84872d6077685b84 [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
17using namespace ndn;
18using namespace std;
19
20void
akmhoque1a481092014-02-19 16:34:22 -060021Nlsr::nlsrRegistrationFailed(const ndn::Name& name)
akmhoque298385a2014-02-13 14:13:09 -060022{
23 cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
24 getNlsrFace().shutdown();
25}
26
27
28void
akmhoque1a481092014-02-19 16:34:22 -060029Nlsr::setInterestFilterNlsr(const string& name)
akmhoque298385a2014-02-13 14:13:09 -060030{
31 getNlsrFace().setInterestFilter(name,
32 func_lib::bind(&interestManager::processInterest, &im,
33 boost::ref(*this), _1, _2),
akmhoque1a481092014-02-19 16:34:22 -060034 func_lib::bind(&Nlsr::nlsrRegistrationFailed, this, _1));
akmhoque298385a2014-02-13 14:13:09 -060035}
36
37
38void
akmhoque1a481092014-02-19 16:34:22 -060039Nlsr::startEventLoop()
akmhoque298385a2014-02-13 14:13:09 -060040{
41 getNlsrFace().processEvents();
42}
43
44int
akmhoque1a481092014-02-19 16:34:22 -060045Nlsr::usage(const string& progname)
akmhoque298385a2014-02-13 14:13:09 -060046{
47
48 cout << "Usage: " << progname << " [OPTIONS...]"<<endl;
49 cout << " NDN routing...." << endl;
50 cout << " -d, --daemon Run in daemon mode" << endl;
51 cout << " -f, --config_file Specify configuration file name" <<endl;
52 cout << " -p, --api_port port where api client will connect" <<endl;
53 cout << " -h, --help Display this help message" << endl;
54
55 exit(EXIT_FAILURE);
56}
57
58int
59main(int argc, char **argv){
akmhoque1a481092014-02-19 16:34:22 -060060 Nlsr nlsr_;
akmhoque298385a2014-02-13 14:13:09 -060061 string programName(argv[0]);
akmhoque1a481092014-02-19 16:34:22 -060062 nlsr_.setConfFileName("nlsr.conf");
akmhoque298385a2014-02-13 14:13:09 -060063
64 int opt;
65 while ((opt = getopt(argc, argv, "df:p:h")) != -1) {
66 switch (opt) {
67 case 'f':
akmhoque1a481092014-02-19 16:34:22 -060068 nlsr_.setConfFileName(optarg);
akmhoque298385a2014-02-13 14:13:09 -060069 break;
70 case 'd':
akmhoque1a481092014-02-19 16:34:22 -060071 nlsr_.setIsDaemonProcess(optarg);
akmhoque298385a2014-02-13 14:13:09 -060072 break;
73 case 'p':
74 {
75 stringstream sst(optarg);
76 int ap;
77 sst>>ap;
akmhoque1a481092014-02-19 16:34:22 -060078 nlsr_.setApiPort(ap);
akmhoque298385a2014-02-13 14:13:09 -060079 }
80 break;
81 case 'h':
82 default:
akmhoque1a481092014-02-19 16:34:22 -060083 nlsr_.usage(programName);
akmhoque298385a2014-02-13 14:13:09 -060084 return EXIT_FAILURE;
85 }
86 }
87
88
akmhoque1a481092014-02-19 16:34:22 -060089 ConfFileProcessor cfp(nlsr_.getConfFileName());
90 int res=cfp.processConfFile(nlsr_);
akmhoque298385a2014-02-13 14:13:09 -060091 if ( res < 0 )
92 {
93 return EXIT_FAILURE;
94 }
95
akmhoque1a481092014-02-19 16:34:22 -060096 nlsr_.getConfParameter().buildRouterPrefix();
97 nlsr_.getNlsrLogger().initNlsrLogger(nlsr_.getConfParameter().getLogDir());
akmhoque92afde42014-02-18 14:04:07 -060098 //src::logger lg;
99 //BOOST_LOG(lg) << "Some log record from nlsr.cpp";
100 //for(int j=0; j< 1000; j++)
101 //{
102 // BOOST_LOG(lg) << "Some log record from nlsr.cpp "<<j;
103 //}
akmhoque1a481092014-02-19 16:34:22 -0600104 nlsr_.getLsdb().setLsaRefreshTime(nlsr_.getConfParameter().getLsaRefreshTime());
105 nlsr_.getFib().setFibEntryRefreshTime(2*nlsr_.getConfParameter().getLsaRefreshTime());
106 nlsr_.getLsdb().setThisRouterPrefix(nlsr_.getConfParameter().getRouterPrefix());
akmhoque298385a2014-02-13 14:13:09 -0600107
108 /* debugging purpose start */
akmhoque1a481092014-02-19 16:34:22 -0600109 cout << nlsr_.getConfParameter();
110 nlsr_.getAdl().printAdl();
111 nlsr_.getNpl().printNpl();
akmhoque298385a2014-02-13 14:13:09 -0600112 /* debugging purpose end */
113
akmhoque1a481092014-02-19 16:34:22 -0600114 nlsr_.getLsdb().buildAndInstallOwnNameLsa(nlsr_);
115 nlsr_.getLsdb().buildAndInstallOwnCorLsa(nlsr_);
akmhoque298385a2014-02-13 14:13:09 -0600116
akmhoque92afde42014-02-18 14:04:07 -0600117
118
akmhoque298385a2014-02-13 14:13:09 -0600119
akmhoque1a481092014-02-19 16:34:22 -0600120 nlsr_.setInterestFilterNlsr(nlsr_.getConfParameter().getRouterPrefix());
121 nlsr_.getIm().scheduleInfoInterest(nlsr_,1);
akmhoque92afde42014-02-18 14:04:07 -0600122 //testing purpose
akmhoque1a481092014-02-19 16:34:22 -0600123 nlsr_.getNlsrTesting().schedlueAddingLsas(nlsr_);
akmhoque298385a2014-02-13 14:13:09 -0600124
125
126
127
128 try{
akmhoque1a481092014-02-19 16:34:22 -0600129 nlsr_.startEventLoop();
akmhoque298385a2014-02-13 14:13:09 -0600130 }catch(std::exception &e) {
131 std::cerr << "ERROR: " << e.what() << std::endl;
132 }
133
134 return EXIT_SUCCESS;
135}