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 | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 10 | |
| 11 | |
| 12 | using namespace ndn; |
| 13 | using namespace std; |
| 14 | |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 15 | void |
| 16 | nlsr::nlsrRegistrationFailed(const ptr_lib::shared_ptr<const Name>&) |
| 17 | { |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 18 | cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl; |
| 19 | nlsrFace.shutdown(); |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 20 | } |
| 21 | |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 22 | |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 23 | void |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 24 | nlsr::setInterestFilterNlsr(const string& name) |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 25 | { |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 26 | nlsrFace.setInterestFilter(name, |
| 27 | func_lib::bind(&interestManager::processInterest, &im, |
| 28 | boost::ref(*this), _1, _2), |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 29 | func_lib::bind(&nlsr::nlsrRegistrationFailed, this, _1)); |
| 30 | } |
| 31 | |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 32 | |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 33 | void |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 34 | nlsr::startEventLoop() |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 35 | { |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 36 | nlsrFace.processEvents(); |
| 37 | } |
| 38 | |
| 39 | int |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 40 | nlsr::usage(const string& progname) |
| 41 | { |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 42 | |
| 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 | |
| 53 | int |
| 54 | main(){ |
| 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 */ |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 66 | nlsr.setInterestFilterNlsr(nlsr.confParam.getRouterPrefix()); |
| 67 | nlsr.im.scheduleInfoInterest(nlsr,1); |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 68 | |
| 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 | } |