blob: a55f63483ebffe9c067ca92f3fae0d93acd19774 [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"
akmhoque157b0a42014-05-13 00:26:37 -05007#include "adjacent.hpp"
akmhoque2bb198e2014-02-28 11:46:27 -06008
akmhoque298385a2014-02-13 14:13:09 -06009
akmhoque53353462014-04-22 08:43:45 -050010namespace nlsr {
11
12using namespace ndn;
13using namespace std;
14
15void
16Nlsr::registrationFailed(const ndn::Name& name)
akmhoque298385a2014-02-13 14:13:09 -060017{
akmhoquefdbddb12014-05-02 18:35:19 -050018 std::cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
19 throw Error("Error: Prefix registration failed");
akmhoque53353462014-04-22 08:43:45 -050020}
akmhoque1fd8c1e2014-02-19 19:41:49 -060021
akmhoque157b0a42014-05-13 00:26:37 -050022void
23Nlsr::onRegistrationSuccess(const ndn::Name& name)
24{
25}
akmhoque1fd8c1e2014-02-19 19:41:49 -060026
akmhoque53353462014-04-22 08:43:45 -050027void
akmhoque31d1d4b2014-05-05 22:08:14 -050028Nlsr::setInfoInterestFilter()
akmhoque53353462014-04-22 08:43:45 -050029{
akmhoque31d1d4b2014-05-05 22:08:14 -050030 ndn::Name name(m_confParam.getRouterPrefix());
akmhoquefdbddb12014-05-02 18:35:19 -050031 getNlsrFace().setInterestFilter(name,
akmhoque31d1d4b2014-05-05 22:08:14 -050032 ndn::bind(&HelloProtocol::processInterest,
33 &m_helloProtocol, _1, _2),
akmhoque157b0a42014-05-13 00:26:37 -050034 ndn::bind(&Nlsr::onRegistrationSuccess, this, _1),
akmhoque31d1d4b2014-05-05 22:08:14 -050035 ndn::bind(&Nlsr::registrationFailed, this, _1));
36}
37
38void
39Nlsr::setLsaInterestFilter()
40{
akmhoque157b0a42014-05-13 00:26:37 -050041 ndn::Name name = m_confParam.getLsaPrefix();
akmhoque31d1d4b2014-05-05 22:08:14 -050042 name.append(m_confParam.getRouterPrefix());
43 getNlsrFace().setInterestFilter(name,
44 ndn::bind(&Lsdb::processInterest,
45 &m_nlsrLsdb, _1, _2),
akmhoque157b0a42014-05-13 00:26:37 -050046 ndn::bind(&Nlsr::onRegistrationSuccess, this, _1),
akmhoquefdbddb12014-05-02 18:35:19 -050047 ndn::bind(&Nlsr::registrationFailed, this, _1));
akmhoque53353462014-04-22 08:43:45 -050048}
49
50void
akmhoque157b0a42014-05-13 00:26:37 -050051Nlsr::registerPrefixes()
52{
53 std::string strategy("ndn:/localhost/nfd/strategy/broadcast");
54 std::list<Adjacent>& adjacents = m_adjacencyList.getAdjList();
55 for (std::list<Adjacent>::iterator it = adjacents.begin();
56 it != adjacents.end(); it++) {
57 m_fib.registerPrefix((*it).getName(), (*it).getConnectingFaceUri(),
58 (*it).getLinkCost(), 31536000); /* One Year in seconds */
59 m_fib.registerPrefix(m_confParam.getChronosyncPrefix(),
60 (*it).getConnectingFaceUri(), (*it).getLinkCost(), 31536000);
61 m_fib.registerPrefix(m_confParam.getLsaPrefix(),
62 (*it).getConnectingFaceUri(), (*it).getLinkCost(), 31536000);
63 m_fib.setStrategy((*it).getName(), strategy);
64 }
65
66 m_fib.setStrategy(m_confParam.getChronosyncPrefix(), strategy);
67 m_fib.setStrategy(m_confParam.getLsaPrefix(), strategy);
68}
69
70void
akmhoque53353462014-04-22 08:43:45 -050071Nlsr::initialize()
72{
73 m_confParam.buildRouterPrefix();
74 m_nlsrLsdb.setLsaRefreshTime(m_confParam.getLsaRefreshTime());
akmhoque31d1d4b2014-05-05 22:08:14 -050075 m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix().toUri());
akmhoque53353462014-04-22 08:43:45 -050076 m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime());
akmhoquec8a10f72014-04-25 18:42:55 -050077 m_sequencingManager.setSeqFileName(m_confParam.getSeqFileDir());
78 m_sequencingManager.initiateSeqNoFromFile();
akmhoque53353462014-04-22 08:43:45 -050079 /* debugging purpose start */
Yingdi Yu0c217822014-04-24 14:22:42 -070080 cout << m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -050081 m_adjacencyList.print();
82 m_namePrefixList.print();
akmhoque53353462014-04-22 08:43:45 -050083 /* debugging purpose end */
akmhoque157b0a42014-05-13 00:26:37 -050084 registerPrefixes();
akmhoque31d1d4b2014-05-05 22:08:14 -050085 m_nlsrLsdb.buildAndInstallOwnNameLsa();
86 m_nlsrLsdb.buildAndInstallOwnCoordinateLsa();
87 setInfoInterestFilter();
88 setLsaInterestFilter();
akmhoque157b0a42014-05-13 00:26:37 -050089 m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncPrefix().toUri());
akmhoquec8a10f72014-04-25 18:42:55 -050090 m_syncLogicHandler.createSyncSocket(boost::ref(*this));
akmhoque31d1d4b2014-05-05 22:08:14 -050091 //m_interestManager.scheduleInfoInterest(10);
92 m_helloProtocol.scheduleInterest(10);
akmhoque53353462014-04-22 08:43:45 -050093}
akmhoque5a44dd42014-03-12 18:11:32 -050094
akmhoque53353462014-04-22 08:43:45 -050095void
96Nlsr::startEventLoop()
97{
akmhoquefdbddb12014-05-02 18:35:19 -050098 m_nlsrFace.processEvents();
akmhoque53353462014-04-22 08:43:45 -050099}
akmhoque5a44dd42014-03-12 18:11:32 -0500100
akmhoquefdbddb12014-05-02 18:35:19 -0500101void
akmhoque53353462014-04-22 08:43:45 -0500102Nlsr::usage(const string& progname)
103{
104 cout << "Usage: " << progname << " [OPTIONS...]" << endl;
105 cout << " NDN routing...." << endl;
106 cout << " -d, --daemon Run in daemon mode" << endl;
107 cout << " -f, --config_file Specify configuration file name" << endl;
108 cout << " -p, --api_port port where api client will connect" << endl;
109 cout << " -h, --help Display this help message" << endl;
akmhoque53353462014-04-22 08:43:45 -0500110}
akmhoque298385a2014-02-13 14:13:09 -0600111
akmhoqueb1710aa2014-02-19 17:13:36 -0600112
113} // namespace nlsr