blob: 444063a9b828bd4f025cc3570614d0e6746dda87 [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
21nlsr::nlsrRegistrationFailed(const ndn::Name& name)
22{
23 cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
24 getNlsrFace().shutdown();
25}
26
27
28void
29nlsr::setInterestFilterNlsr(const string& name)
30{
31 getNlsrFace().setInterestFilter(name,
32 func_lib::bind(&interestManager::processInterest, &im,
33 boost::ref(*this), _1, _2),
34 func_lib::bind(&nlsr::nlsrRegistrationFailed, this, _1));
35}
36
37
38void
39nlsr::startEventLoop()
40{
41 getNlsrFace().processEvents();
42}
43
44int
45nlsr::usage(const string& progname)
46{
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){
60 nlsr nlsr;
61 string programName(argv[0]);
62 nlsr.setConfFileName("nlsr.conf");
63
64 int opt;
65 while ((opt = getopt(argc, argv, "df:p:h")) != -1) {
66 switch (opt) {
67 case 'f':
68 nlsr.setConfFileName(optarg);
69 break;
70 case 'd':
71 nlsr.setIsDaemonProcess(optarg);
72 break;
73 case 'p':
74 {
75 stringstream sst(optarg);
76 int ap;
77 sst>>ap;
78 nlsr.setApiPort(ap);
79 }
80 break;
81 case 'h':
82 default:
83 nlsr.usage(programName);
84 return EXIT_FAILURE;
85 }
86 }
87
88
89 ConfFileProcessor cfp(nlsr.getConfFileName());
90 int res=cfp.processConfFile(nlsr);
91 if ( res < 0 )
92 {
93 return EXIT_FAILURE;
94 }
95
96 nlsr.getConfParameter().buildRouterPrefix();
akmhoqueee79e462014-02-17 21:17:52 -060097 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 //}
akmhoque298385a2014-02-13 14:13:09 -0600104 nlsr.getLsdb().setLsaRefreshTime(nlsr.getConfParameter().getLsaRefreshTime());
105 nlsr.getFib().setFibEntryRefreshTime(2*nlsr.getConfParameter().getLsaRefreshTime());
akmhoque298385a2014-02-13 14:13:09 -0600106 nlsr.getLsdb().setThisRouterPrefix(nlsr.getConfParameter().getRouterPrefix());
107
108 /* debugging purpose start */
109 cout << nlsr.getConfParameter();
110 nlsr.getAdl().printAdl();
111 nlsr.getNpl().printNpl();
112 /* debugging purpose end */
113
114 nlsr.getLsdb().buildAndInstallOwnNameLsa(nlsr);
115 nlsr.getLsdb().buildAndInstallOwnCorLsa(nlsr);
116
akmhoque92afde42014-02-18 14:04:07 -0600117
118
akmhoque298385a2014-02-13 14:13:09 -0600119
120 nlsr.setInterestFilterNlsr(nlsr.getConfParameter().getRouterPrefix());
121 nlsr.getIm().scheduleInfoInterest(nlsr,1);
akmhoque92afde42014-02-18 14:04:07 -0600122 //testing purpose
123 nlsr.getNlsrTesting().schedlueAddingLsas(nlsr);
akmhoque298385a2014-02-13 14:13:09 -0600124
125
126
127
128 try{
129 nlsr.startEventLoop();
130 }catch(std::exception &e) {
131 std::cerr << "ERROR: " << e.what() << std::endl;
132 }
133
134 return EXIT_SUCCESS;
135}