blob: 00bd510a90bb3642bc111b8510984f0747e2d4ab [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,
31 func_lib::bind(&InterestManager::processInterest, &m_im,
32 boost::ref(*this), _1, _2),
33 func_lib::bind(&Nlsr::registrationFailed, this, _1));
34}
35
36void
37Nlsr::initialize()
38{
39 m_confParam.buildRouterPrefix();
40 m_nlsrLsdb.setLsaRefreshTime(m_confParam.getLsaRefreshTime());
41 m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix());
42 m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime());
43 if (!m_km.initialize(m_confParam))
akmhoque5a44dd42014-03-12 18:11:32 -050044 {
akmhoque53353462014-04-22 08:43:45 -050045 std::cerr << "Can not initiate/load certificate" << endl;
akmhoque5a44dd42014-03-12 18:11:32 -050046 }
akmhoque53353462014-04-22 08:43:45 -050047 m_sm.setSeqFileName(m_confParam.getSeqFileDir());
48 m_sm.initiateSeqNoFromFile();
49 /* debugging purpose start */
50 cout << m_confParam;
51 m_adl.printAdl();
52 m_npl.print();
53 /* debugging purpose end */
54 m_nlsrLsdb.buildAndInstallOwnNameLsa(boost::ref(*this));
55 m_nlsrLsdb.buildAndInstallOwnCorLsa(boost::ref(*this));
56 setInterestFilterNlsr(m_confParam.getRouterPrefix());
57 setInterestFilterNlsr(m_confParam.getChronosyncLsaPrefix() +
58 m_confParam.getRouterPrefix());
59 setInterestFilterNlsr(m_confParam.getRootKeyPrefix());
60 m_slh.setSyncPrefix(m_confParam.getChronosyncSyncPrefix());
61 m_slh.createSyncSocket(boost::ref(*this));
62 m_slh.publishKeyUpdate(m_km);
63 m_im.scheduleInfoInterest(boost::ref(*this), 10);
64}
akmhoque5a44dd42014-03-12 18:11:32 -050065
akmhoque53353462014-04-22 08:43:45 -050066void
67Nlsr::startEventLoop()
68{
69 m_io->run();
70}
akmhoque5a44dd42014-03-12 18:11:32 -050071
akmhoque53353462014-04-22 08:43:45 -050072int
73Nlsr::usage(const string& progname)
74{
75 cout << "Usage: " << progname << " [OPTIONS...]" << endl;
76 cout << " NDN routing...." << endl;
77 cout << " -d, --daemon Run in daemon mode" << endl;
78 cout << " -f, --config_file Specify configuration file name" << endl;
79 cout << " -p, --api_port port where api client will connect" << endl;
80 cout << " -h, --help Display this help message" << endl;
81 exit(EXIT_FAILURE);
82}
akmhoque298385a2014-02-13 14:13:09 -060083
akmhoqueb1710aa2014-02-19 17:13:36 -060084
85} // namespace nlsr