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 | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 23 | Nlsr::setInfoInterestFilter() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 24 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 25 | ndn::Name name(m_confParam.getRouterPrefix()); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 26 | getNlsrFace().setInterestFilter(name, |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 27 | ndn::bind(&HelloProtocol::processInterest, |
| 28 | &m_helloProtocol, _1, _2), |
| 29 | ndn::bind(&Nlsr::registrationFailed, this, _1)); |
| 30 | } |
| 31 | |
| 32 | void |
| 33 | Nlsr::setLsaInterestFilter() |
| 34 | { |
| 35 | // ndn::Name name(m_confParam.getChronosyncLsaPrefix() + |
| 36 | // m_confParam.getRouterPrefix()); |
| 37 | ndn::Name name = m_confParam.getChronosyncLsaPrefix(); |
| 38 | name.append(m_confParam.getRouterPrefix()); |
| 39 | getNlsrFace().setInterestFilter(name, |
| 40 | ndn::bind(&Lsdb::processInterest, |
| 41 | &m_nlsrLsdb, _1, _2), |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 42 | ndn::bind(&Nlsr::registrationFailed, this, _1)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void |
| 46 | Nlsr::initialize() |
| 47 | { |
| 48 | m_confParam.buildRouterPrefix(); |
| 49 | m_nlsrLsdb.setLsaRefreshTime(m_confParam.getLsaRefreshTime()); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 50 | m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix().toUri()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 51 | m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime()); |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 52 | m_sequencingManager.setSeqFileName(m_confParam.getSeqFileDir()); |
| 53 | m_sequencingManager.initiateSeqNoFromFile(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 54 | /* debugging purpose start */ |
Yingdi Yu | 0c21782 | 2014-04-24 14:22:42 -0700 | [diff] [blame] | 55 | cout << m_confParam; |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 56 | m_adjacencyList.print(); |
| 57 | m_namePrefixList.print(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 58 | /* debugging purpose end */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 59 | m_nlsrLsdb.buildAndInstallOwnNameLsa(); |
| 60 | m_nlsrLsdb.buildAndInstallOwnCoordinateLsa(); |
| 61 | setInfoInterestFilter(); |
| 62 | setLsaInterestFilter(); |
| 63 | m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncSyncPrefix().toUri()); |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 64 | m_syncLogicHandler.createSyncSocket(boost::ref(*this)); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 65 | //m_interestManager.scheduleInfoInterest(10); |
| 66 | m_helloProtocol.scheduleInterest(10); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 67 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 68 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 69 | void |
| 70 | Nlsr::startEventLoop() |
| 71 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 72 | m_nlsrFace.processEvents(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 73 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 74 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 75 | void |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 76 | Nlsr::usage(const string& progname) |
| 77 | { |
| 78 | cout << "Usage: " << progname << " [OPTIONS...]" << endl; |
| 79 | cout << " NDN routing...." << endl; |
| 80 | cout << " -d, --daemon Run in daemon mode" << endl; |
| 81 | cout << " -f, --config_file Specify configuration file name" << endl; |
| 82 | cout << " -p, --api_port port where api client will connect" << endl; |
| 83 | cout << " -h, --help Display this help message" << endl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 84 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 85 | |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 86 | |
| 87 | } // namespace nlsr |