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 | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 7 | #include "adjacent.hpp" |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 8 | #include "logger.hpp" |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 9 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 10 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 11 | namespace nlsr { |
| 12 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 13 | INIT_LOGGER("nlsr"); |
| 14 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 15 | using namespace ndn; |
| 16 | using namespace std; |
| 17 | |
| 18 | void |
| 19 | Nlsr::registrationFailed(const ndn::Name& name) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 20 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 21 | std::cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl; |
| 22 | throw Error("Error: Prefix registration failed"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 23 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 24 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 25 | void |
| 26 | Nlsr::onRegistrationSuccess(const ndn::Name& name) |
| 27 | { |
| 28 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 29 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 30 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 31 | Nlsr::setInfoInterestFilter() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 32 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 33 | ndn::Name name(m_confParam.getRouterPrefix()); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 34 | _LOG_DEBUG("Setting interest filter for name: " << name); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 35 | getNlsrFace().setInterestFilter(name, |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 36 | ndn::bind(&HelloProtocol::processInterest, |
| 37 | &m_helloProtocol, _1, _2), |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 38 | ndn::bind(&Nlsr::onRegistrationSuccess, this, _1), |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 39 | ndn::bind(&Nlsr::registrationFailed, this, _1)); |
| 40 | } |
| 41 | |
| 42 | void |
| 43 | Nlsr::setLsaInterestFilter() |
| 44 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 45 | ndn::Name name = m_confParam.getLsaPrefix(); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 46 | name.append(m_confParam.getRouterPrefix()); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 47 | _LOG_DEBUG("Setting interest filter for name: " << name); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 48 | getNlsrFace().setInterestFilter(name, |
| 49 | ndn::bind(&Lsdb::processInterest, |
| 50 | &m_nlsrLsdb, _1, _2), |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 51 | ndn::bind(&Nlsr::onRegistrationSuccess, this, _1), |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 52 | ndn::bind(&Nlsr::registrationFailed, this, _1)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 56 | Nlsr::registerPrefixes() |
| 57 | { |
| 58 | std::string strategy("ndn:/localhost/nfd/strategy/broadcast"); |
| 59 | std::list<Adjacent>& adjacents = m_adjacencyList.getAdjList(); |
| 60 | for (std::list<Adjacent>::iterator it = adjacents.begin(); |
| 61 | it != adjacents.end(); it++) { |
| 62 | m_fib.registerPrefix((*it).getName(), (*it).getConnectingFaceUri(), |
| 63 | (*it).getLinkCost(), 31536000); /* One Year in seconds */ |
| 64 | m_fib.registerPrefix(m_confParam.getChronosyncPrefix(), |
| 65 | (*it).getConnectingFaceUri(), (*it).getLinkCost(), 31536000); |
| 66 | m_fib.registerPrefix(m_confParam.getLsaPrefix(), |
| 67 | (*it).getConnectingFaceUri(), (*it).getLinkCost(), 31536000); |
| 68 | m_fib.setStrategy((*it).getName(), strategy); |
| 69 | } |
| 70 | |
| 71 | m_fib.setStrategy(m_confParam.getChronosyncPrefix(), strategy); |
| 72 | m_fib.setStrategy(m_confParam.getLsaPrefix(), strategy); |
| 73 | } |
| 74 | |
| 75 | void |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 76 | Nlsr::initialize() |
| 77 | { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 78 | _LOG_DEBUG("Initializing Nlsr"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 79 | m_confParam.buildRouterPrefix(); |
| 80 | m_nlsrLsdb.setLsaRefreshTime(m_confParam.getLsaRefreshTime()); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 81 | m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix().toUri()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 82 | m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime()); |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 83 | m_sequencingManager.setSeqFileName(m_confParam.getSeqFileDir()); |
| 84 | m_sequencingManager.initiateSeqNoFromFile(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 85 | /* debugging purpose start */ |
Yingdi Yu | 0c21782 | 2014-04-24 14:22:42 -0700 | [diff] [blame] | 86 | cout << m_confParam; |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 87 | m_adjacencyList.print(); |
| 88 | m_namePrefixList.print(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 89 | /* debugging purpose end */ |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 90 | /* Logging start */ |
| 91 | m_confParam.writeLog(); |
| 92 | m_adjacencyList.writeLog(); |
| 93 | m_namePrefixList.writeLog(); |
| 94 | /* Logging end */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 95 | registerPrefixes(); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 96 | setInfoInterestFilter(); |
| 97 | setLsaInterestFilter(); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 98 | m_nlsrLsdb.buildAndInstallOwnNameLsa(); |
| 99 | m_nlsrLsdb.buildAndInstallOwnCoordinateLsa(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 100 | m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncPrefix().toUri()); |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 101 | m_syncLogicHandler.createSyncSocket(boost::ref(*this)); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 102 | //m_interestManager.scheduleInfoInterest(10); |
| 103 | m_helloProtocol.scheduleInterest(10); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 104 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 105 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 106 | void |
| 107 | Nlsr::startEventLoop() |
| 108 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 109 | m_nlsrFace.processEvents(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 110 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 111 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 112 | void |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 113 | Nlsr::usage(const string& progname) |
| 114 | { |
| 115 | cout << "Usage: " << progname << " [OPTIONS...]" << endl; |
| 116 | cout << " NDN routing...." << endl; |
| 117 | cout << " -d, --daemon Run in daemon mode" << endl; |
| 118 | cout << " -f, --config_file Specify configuration file name" << endl; |
| 119 | cout << " -p, --api_port port where api client will connect" << endl; |
| 120 | cout << " -h, --help Display this help message" << endl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 121 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 122 | |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 123 | |
| 124 | } // namespace nlsr |