blob: fe4ba01ca45b9998723e65ca1ebb8f23fd4d72f8 [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
akmhoque1fd8c1e2014-02-19 19:41:49 -060015#include "nlsr_test.hpp"
akmhoque298385a2014-02-13 14:13:09 -060016
akmhoque1fd8c1e2014-02-19 19:41:49 -060017namespace nlsr
akmhoque298385a2014-02-13 14:13:09 -060018{
akmhoque1fd8c1e2014-02-19 19:41:49 -060019
20 using namespace ndn;
21 using namespace std;
22
23 void
24 Nlsr::nlsrRegistrationFailed(const ndn::Name& name)
25 {
26 cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
27 getNlsrFace().shutdown();
28 }
akmhoque298385a2014-02-13 14:13:09 -060029
30
akmhoque1fd8c1e2014-02-19 19:41:49 -060031 void
32 Nlsr::setInterestFilterNlsr(const string& name)
33 {
34 getNlsrFace().setInterestFilter(name,
35 func_lib::bind(&interestManager::processInterest, &im,
36 boost::ref(*this), _1, _2),
37 func_lib::bind(&Nlsr::nlsrRegistrationFailed, this, _1));
38 }
akmhoque298385a2014-02-13 14:13:09 -060039
40
akmhoque1fd8c1e2014-02-19 19:41:49 -060041 void
42 Nlsr::startEventLoop()
43 {
44 getNlsrFace().processEvents();
45 }
akmhoque298385a2014-02-13 14:13:09 -060046
akmhoque1fd8c1e2014-02-19 19:41:49 -060047 int
48 Nlsr::usage(const string& progname)
49 {
akmhoque298385a2014-02-13 14:13:09 -060050 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;
akmhoque298385a2014-02-13 14:13:09 -060056 exit(EXIT_FAILURE);
akmhoque1fd8c1e2014-02-19 19:41:49 -060057 }
akmhoque298385a2014-02-13 14:13:09 -060058
akmhoqueb1710aa2014-02-19 17:13:36 -060059
60} // namespace nlsr
61
62using namespace nlsr;
63
akmhoque1fd8c1e2014-02-19 19:41:49 -060064int
65main(int argc, char **argv)
66{
67 nlsr::Nlsr nlsr_;
68 string programName(argv[0]);
69 nlsr_.setConfFileName("nlsr.conf");
akmhoque1fd8c1e2014-02-19 19:41:49 -060070 int opt;
71 while ((opt = getopt(argc, argv, "df:p:h")) != -1)
72 {
73 switch (opt)
74 {
75 case 'f':
76 nlsr_.setConfFileName(optarg);
77 break;
78 case 'd':
79 nlsr_.setIsDaemonProcess(optarg);
80 break;
81 case 'p':
82 {
83 stringstream sst(optarg);
84 int ap;
85 sst>>ap;
86 nlsr_.setApiPort(ap);
87 }
88 break;
89 case 'h':
90 default:
91 nlsr_.usage(programName);
92 return EXIT_FAILURE;
93 }
akmhoque298385a2014-02-13 14:13:09 -060094 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060095 ConfFileProcessor cfp(nlsr_.getConfFileName());
96 int res=cfp.processConfFile(nlsr_);
97 if ( res < 0 )
98 {
99 return EXIT_FAILURE;
100 }
akmhoque1fd8c1e2014-02-19 19:41:49 -0600101 nlsr_.getConfParameter().buildRouterPrefix();
102 nlsr_.getNlsrLogger().initNlsrLogger(nlsr_.getConfParameter().getLogDir());
103 //src::logger lg;
104 //BOOST_LOG(lg) << "Some log record from nlsr.cpp";
105 //for(int j=0; j< 1000; j++)
106 //{
107 // BOOST_LOG(lg) << "Some log record from nlsr.cpp "<<j;
108 //}
109 nlsr_.getLsdb().setLsaRefreshTime(nlsr_.getConfParameter().getLsaRefreshTime());
110 nlsr_.getFib().setFibEntryRefreshTime(
111 2*nlsr_.getConfParameter().getLsaRefreshTime());
112 nlsr_.getLsdb().setThisRouterPrefix(nlsr_.getConfParameter().getRouterPrefix());
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}