blob: 569a40a7ca179ef914cc947d2cfdf1e72a4c2372 [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>
6#include<string>
7#include <sstream>
8
9#include "nlsr.hpp"
10#include "nlsr_conf_param.hpp"
11#include "nlsr_conf_processor.hpp"
12#include "nlsr_lsdb.hpp"
13//test purpose of NLSR
14#include "nlsr_test.hpp"
15
16using namespace ndn;
17using namespace std;
18
19void
20nlsr::nlsrRegistrationFailed(const ndn::Name& name)
21{
22 cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
23 getNlsrFace().shutdown();
24}
25
26
27void
28nlsr::setInterestFilterNlsr(const string& name)
29{
30 getNlsrFace().setInterestFilter(name,
31 func_lib::bind(&interestManager::processInterest, &im,
32 boost::ref(*this), _1, _2),
33 func_lib::bind(&nlsr::nlsrRegistrationFailed, this, _1));
34}
35
36
37void
38nlsr::startEventLoop()
39{
40 getNlsrFace().processEvents();
41}
42
43int
44nlsr::usage(const string& progname)
45{
46
47 cout << "Usage: " << progname << " [OPTIONS...]"<<endl;
48 cout << " NDN routing...." << endl;
49 cout << " -d, --daemon Run in daemon mode" << endl;
50 cout << " -f, --config_file Specify configuration file name" <<endl;
51 cout << " -p, --api_port port where api client will connect" <<endl;
52 cout << " -h, --help Display this help message" << endl;
53
54 exit(EXIT_FAILURE);
55}
56
57int
58main(int argc, char **argv){
59 nlsr nlsr;
60 string programName(argv[0]);
61 nlsr.setConfFileName("nlsr.conf");
62
63 int opt;
64 while ((opt = getopt(argc, argv, "df:p:h")) != -1) {
65 switch (opt) {
66 case 'f':
67 nlsr.setConfFileName(optarg);
68 break;
69 case 'd':
70 nlsr.setIsDaemonProcess(optarg);
71 break;
72 case 'p':
73 {
74 stringstream sst(optarg);
75 int ap;
76 sst>>ap;
77 nlsr.setApiPort(ap);
78 }
79 break;
80 case 'h':
81 default:
82 nlsr.usage(programName);
83 return EXIT_FAILURE;
84 }
85 }
86
87
88 ConfFileProcessor cfp(nlsr.getConfFileName());
89 int res=cfp.processConfFile(nlsr);
90 if ( res < 0 )
91 {
92 return EXIT_FAILURE;
93 }
94
95 nlsr.getConfParameter().buildRouterPrefix();
96 nlsr.getLsdb().setLsaRefreshTime(nlsr.getConfParameter().getLsaRefreshTime());
97 nlsr.getFib().setFibEntryRefreshTime(2*nlsr.getConfParameter().getLsaRefreshTime());
akmhoque85d88332014-02-17 21:11:21 -060098 //nlsr.getFib().scheduleFibRefreshing(nlsr, 60);
akmhoque298385a2014-02-13 14:13:09 -060099 nlsr.getLsdb().setThisRouterPrefix(nlsr.getConfParameter().getRouterPrefix());
100
101 /* debugging purpose start */
102 cout << nlsr.getConfParameter();
103 nlsr.getAdl().printAdl();
104 nlsr.getNpl().printNpl();
105 /* debugging purpose end */
106
107 nlsr.getLsdb().buildAndInstallOwnNameLsa(nlsr);
108 nlsr.getLsdb().buildAndInstallOwnCorLsa(nlsr);
109
110 //testing purpose
111 nlsr.getNlsrTesting().schedlueAddingLsas(nlsr);
112
113 nlsr.setInterestFilterNlsr(nlsr.getConfParameter().getRouterPrefix());
114 nlsr.getIm().scheduleInfoInterest(nlsr,1);
115
116
117
118
119 try{
120 nlsr.startEventLoop();
121 }catch(std::exception &e) {
122 std::cerr << "ERROR: " << e.what() << std::endl;
123 }
124
125 return EXIT_SUCCESS;
126}