blob: 91b4c25776dbedac886b740425a05ec6b884ca56 [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
akmhoque31d1d4b2014-05-05 22:08:14 -050023Nlsr::setInfoInterestFilter()
akmhoque53353462014-04-22 08:43:45 -050024{
akmhoque31d1d4b2014-05-05 22:08:14 -050025 ndn::Name name(m_confParam.getRouterPrefix());
akmhoquefdbddb12014-05-02 18:35:19 -050026 getNlsrFace().setInterestFilter(name,
akmhoque31d1d4b2014-05-05 22:08:14 -050027 ndn::bind(&HelloProtocol::processInterest,
28 &m_helloProtocol, _1, _2),
29 ndn::bind(&Nlsr::registrationFailed, this, _1));
30}
31
32void
33Nlsr::setLsaInterestFilter()
34{
35 // ndn::Name name(m_confParam.getChronosyncLsaPrefix() +
36 // m_confParam.getRouterPrefix());
37 ndn::Name name = m_confParam.getChronosyncLsaPrefix();
38 name.append(m_confParam.getRouterPrefix());
39 getNlsrFace().setInterestFilter(name,
40 ndn::bind(&Lsdb::processInterest,
41 &m_nlsrLsdb, _1, _2),
akmhoquefdbddb12014-05-02 18:35:19 -050042 ndn::bind(&Nlsr::registrationFailed, this, _1));
akmhoque53353462014-04-22 08:43:45 -050043}
44
45void
46Nlsr::initialize()
47{
48 m_confParam.buildRouterPrefix();
49 m_nlsrLsdb.setLsaRefreshTime(m_confParam.getLsaRefreshTime());
akmhoque31d1d4b2014-05-05 22:08:14 -050050 m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix().toUri());
akmhoque53353462014-04-22 08:43:45 -050051 m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime());
akmhoquec8a10f72014-04-25 18:42:55 -050052 m_sequencingManager.setSeqFileName(m_confParam.getSeqFileDir());
53 m_sequencingManager.initiateSeqNoFromFile();
akmhoque53353462014-04-22 08:43:45 -050054 /* debugging purpose start */
Yingdi Yu0c217822014-04-24 14:22:42 -070055 cout << m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -050056 m_adjacencyList.print();
57 m_namePrefixList.print();
akmhoque53353462014-04-22 08:43:45 -050058 /* debugging purpose end */
akmhoque31d1d4b2014-05-05 22:08:14 -050059 m_nlsrLsdb.buildAndInstallOwnNameLsa();
60 m_nlsrLsdb.buildAndInstallOwnCoordinateLsa();
61 setInfoInterestFilter();
62 setLsaInterestFilter();
63 m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncSyncPrefix().toUri());
akmhoquec8a10f72014-04-25 18:42:55 -050064 m_syncLogicHandler.createSyncSocket(boost::ref(*this));
akmhoque31d1d4b2014-05-05 22:08:14 -050065 //m_interestManager.scheduleInfoInterest(10);
66 m_helloProtocol.scheduleInterest(10);
akmhoque53353462014-04-22 08:43:45 -050067}
akmhoque5a44dd42014-03-12 18:11:32 -050068
akmhoque53353462014-04-22 08:43:45 -050069void
70Nlsr::startEventLoop()
71{
akmhoquefdbddb12014-05-02 18:35:19 -050072 m_nlsrFace.processEvents();
akmhoque53353462014-04-22 08:43:45 -050073}
akmhoque5a44dd42014-03-12 18:11:32 -050074
akmhoquefdbddb12014-05-02 18:35:19 -050075void
akmhoque53353462014-04-22 08:43:45 -050076Nlsr::usage(const string& progname)
77{
78 cout << "Usage: " << progname << " [OPTIONS...]" << endl;
79 cout << " NDN routing...." << endl;
80 cout << " -d, --daemon Run in daemon mode" << endl;
81 cout << " -f, --config_file Specify configuration file name" << endl;
82 cout << " -p, --api_port port where api client will connect" << endl;
83 cout << " -h, --help Display this help message" << endl;
akmhoque53353462014-04-22 08:43:45 -050084}
akmhoque298385a2014-02-13 14:13:09 -060085
akmhoqueb1710aa2014-02-19 17:13:36 -060086
87} // namespace nlsr