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> |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame^] | 6 | #include<string> |
| 7 | #include <sstream> |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 8 | |
| 9 | #include "nlsr.hpp" |
akmhoque | 204e754 | 2014-01-31 16:08:25 -0600 | [diff] [blame] | 10 | #include "nlsr_conf_param.hpp" |
| 11 | #include "nlsr_conf_processor.hpp" |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 12 | #include "nlsr_lsdb.hpp" |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame^] | 13 | //test purpose of NLSR |
| 14 | #include "nlsr_test.hpp" |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 15 | |
| 16 | using namespace ndn; |
| 17 | using namespace std; |
| 18 | |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 19 | void |
| 20 | nlsr::nlsrRegistrationFailed(const ptr_lib::shared_ptr<const Name>&) |
| 21 | { |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 22 | cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl; |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 23 | getNlsrFace().shutdown(); |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 24 | } |
| 25 | |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 26 | |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 27 | void |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 28 | nlsr::setInterestFilterNlsr(const string& name) |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 29 | { |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 30 | getNlsrFace().setInterestFilter(name, |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 31 | func_lib::bind(&interestManager::processInterest, &im, |
| 32 | boost::ref(*this), _1, _2), |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 33 | func_lib::bind(&nlsr::nlsrRegistrationFailed, this, _1)); |
| 34 | } |
| 35 | |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 36 | |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 37 | void |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 38 | nlsr::startEventLoop() |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 39 | { |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 40 | getNlsrFace().processEvents(); |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | int |
akmhoque | 147f499 | 2014-01-31 15:52:49 -0600 | [diff] [blame] | 44 | nlsr::usage(const string& progname) |
| 45 | { |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 46 | |
| 47 | cout << "Usage: " << progname << " [OPTIONS...]"<<endl; |
| 48 | cout << " NDN routing...." << endl; |
| 49 | cout << " -d, --daemon Run in daemon mode" << endl; |
| 50 | cout << " -f, --config_file Specify configuration file name" <<endl; |
| 51 | cout << " -p, --api_port port where api client will connect" <<endl; |
| 52 | cout << " -h, --help Display this help message" << endl; |
| 53 | |
| 54 | exit(EXIT_FAILURE); |
| 55 | } |
| 56 | |
| 57 | int |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame^] | 58 | main(int argc, char **argv){ |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 59 | |
| 60 | nlsr nlsr; |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame^] | 61 | string programName(argv[0]); |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 62 | nlsr.setConfFileName("nlsr.conf"); |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame^] | 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 | |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 89 | ConfFileProcessor cfp(nlsr.getConfFileName()); |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame^] | 90 | int res=cfp.processConfFile(nlsr); |
| 91 | if ( res < 0 ) |
| 92 | { |
| 93 | return EXIT_FAILURE; |
| 94 | } |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 95 | nlsr.getConfParameter().buildRouterPrefix(); |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 96 | |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame^] | 97 | /* debugging purpose start */ |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 98 | cout << nlsr.getConfParameter(); |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 99 | nlsr.getAdl().printAdl(); |
| 100 | nlsr.getNpl().printNpl(); |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame^] | 101 | /* debugging purpose end */ |
| 102 | |
| 103 | nlsr.getLsdb().buildAndInstallOwnNameLsa(nlsr); |
| 104 | nlsr.getLsdb().buildAndInstallOwnCorLsa(nlsr); |
| 105 | |
| 106 | //testing purpose |
| 107 | nlsr.getNlsrTesting().schedlueAddingLsas(nlsr); |
| 108 | |
akmhoque | a8cd6b9 | 2014-01-31 20:13:26 -0600 | [diff] [blame] | 109 | nlsr.setInterestFilterNlsr(nlsr.getConfParameter().getRouterPrefix()); |
| 110 | nlsr.getIm().scheduleInfoInterest(nlsr,1); |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | try{ |
| 116 | nlsr.startEventLoop(); |
| 117 | }catch(std::exception &e) { |
| 118 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 119 | } |
| 120 | |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame^] | 121 | return EXIT_SUCCESS; |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 122 | } |