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