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