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, |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 31 | ndn::bind(&InterestManager::processInterest, &m_im,_1, _2), |
| 32 | ndn::bind(&Nlsr::registrationFailed, this, _1)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void |
| 36 | Nlsr::initialize() |
| 37 | { |
| 38 | m_confParam.buildRouterPrefix(); |
| 39 | m_nlsrLsdb.setLsaRefreshTime(m_confParam.getLsaRefreshTime()); |
| 40 | m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix()); |
| 41 | m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime()); |
| 42 | if (!m_km.initialize(m_confParam)) |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 43 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 44 | std::cerr << "Can not initiate/load certificate" << endl; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 45 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 46 | m_sm.setSeqFileName(m_confParam.getSeqFileDir()); |
| 47 | m_sm.initiateSeqNoFromFile(); |
| 48 | /* debugging purpose start */ |
| 49 | cout << m_confParam; |
| 50 | m_adl.printAdl(); |
| 51 | m_npl.print(); |
| 52 | /* debugging purpose end */ |
| 53 | m_nlsrLsdb.buildAndInstallOwnNameLsa(boost::ref(*this)); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 54 | m_nlsrLsdb.buildAndInstallOwnCoordinateLsa(boost::ref(*this)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 55 | setInterestFilterNlsr(m_confParam.getRouterPrefix()); |
| 56 | setInterestFilterNlsr(m_confParam.getChronosyncLsaPrefix() + |
| 57 | m_confParam.getRouterPrefix()); |
| 58 | setInterestFilterNlsr(m_confParam.getRootKeyPrefix()); |
| 59 | m_slh.setSyncPrefix(m_confParam.getChronosyncSyncPrefix()); |
| 60 | m_slh.createSyncSocket(boost::ref(*this)); |
| 61 | m_slh.publishKeyUpdate(m_km); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 62 | m_im.scheduleInfoInterest(10); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 63 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 64 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 65 | void |
| 66 | Nlsr::startEventLoop() |
| 67 | { |
| 68 | m_io->run(); |
| 69 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 70 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 71 | int |
| 72 | Nlsr::usage(const string& progname) |
| 73 | { |
| 74 | cout << "Usage: " << progname << " [OPTIONS...]" << endl; |
| 75 | cout << " NDN routing...." << endl; |
| 76 | cout << " -d, --daemon Run in daemon mode" << endl; |
| 77 | cout << " -f, --config_file Specify configuration file name" << endl; |
| 78 | cout << " -p, --api_port port where api client will connect" << endl; |
| 79 | cout << " -h, --help Display this help message" << endl; |
| 80 | exit(EXIT_FAILURE); |
| 81 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 82 | |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 83 | |
| 84 | } // namespace nlsr |