blob: 22e7dc8f6a365174aa66cdc1fa81589fd104253d [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#include <cstdlib>
akmhoque92afde42014-02-18 14:04:07 -06002#include <string>
akmhoque298385a2014-02-13 14:13:09 -06003#include <sstream>
akmhoque05d5fcf2014-04-15 14:58:45 -05004#include <cstdio>
akmhoque298385a2014-02-13 14:13:09 -06005
6#include "nlsr.hpp"
akmhoque2bb198e2014-02-28 11:46:27 -06007
akmhoque298385a2014-02-13 14:13:09 -06008
akmhoque53353462014-04-22 08:43:45 -05009namespace nlsr {
10
11using namespace ndn;
12using namespace std;
13
14void
15Nlsr::registrationFailed(const ndn::Name& name)
akmhoque298385a2014-02-13 14:13:09 -060016{
akmhoquefdbddb12014-05-02 18:35:19 -050017 std::cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
18 throw Error("Error: Prefix registration failed");
akmhoque53353462014-04-22 08:43:45 -050019}
akmhoque1fd8c1e2014-02-19 19:41:49 -060020
akmhoque1fd8c1e2014-02-19 19:41:49 -060021
akmhoque53353462014-04-22 08:43:45 -050022void
akmhoquefdbddb12014-05-02 18:35:19 -050023Nlsr::setInterestFilter(const string& name)
akmhoque53353462014-04-22 08:43:45 -050024{
akmhoquefdbddb12014-05-02 18:35:19 -050025 getNlsrFace().setInterestFilter(name,
26 ndn::bind(&InterestManager::processInterest,
27 &m_interestManager, _1, _2),
28 ndn::bind(&Nlsr::registrationFailed, this, _1));
akmhoque53353462014-04-22 08:43:45 -050029}
30
31void
32Nlsr::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 Yu0c217822014-04-24 14:22:42 -070038 // if (!m_km.initialize(m_confParam))
39 // {
40 // std::cerr << "Can not initiate/load certificate" << endl;
41 // }
akmhoquec8a10f72014-04-25 18:42:55 -050042 m_sequencingManager.setSeqFileName(m_confParam.getSeqFileDir());
43 m_sequencingManager.initiateSeqNoFromFile();
akmhoque53353462014-04-22 08:43:45 -050044 /* debugging purpose start */
Yingdi Yu0c217822014-04-24 14:22:42 -070045 cout << m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -050046 m_adjacencyList.print();
47 m_namePrefixList.print();
akmhoque53353462014-04-22 08:43:45 -050048 /* debugging purpose end */
49 m_nlsrLsdb.buildAndInstallOwnNameLsa(boost::ref(*this));
akmhoqueb6450b12014-04-24 00:01:03 -050050 m_nlsrLsdb.buildAndInstallOwnCoordinateLsa(boost::ref(*this));
akmhoquefdbddb12014-05-02 18:35:19 -050051 setInterestFilter(m_confParam.getRouterPrefix());
52 setInterestFilter(m_confParam.getChronosyncLsaPrefix() +
53 m_confParam.getRouterPrefix());
54 setInterestFilter(m_confParam.getRootKeyPrefix());
akmhoquec8a10f72014-04-25 18:42:55 -050055 m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncSyncPrefix());
56 m_syncLogicHandler.createSyncSocket(boost::ref(*this));
Yingdi Yu0c217822014-04-24 14:22:42 -070057 // m_slh.publishKeyUpdate(m_km);
akmhoquec8a10f72014-04-25 18:42:55 -050058 m_interestManager.scheduleInfoInterest(10);
akmhoque53353462014-04-22 08:43:45 -050059}
akmhoque5a44dd42014-03-12 18:11:32 -050060
akmhoque53353462014-04-22 08:43:45 -050061void
62Nlsr::startEventLoop()
63{
akmhoquefdbddb12014-05-02 18:35:19 -050064 m_nlsrFace.processEvents();
akmhoque53353462014-04-22 08:43:45 -050065}
akmhoque5a44dd42014-03-12 18:11:32 -050066
akmhoquefdbddb12014-05-02 18:35:19 -050067void
akmhoque53353462014-04-22 08:43:45 -050068Nlsr::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;
akmhoque53353462014-04-22 08:43:45 -050076}
akmhoque298385a2014-02-13 14:13:09 -060077
akmhoqueb1710aa2014-02-19 17:13:36 -060078
79} // namespace nlsr