blob: 61f9424848e781897ab2acb4b9608cc535ad5332 [file] [log] [blame]
akmhoque87347a32014-01-31 11:00:44 -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
7#include "nlsr.hpp"
akmhoque204e7542014-01-31 16:08:25 -06008#include "nlsr_conf_param.hpp"
9#include "nlsr_conf_processor.hpp"
akmhoque87347a32014-01-31 11:00:44 -060010
11
12using namespace ndn;
13using namespace std;
14
akmhoque87347a32014-01-31 11:00:44 -060015void
16nlsr::nlsrRegistrationFailed(const ptr_lib::shared_ptr<const Name>&)
17{
akmhoque147f4992014-01-31 15:52:49 -060018 cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
19 nlsrFace.shutdown();
akmhoque87347a32014-01-31 11:00:44 -060020}
21
akmhoque147f4992014-01-31 15:52:49 -060022
akmhoque87347a32014-01-31 11:00:44 -060023void
akmhoque147f4992014-01-31 15:52:49 -060024nlsr::setInterestFilterNlsr(const string& name)
akmhoque87347a32014-01-31 11:00:44 -060025{
akmhoque147f4992014-01-31 15:52:49 -060026 nlsrFace.setInterestFilter(name,
27 func_lib::bind(&interestManager::processInterest, &im,
28 boost::ref(*this), _1, _2),
akmhoque87347a32014-01-31 11:00:44 -060029 func_lib::bind(&nlsr::nlsrRegistrationFailed, this, _1));
30}
31
akmhoque147f4992014-01-31 15:52:49 -060032
akmhoque87347a32014-01-31 11:00:44 -060033void
akmhoque147f4992014-01-31 15:52:49 -060034nlsr::startEventLoop()
akmhoque87347a32014-01-31 11:00:44 -060035{
akmhoque87347a32014-01-31 11:00:44 -060036 nlsrFace.processEvents();
37}
38
39int
akmhoque147f4992014-01-31 15:52:49 -060040nlsr::usage(const string& progname)
41{
akmhoque87347a32014-01-31 11:00:44 -060042
43 cout << "Usage: " << progname << " [OPTIONS...]"<<endl;
44 cout << " NDN routing...." << endl;
45 cout << " -d, --daemon Run in daemon mode" << endl;
46 cout << " -f, --config_file Specify configuration file name" <<endl;
47 cout << " -p, --api_port port where api client will connect" <<endl;
48 cout << " -h, --help Display this help message" << endl;
49
50 exit(EXIT_FAILURE);
51}
52
53int
54main(){
55
56 nlsr nlsr;
57 nlsr.setConfFileName("nlsr.conf");
58 ConfFileProcessor cfp(nlsr.getConfFileName());
59 cfp.processConfFile(nlsr);
60 nlsr.confParam.buildRouterPrefix();
61/* debugging purpose start */
62 cout << nlsr.confParam ;
63 nlsr.adl.printAdl();
64 nlsr.npl.printNpl();
65/* debugging purpose end */
akmhoque147f4992014-01-31 15:52:49 -060066 nlsr.setInterestFilterNlsr(nlsr.confParam.getRouterPrefix());
67 nlsr.im.scheduleInfoInterest(nlsr,1);
akmhoque87347a32014-01-31 11:00:44 -060068
69
70
71
72 try{
73 nlsr.startEventLoop();
74 }catch(std::exception &e) {
75 std::cerr << "ERROR: " << e.what() << std::endl;
76 }
77
78 return 0;
79}