blob: f4616ce7b06407b92d1211605eb2c73b91a2854d [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{
akmhoque53353462014-04-22 08:43:45 -050017 cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
18 getNlsrFace()->shutdown();
19}
akmhoque1fd8c1e2014-02-19 19:41:49 -060020
akmhoque1fd8c1e2014-02-19 19:41:49 -060021
akmhoque53353462014-04-22 08:43:45 -050022void
23Nlsr::setInterestFilterNlsr(const string& name)
24{
25 getNlsrFace()->setInterestFilter(name,
akmhoquec8a10f72014-04-25 18:42:55 -050026 ndn::bind(&InterestManager::processInterest, &m_interestManager, _1, _2),
akmhoqueb6450b12014-04-24 00:01:03 -050027 ndn::bind(&Nlsr::registrationFailed, this, _1));
akmhoque53353462014-04-22 08:43:45 -050028}
29
30void
31Nlsr::initialize()
32{
33 m_confParam.buildRouterPrefix();
34 m_nlsrLsdb.setLsaRefreshTime(m_confParam.getLsaRefreshTime());
35 m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix());
36 m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime());
Yingdi Yu0c217822014-04-24 14:22:42 -070037 // if (!m_km.initialize(m_confParam))
38 // {
39 // std::cerr << "Can not initiate/load certificate" << endl;
40 // }
akmhoquec8a10f72014-04-25 18:42:55 -050041 m_sequencingManager.setSeqFileName(m_confParam.getSeqFileDir());
42 m_sequencingManager.initiateSeqNoFromFile();
akmhoque53353462014-04-22 08:43:45 -050043 /* debugging purpose start */
Yingdi Yu0c217822014-04-24 14:22:42 -070044 cout << m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -050045 m_adjacencyList.print();
46 m_namePrefixList.print();
akmhoque53353462014-04-22 08:43:45 -050047 /* debugging purpose end */
48 m_nlsrLsdb.buildAndInstallOwnNameLsa(boost::ref(*this));
akmhoqueb6450b12014-04-24 00:01:03 -050049 m_nlsrLsdb.buildAndInstallOwnCoordinateLsa(boost::ref(*this));
akmhoque53353462014-04-22 08:43:45 -050050 setInterestFilterNlsr(m_confParam.getRouterPrefix());
51 setInterestFilterNlsr(m_confParam.getChronosyncLsaPrefix() +
52 m_confParam.getRouterPrefix());
53 setInterestFilterNlsr(m_confParam.getRootKeyPrefix());
akmhoquec8a10f72014-04-25 18:42:55 -050054 m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncSyncPrefix());
55 m_syncLogicHandler.createSyncSocket(boost::ref(*this));
Yingdi Yu0c217822014-04-24 14:22:42 -070056 // m_slh.publishKeyUpdate(m_km);
akmhoquec8a10f72014-04-25 18:42:55 -050057 m_interestManager.scheduleInfoInterest(10);
akmhoque53353462014-04-22 08:43:45 -050058}
akmhoque5a44dd42014-03-12 18:11:32 -050059
akmhoque53353462014-04-22 08:43:45 -050060void
61Nlsr::startEventLoop()
62{
63 m_io->run();
64}
akmhoque5a44dd42014-03-12 18:11:32 -050065
akmhoque53353462014-04-22 08:43:45 -050066int
67Nlsr::usage(const string& progname)
68{
69 cout << "Usage: " << progname << " [OPTIONS...]" << endl;
70 cout << " NDN routing...." << endl;
71 cout << " -d, --daemon Run in daemon mode" << endl;
72 cout << " -f, --config_file Specify configuration file name" << endl;
73 cout << " -p, --api_port port where api client will connect" << endl;
74 cout << " -h, --help Display this help message" << endl;
75 exit(EXIT_FAILURE);
76}
akmhoque298385a2014-02-13 14:13:09 -060077
akmhoqueb1710aa2014-02-19 17:13:36 -060078
79} // namespace nlsr