blob: 194fbe9b2bfedbe7f0f35dcfb2d55ffa64e6f09e [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);
64
65
akmhoque87347a32014-01-31 11:00:44 -060066/* debugging purpose start */
akmhoquea8cd6b92014-01-31 20:13:26 -060067 cout << nlsr.getConfParameter(); ;
68 nlsr.getAdl().printAdl();
69 nlsr.getNpl().printNpl();
akmhoquebd7c8e62014-02-01 14:57:40 -060070 nlsr.getLsdb().printNameLsdb();
akmhoque87347a32014-01-31 11:00:44 -060071/* debugging purpose end */
akmhoquea8cd6b92014-01-31 20:13:26 -060072 nlsr.setInterestFilterNlsr(nlsr.getConfParameter().getRouterPrefix());
73 nlsr.getIm().scheduleInfoInterest(nlsr,1);
akmhoque87347a32014-01-31 11:00:44 -060074
75
76
77
78 try{
79 nlsr.startEventLoop();
80 }catch(std::exception &e) {
81 std::cerr << "ERROR: " << e.what() << std::endl;
82 }
83
84 return 0;
85}