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