blob: a21aa3f123bd72fd03e399e268790c462b6d92bb [file] [log] [blame]
akmhoque87347a32014-01-31 11:00:44 -06001#include <ndn-cpp-dev/face.hpp>
2#include <ndn-cpp-dev/security/key-chain.hpp>
3#include <ndn-cpp-dev/util/scheduler.hpp>
4
5#include <cstdlib>
6
7#include "nlsr.hpp"
akmhoque204e7542014-01-31 16:08:25 -06008#include "nlsr_conf_param.hpp"
9#include "nlsr_conf_processor.hpp"
akmhoquebd7c8e62014-02-01 14:57:40 -060010#include "nlsr_lsdb.hpp"
akmhoque87347a32014-01-31 11:00:44 -060011
12
13using namespace ndn;
14using namespace std;
15
akmhoque87347a32014-01-31 11:00:44 -060016void
17nlsr::nlsrRegistrationFailed(const ptr_lib::shared_ptr<const Name>&)
18{
akmhoque147f4992014-01-31 15:52:49 -060019 cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
akmhoquea8cd6b92014-01-31 20:13:26 -060020 getNlsrFace().shutdown();
akmhoque87347a32014-01-31 11:00:44 -060021}
22
akmhoque147f4992014-01-31 15:52:49 -060023
akmhoque87347a32014-01-31 11:00:44 -060024void
akmhoque147f4992014-01-31 15:52:49 -060025nlsr::setInterestFilterNlsr(const string& name)
akmhoque87347a32014-01-31 11:00:44 -060026{
akmhoquea8cd6b92014-01-31 20:13:26 -060027 getNlsrFace().setInterestFilter(name,
akmhoque147f4992014-01-31 15:52:49 -060028 func_lib::bind(&interestManager::processInterest, &im,
29 boost::ref(*this), _1, _2),
akmhoque87347a32014-01-31 11:00:44 -060030 func_lib::bind(&nlsr::nlsrRegistrationFailed, this, _1));
31}
32
akmhoque147f4992014-01-31 15:52:49 -060033
akmhoque87347a32014-01-31 11:00:44 -060034void
akmhoque147f4992014-01-31 15:52:49 -060035nlsr::startEventLoop()
akmhoque87347a32014-01-31 11:00:44 -060036{
akmhoquea8cd6b92014-01-31 20:13:26 -060037 getNlsrFace().processEvents();
akmhoque87347a32014-01-31 11:00:44 -060038}
39
40int
akmhoque147f4992014-01-31 15:52:49 -060041nlsr::usage(const string& progname)
42{
akmhoque87347a32014-01-31 11:00:44 -060043
44 cout << "Usage: " << progname << " [OPTIONS...]"<<endl;
45 cout << " NDN routing...." << endl;
46 cout << " -d, --daemon Run in daemon mode" << endl;
47 cout << " -f, --config_file Specify configuration file name" <<endl;
48 cout << " -p, --api_port port where api client will connect" <<endl;
49 cout << " -h, --help Display this help message" << endl;
50
51 exit(EXIT_FAILURE);
52}
53
54int
55main(){
56
57 nlsr nlsr;
58 nlsr.setConfFileName("nlsr.conf");
59 ConfFileProcessor cfp(nlsr.getConfFileName());
60 cfp.processConfFile(nlsr);
akmhoquea8cd6b92014-01-31 20:13:26 -060061 nlsr.getConfParameter().buildRouterPrefix();
akmhoquebd7c8e62014-02-01 14:57:40 -060062
63 nlsr.getLsdb().buildAndInstallOwnNameLsa(nlsr);
akmhoque3c6bd922014-02-01 17:10:17 -060064 nlsr.getLsdb().buildAndInstallOwnCorLsa(nlsr);
akmhoquebd7c8e62014-02-01 14:57:40 -060065
66
akmhoque87347a32014-01-31 11:00:44 -060067/* debugging purpose start */
akmhoquecd552472014-02-01 21:22:16 -060068 cout << nlsr.getConfParameter();
akmhoquea8cd6b92014-01-31 20:13:26 -060069 nlsr.getAdl().printAdl();
70 nlsr.getNpl().printNpl();
akmhoquebd7c8e62014-02-01 14:57:40 -060071 nlsr.getLsdb().printNameLsdb();
akmhoque3c6bd922014-02-01 17:10:17 -060072 nlsr.getLsdb().printCorLsdb();
akmhoque87347a32014-01-31 11:00:44 -060073/* debugging purpose end */
akmhoquea8cd6b92014-01-31 20:13:26 -060074 nlsr.setInterestFilterNlsr(nlsr.getConfParameter().getRouterPrefix());
75 nlsr.getIm().scheduleInfoInterest(nlsr,1);
akmhoque87347a32014-01-31 11:00:44 -060076
77
78
79
80 try{
81 nlsr.startEventLoop();
82 }catch(std::exception &e) {
83 std::cerr << "ERROR: " << e.what() << std::endl;
84 }
85
86 return 0;
87}