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