akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 1 | #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" |
akmhoque | 204e754 | 2014-01-31 16:08:25 -0600 | [diff] [blame] | 8 | #include "nlsr_conf_param.hpp" |
| 9 | #include "nlsr_conf_processor.hpp" |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 10 | #include "nlsr_lsdb.hpp" |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 11 | |
| 12 | |
| 13 | using namespace ndn; |
| 14 | using namespace std; |
| 15 | |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 16 | void |
| 17 | nlsr::nlsrRegistrationFailed(const ptr_lib::shared_ptr<const Name>&) |
| 18 | { |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 19 | cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl; |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 20 | getNlsrFace().shutdown(); |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 21 | } |
| 22 | |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 23 | |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 24 | void |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 25 | nlsr::setInterestFilterNlsr(const string& name) |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 26 | { |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 27 | getNlsrFace().setInterestFilter(name, |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 28 | func_lib::bind(&interestManager::processInterest, &im, |
| 29 | boost::ref(*this), _1, _2), |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 30 | func_lib::bind(&nlsr::nlsrRegistrationFailed, this, _1)); |
| 31 | } |
| 32 | |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 33 | |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 34 | void |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 35 | nlsr::startEventLoop() |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 36 | { |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 37 | getNlsrFace().processEvents(); |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | int |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 41 | nlsr::usage(const string& progname) |
| 42 | { |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 43 | |
| 44 | cout << "Usage: " << progname << " [OPTIONS...]"<<endl; |
| 45 | cout << " NDN routing...." << endl; |
| 46 | cout << " -d, --daemon Run in daemon mode" << endl; |
| 47 | cout << " -f, --config_file Specify configuration file name" <<endl; |
| 48 | cout << " -p, --api_port port where api client will connect" <<endl; |
| 49 | cout << " -h, --help Display this help message" << endl; |
| 50 | |
| 51 | exit(EXIT_FAILURE); |
| 52 | } |
| 53 | |
| 54 | int |
| 55 | main(){ |
| 56 | |
| 57 | nlsr nlsr; |
| 58 | nlsr.setConfFileName("nlsr.conf"); |
| 59 | ConfFileProcessor cfp(nlsr.getConfFileName()); |
| 60 | cfp.processConfFile(nlsr); |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 61 | nlsr.getConfParameter().buildRouterPrefix(); |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 62 | |
| 63 | nlsr.getLsdb().buildAndInstallOwnNameLsa(nlsr); |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 64 | nlsr.getLsdb().buildAndInstallOwnCorLsa(nlsr); |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 65 | |
| 66 | |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 67 | /* debugging purpose start */ |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 68 | cout << nlsr.getConfParameter(); |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 69 | nlsr.getAdl().printAdl(); |
| 70 | nlsr.getNpl().printNpl(); |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 71 | nlsr.getLsdb().printNameLsdb(); |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 72 | nlsr.getLsdb().printCorLsdb(); |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 73 | /* debugging purpose end */ |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 74 | nlsr.setInterestFilterNlsr(nlsr.getConfParameter().getRouterPrefix()); |
| 75 | nlsr.getIm().scheduleInfoInterest(nlsr,1); |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | try{ |
| 81 | nlsr.startEventLoop(); |
| 82 | }catch(std::exception &e) { |
| 83 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 84 | } |
| 85 | |
| 86 | return 0; |
| 87 | } |