blob: 70a07cf6538e873caf5f85cd88ca43cda72276b2 [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>
akmhoqueeb764c52014-03-11 16:01:09 -05005#include <ndn-cpp-dev/face.hpp>
6#include <ndn-cpp-dev/security/key-chain.hpp>
7#include <ndn-cpp-dev/security/identity-certificate.hpp>
8#include <ndn-cpp-dev/util/scheduler.hpp>
9
akmhoque298385a2014-02-13 14:13:09 -060010
11#include "nlsr.hpp"
akmhoque2bb198e2014-02-28 11:46:27 -060012
akmhoque298385a2014-02-13 14:13:09 -060013
akmhoque53353462014-04-22 08:43:45 -050014namespace nlsr {
15
16using namespace ndn;
17using namespace std;
18
19void
20Nlsr::registrationFailed(const ndn::Name& name)
akmhoque298385a2014-02-13 14:13:09 -060021{
akmhoque53353462014-04-22 08:43:45 -050022 cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
23 getNlsrFace()->shutdown();
24}
akmhoque1fd8c1e2014-02-19 19:41:49 -060025
akmhoque1fd8c1e2014-02-19 19:41:49 -060026
akmhoque53353462014-04-22 08:43:45 -050027void
28Nlsr::setInterestFilterNlsr(const string& name)
29{
30 getNlsrFace()->setInterestFilter(name,
akmhoqueb6450b12014-04-24 00:01:03 -050031 ndn::bind(&InterestManager::processInterest, &m_im,_1, _2),
32 ndn::bind(&Nlsr::registrationFailed, this, _1));
akmhoque53353462014-04-22 08:43:45 -050033}
34
35void
36Nlsr::initialize()
37{
38 m_confParam.buildRouterPrefix();
39 m_nlsrLsdb.setLsaRefreshTime(m_confParam.getLsaRefreshTime());
40 m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix());
41 m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime());
42 if (!m_km.initialize(m_confParam))
akmhoque5a44dd42014-03-12 18:11:32 -050043 {
akmhoque53353462014-04-22 08:43:45 -050044 std::cerr << "Can not initiate/load certificate" << endl;
akmhoque5a44dd42014-03-12 18:11:32 -050045 }
akmhoque53353462014-04-22 08:43:45 -050046 m_sm.setSeqFileName(m_confParam.getSeqFileDir());
47 m_sm.initiateSeqNoFromFile();
48 /* debugging purpose start */
49 cout << m_confParam;
50 m_adl.printAdl();
51 m_npl.print();
52 /* debugging purpose end */
53 m_nlsrLsdb.buildAndInstallOwnNameLsa(boost::ref(*this));
akmhoqueb6450b12014-04-24 00:01:03 -050054 m_nlsrLsdb.buildAndInstallOwnCoordinateLsa(boost::ref(*this));
akmhoque53353462014-04-22 08:43:45 -050055 setInterestFilterNlsr(m_confParam.getRouterPrefix());
56 setInterestFilterNlsr(m_confParam.getChronosyncLsaPrefix() +
57 m_confParam.getRouterPrefix());
58 setInterestFilterNlsr(m_confParam.getRootKeyPrefix());
59 m_slh.setSyncPrefix(m_confParam.getChronosyncSyncPrefix());
60 m_slh.createSyncSocket(boost::ref(*this));
61 m_slh.publishKeyUpdate(m_km);
akmhoqueb6450b12014-04-24 00:01:03 -050062 m_im.scheduleInfoInterest(10);
akmhoque53353462014-04-22 08:43:45 -050063}
akmhoque5a44dd42014-03-12 18:11:32 -050064
akmhoque53353462014-04-22 08:43:45 -050065void
66Nlsr::startEventLoop()
67{
68 m_io->run();
69}
akmhoque5a44dd42014-03-12 18:11:32 -050070
akmhoque53353462014-04-22 08:43:45 -050071int
72Nlsr::usage(const string& progname)
73{
74 cout << "Usage: " << progname << " [OPTIONS...]" << endl;
75 cout << " NDN routing...." << endl;
76 cout << " -d, --daemon Run in daemon mode" << endl;
77 cout << " -f, --config_file Specify configuration file name" << endl;
78 cout << " -p, --api_port port where api client will connect" << endl;
79 cout << " -h, --help Display this help message" << endl;
80 exit(EXIT_FAILURE);
81}
akmhoque298385a2014-02-13 14:13:09 -060082
akmhoqueb1710aa2014-02-19 17:13:36 -060083
84} // namespace nlsr