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