akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 1 | #include <cstdlib> |
akmhoque | 92afde4 | 2014-02-18 14:04:07 -0600 | [diff] [blame] | 2 | #include <string> |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 3 | #include <sstream> |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 4 | #include <cstdio> |
akmhoque | eb764c5 | 2014-03-11 16:01:09 -0500 | [diff] [blame] | 5 | #include <ndn-cpp-dev/face.hpp> |
| 6 | #include <ndn-cpp-dev/security/key-chain.hpp> |
| 7 | #include <ndn-cpp-dev/security/identity-certificate.hpp> |
| 8 | #include <ndn-cpp-dev/util/scheduler.hpp> |
| 9 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 10 | |
| 11 | #include "nlsr.hpp" |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 12 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 13 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame^] | 14 | namespace nlsr { |
| 15 | |
| 16 | using namespace ndn; |
| 17 | using namespace std; |
| 18 | |
| 19 | void |
| 20 | Nlsr::registrationFailed(const ndn::Name& name) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 21 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame^] | 22 | cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl; |
| 23 | getNlsrFace()->shutdown(); |
| 24 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 25 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 26 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame^] | 27 | void |
| 28 | Nlsr::setInterestFilterNlsr(const string& name) |
| 29 | { |
| 30 | getNlsrFace()->setInterestFilter(name, |
| 31 | func_lib::bind(&InterestManager::processInterest, &m_im, |
| 32 | boost::ref(*this), _1, _2), |
| 33 | func_lib::bind(&Nlsr::registrationFailed, this, _1)); |
| 34 | } |
| 35 | |
| 36 | void |
| 37 | Nlsr::initialize() |
| 38 | { |
| 39 | m_confParam.buildRouterPrefix(); |
| 40 | m_nlsrLsdb.setLsaRefreshTime(m_confParam.getLsaRefreshTime()); |
| 41 | m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix()); |
| 42 | m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime()); |
| 43 | if (!m_km.initialize(m_confParam)) |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 44 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame^] | 45 | std::cerr << "Can not initiate/load certificate" << endl; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 46 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame^] | 47 | m_sm.setSeqFileName(m_confParam.getSeqFileDir()); |
| 48 | m_sm.initiateSeqNoFromFile(); |
| 49 | /* debugging purpose start */ |
| 50 | cout << m_confParam; |
| 51 | m_adl.printAdl(); |
| 52 | m_npl.print(); |
| 53 | /* debugging purpose end */ |
| 54 | m_nlsrLsdb.buildAndInstallOwnNameLsa(boost::ref(*this)); |
| 55 | m_nlsrLsdb.buildAndInstallOwnCorLsa(boost::ref(*this)); |
| 56 | setInterestFilterNlsr(m_confParam.getRouterPrefix()); |
| 57 | setInterestFilterNlsr(m_confParam.getChronosyncLsaPrefix() + |
| 58 | m_confParam.getRouterPrefix()); |
| 59 | setInterestFilterNlsr(m_confParam.getRootKeyPrefix()); |
| 60 | m_slh.setSyncPrefix(m_confParam.getChronosyncSyncPrefix()); |
| 61 | m_slh.createSyncSocket(boost::ref(*this)); |
| 62 | m_slh.publishKeyUpdate(m_km); |
| 63 | m_im.scheduleInfoInterest(boost::ref(*this), 10); |
| 64 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 65 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame^] | 66 | void |
| 67 | Nlsr::startEventLoop() |
| 68 | { |
| 69 | m_io->run(); |
| 70 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 71 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame^] | 72 | int |
| 73 | Nlsr::usage(const string& progname) |
| 74 | { |
| 75 | cout << "Usage: " << progname << " [OPTIONS...]" << endl; |
| 76 | cout << " NDN routing...." << endl; |
| 77 | cout << " -d, --daemon Run in daemon mode" << endl; |
| 78 | cout << " -f, --config_file Specify configuration file name" << endl; |
| 79 | cout << " -p, --api_port port where api client will connect" << endl; |
| 80 | cout << " -h, --help Display this help message" << endl; |
| 81 | exit(EXIT_FAILURE); |
| 82 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 83 | |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 84 | |
| 85 | } // namespace nlsr |