blob: 49886e0c01a625400f0e8d3bac6e9f7b200f7b20 [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
51 cout << "Usage: " << progname << " [OPTIONS...]"<<endl;
52 cout << " NDN routing...." << endl;
53 cout << " -d, --daemon Run in daemon mode" << endl;
54 cout << " -f, --config_file Specify configuration file name" <<endl;
55 cout << " -p, --api_port port where api client will connect" <<endl;
56 cout << " -h, --help Display this help message" << endl;
57
58 exit(EXIT_FAILURE);
akmhoque1fd8c1e2014-02-19 19:41:49 -060059 }
akmhoque298385a2014-02-13 14:13:09 -060060
akmhoqueb1710aa2014-02-19 17:13:36 -060061
62} // namespace nlsr
63
64using namespace nlsr;
65
akmhoque1fd8c1e2014-02-19 19:41:49 -060066int
67main(int argc, char **argv)
68{
69 nlsr::Nlsr nlsr_;
70 string programName(argv[0]);
71 nlsr_.setConfFileName("nlsr.conf");
akmhoque298385a2014-02-13 14:13:09 -060072
akmhoque1fd8c1e2014-02-19 19:41:49 -060073 int opt;
74 while ((opt = getopt(argc, argv, "df:p:h")) != -1)
75 {
76 switch (opt)
77 {
78 case 'f':
79 nlsr_.setConfFileName(optarg);
80 break;
81 case 'd':
82 nlsr_.setIsDaemonProcess(optarg);
83 break;
84 case 'p':
85 {
86 stringstream sst(optarg);
87 int ap;
88 sst>>ap;
89 nlsr_.setApiPort(ap);
90 }
91 break;
92 case 'h':
93 default:
94 nlsr_.usage(programName);
95 return EXIT_FAILURE;
96 }
akmhoque298385a2014-02-13 14:13:09 -060097 }
akmhoque298385a2014-02-13 14:13:09 -060098
akmhoque298385a2014-02-13 14:13:09 -060099
akmhoque1fd8c1e2014-02-19 19:41:49 -0600100 ConfFileProcessor cfp(nlsr_.getConfFileName());
101 int res=cfp.processConfFile(nlsr_);
102 if ( res < 0 )
103 {
104 return EXIT_FAILURE;
105 }
akmhoque298385a2014-02-13 14:13:09 -0600106
akmhoque1fd8c1e2014-02-19 19:41:49 -0600107 nlsr_.getConfParameter().buildRouterPrefix();
108 nlsr_.getNlsrLogger().initNlsrLogger(nlsr_.getConfParameter().getLogDir());
109 //src::logger lg;
110 //BOOST_LOG(lg) << "Some log record from nlsr.cpp";
111 //for(int j=0; j< 1000; j++)
112 //{
113 // BOOST_LOG(lg) << "Some log record from nlsr.cpp "<<j;
114 //}
115 nlsr_.getLsdb().setLsaRefreshTime(nlsr_.getConfParameter().getLsaRefreshTime());
116 nlsr_.getFib().setFibEntryRefreshTime(
117 2*nlsr_.getConfParameter().getLsaRefreshTime());
118 nlsr_.getLsdb().setThisRouterPrefix(nlsr_.getConfParameter().getRouterPrefix());
akmhoque298385a2014-02-13 14:13:09 -0600119
akmhoque1fd8c1e2014-02-19 19:41:49 -0600120 /* debugging purpose start */
121 cout << nlsr_.getConfParameter();
122 nlsr_.getAdl().printAdl();
123 nlsr_.getNpl().printNpl();
124 /* debugging purpose end */
akmhoque298385a2014-02-13 14:13:09 -0600125
akmhoque1fd8c1e2014-02-19 19:41:49 -0600126 nlsr_.getLsdb().buildAndInstallOwnNameLsa(nlsr_);
127 nlsr_.getLsdb().buildAndInstallOwnCorLsa(nlsr_);
akmhoque298385a2014-02-13 14:13:09 -0600128
akmhoque298385a2014-02-13 14:13:09 -0600129
akmhoque1fd8c1e2014-02-19 19:41:49 -0600130
131
132 nlsr_.setInterestFilterNlsr(nlsr_.getConfParameter().getRouterPrefix());
133 nlsr_.getIm().scheduleInfoInterest(nlsr_,1);
134 //testing purpose
135 nlsr_.getNlsrTesting().schedlueAddingLsas(nlsr_);
136
137
138
139
140 try
141 {
142 nlsr_.startEventLoop();
143 }
144 catch(std::exception &e)
145 {
146 std::cerr << "ERROR: " << e.what() << std::endl;
147 }
148
149 return EXIT_SUCCESS;
akmhoque298385a2014-02-13 14:13:09 -0600150}