blob: 3ca2279120d6c032b11760e70b080a5a90be5d8c [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>
akmhoque298385a2014-02-13 14:13:09 -06004#include <cstdlib>
akmhoque92afde42014-02-18 14:04:07 -06005#include <string>
akmhoque298385a2014-02-13 14:13:09 -06006#include <sstream>
7
8#include "nlsr.hpp"
9#include "nlsr_conf_param.hpp"
10#include "nlsr_conf_processor.hpp"
11#include "nlsr_lsdb.hpp"
akmhoque92afde42014-02-18 14:04:07 -060012#include "nlsr_logger.hpp"
akmhoque298385a2014-02-13 14:13:09 -060013//test purpose of NLSR
akmhoque1fd8c1e2014-02-19 19:41:49 -060014#include "nlsr_test.hpp"
akmhoque298385a2014-02-13 14:13:09 -060015
akmhoque1fd8c1e2014-02-19 19:41:49 -060016namespace nlsr
akmhoque298385a2014-02-13 14:13:09 -060017{
akmhoque1fd8c1e2014-02-19 19:41:49 -060018
19 using namespace ndn;
20 using namespace std;
21
22 void
23 Nlsr::nlsrRegistrationFailed(const ndn::Name& name)
24 {
25 cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
26 getNlsrFace().shutdown();
27 }
akmhoque298385a2014-02-13 14:13:09 -060028
29
akmhoque1fd8c1e2014-02-19 19:41:49 -060030 void
31 Nlsr::setInterestFilterNlsr(const string& name)
32 {
33 getNlsrFace().setInterestFilter(name,
34 func_lib::bind(&interestManager::processInterest, &im,
35 boost::ref(*this), _1, _2),
36 func_lib::bind(&Nlsr::nlsrRegistrationFailed, this, _1));
37 }
akmhoque298385a2014-02-13 14:13:09 -060038
39
akmhoque1fd8c1e2014-02-19 19:41:49 -060040 void
41 Nlsr::startEventLoop()
42 {
43 getNlsrFace().processEvents();
44 }
akmhoque298385a2014-02-13 14:13:09 -060045
akmhoque1fd8c1e2014-02-19 19:41:49 -060046 int
47 Nlsr::usage(const string& progname)
48 {
akmhoque298385a2014-02-13 14:13:09 -060049 cout << "Usage: " << progname << " [OPTIONS...]"<<endl;
50 cout << " NDN routing...." << endl;
51 cout << " -d, --daemon Run in daemon mode" << endl;
52 cout << " -f, --config_file Specify configuration file name" <<endl;
53 cout << " -p, --api_port port where api client will connect" <<endl;
54 cout << " -h, --help Display this help message" << endl;
akmhoque298385a2014-02-13 14:13:09 -060055 exit(EXIT_FAILURE);
akmhoque1fd8c1e2014-02-19 19:41:49 -060056 }
akmhoque298385a2014-02-13 14:13:09 -060057
akmhoqueb1710aa2014-02-19 17:13:36 -060058
59} // namespace nlsr
60
61using namespace nlsr;
62
akmhoque1fd8c1e2014-02-19 19:41:49 -060063int
64main(int argc, char **argv)
65{
66 nlsr::Nlsr nlsr_;
67 string programName(argv[0]);
68 nlsr_.setConfFileName("nlsr.conf");
akmhoque1fd8c1e2014-02-19 19:41:49 -060069 int opt;
70 while ((opt = getopt(argc, argv, "df:p:h")) != -1)
71 {
72 switch (opt)
73 {
74 case 'f':
75 nlsr_.setConfFileName(optarg);
76 break;
77 case 'd':
78 nlsr_.setIsDaemonProcess(optarg);
79 break;
80 case 'p':
81 {
82 stringstream sst(optarg);
83 int ap;
84 sst>>ap;
85 nlsr_.setApiPort(ap);
86 }
87 break;
88 case 'h':
89 default:
90 nlsr_.usage(programName);
91 return EXIT_FAILURE;
92 }
akmhoque298385a2014-02-13 14:13:09 -060093 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060094 ConfFileProcessor cfp(nlsr_.getConfFileName());
95 int res=cfp.processConfFile(nlsr_);
96 if ( res < 0 )
97 {
98 return EXIT_FAILURE;
99 }
akmhoque1fd8c1e2014-02-19 19:41:49 -0600100 nlsr_.getConfParameter().buildRouterPrefix();
101 nlsr_.getNlsrLogger().initNlsrLogger(nlsr_.getConfParameter().getLogDir());
102 //src::logger lg;
103 //BOOST_LOG(lg) << "Some log record from nlsr.cpp";
104 //for(int j=0; j< 1000; j++)
105 //{
106 // BOOST_LOG(lg) << "Some log record from nlsr.cpp "<<j;
107 //}
108 nlsr_.getLsdb().setLsaRefreshTime(nlsr_.getConfParameter().getLsaRefreshTime());
109 nlsr_.getFib().setFibEntryRefreshTime(
akmhoque66e66182014-02-21 17:56:03 -0600110 2*nlsr_.getConfParameter().getLsaRefreshTime());
akmhoque1fd8c1e2014-02-19 19:41:49 -0600111 nlsr_.getLsdb().setThisRouterPrefix(nlsr_.getConfParameter().getRouterPrefix());
akmhoque66e66182014-02-21 17:56:03 -0600112 nlsr_.getKeyManager().initKeyManager(nlsr_.getConfParameter());
akmhoque1fd8c1e2014-02-19 19:41:49 -0600113 /* debugging purpose start */
114 cout << nlsr_.getConfParameter();
115 nlsr_.getAdl().printAdl();
116 nlsr_.getNpl().printNpl();
117 /* debugging purpose end */
akmhoque1fd8c1e2014-02-19 19:41:49 -0600118 nlsr_.getLsdb().buildAndInstallOwnNameLsa(nlsr_);
119 nlsr_.getLsdb().buildAndInstallOwnCorLsa(nlsr_);
akmhoque1fd8c1e2014-02-19 19:41:49 -0600120 nlsr_.setInterestFilterNlsr(nlsr_.getConfParameter().getRouterPrefix());
121 nlsr_.getIm().scheduleInfoInterest(nlsr_,1);
122 //testing purpose
123 nlsr_.getNlsrTesting().schedlueAddingLsas(nlsr_);
akmhoque1fd8c1e2014-02-19 19:41:49 -0600124 try
125 {
126 nlsr_.startEventLoop();
127 }
128 catch(std::exception &e)
129 {
130 std::cerr << "ERROR: " << e.what() << std::endl;
131 }
akmhoque1fd8c1e2014-02-19 19:41:49 -0600132 return EXIT_SUCCESS;
akmhoque298385a2014-02-13 14:13:09 -0600133}