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