blob: 99552b055fbf3fda6cd7231fdb83274c54d9f460 [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"
akmhoque87347a32014-01-31 11:00:44 -060010
11
12using namespace ndn;
13using namespace std;
14
akmhoque87347a32014-01-31 11:00:44 -060015void
16nlsr::nlsrRegistrationFailed(const ptr_lib::shared_ptr<const Name>&)
17{
akmhoque147f4992014-01-31 15:52:49 -060018 cerr << "ERROR: Failed to register prefix in local hub's daemon" << endl;
akmhoquea8cd6b92014-01-31 20:13:26 -060019 getNlsrFace().shutdown();
akmhoque87347a32014-01-31 11:00:44 -060020}
21
akmhoque147f4992014-01-31 15:52:49 -060022
akmhoque87347a32014-01-31 11:00:44 -060023void
akmhoque147f4992014-01-31 15:52:49 -060024nlsr::setInterestFilterNlsr(const string& name)
akmhoque87347a32014-01-31 11:00:44 -060025{
akmhoquea8cd6b92014-01-31 20:13:26 -060026 getNlsrFace().setInterestFilter(name,
akmhoque147f4992014-01-31 15:52:49 -060027 func_lib::bind(&interestManager::processInterest, &im,
28 boost::ref(*this), _1, _2),
akmhoque87347a32014-01-31 11:00:44 -060029 func_lib::bind(&nlsr::nlsrRegistrationFailed, this, _1));
30}
31
akmhoque147f4992014-01-31 15:52:49 -060032
akmhoque87347a32014-01-31 11:00:44 -060033void
akmhoque147f4992014-01-31 15:52:49 -060034nlsr::startEventLoop()
akmhoque87347a32014-01-31 11:00:44 -060035{
akmhoquea8cd6b92014-01-31 20:13:26 -060036 getNlsrFace().processEvents();
akmhoque87347a32014-01-31 11:00:44 -060037}
38
39int
akmhoque147f4992014-01-31 15:52:49 -060040nlsr::usage(const string& progname)
41{
akmhoque87347a32014-01-31 11:00:44 -060042
43 cout << "Usage: " << progname << " [OPTIONS...]"<<endl;
44 cout << " NDN routing...." << endl;
45 cout << " -d, --daemon Run in daemon mode" << endl;
46 cout << " -f, --config_file Specify configuration file name" <<endl;
47 cout << " -p, --api_port port where api client will connect" <<endl;
48 cout << " -h, --help Display this help message" << endl;
49
50 exit(EXIT_FAILURE);
51}
52
53int
54main(){
55
56 nlsr nlsr;
57 nlsr.setConfFileName("nlsr.conf");
58 ConfFileProcessor cfp(nlsr.getConfFileName());
59 cfp.processConfFile(nlsr);
akmhoquea8cd6b92014-01-31 20:13:26 -060060 nlsr.getConfParameter().buildRouterPrefix();
akmhoque87347a32014-01-31 11:00:44 -060061/* debugging purpose start */
akmhoquea8cd6b92014-01-31 20:13:26 -060062 cout << nlsr.getConfParameter(); ;
63 nlsr.getAdl().printAdl();
64 nlsr.getNpl().printNpl();
akmhoque87347a32014-01-31 11:00:44 -060065/* debugging purpose end */
akmhoquea8cd6b92014-01-31 20:13:26 -060066 nlsr.setInterestFilterNlsr(nlsr.getConfParameter().getRouterPrefix());
67 nlsr.getIm().scheduleInfoInterest(nlsr,1);
akmhoque87347a32014-01-31 11:00:44 -060068
69
70
71
72 try{
73 nlsr.startEventLoop();
74 }catch(std::exception &e) {
75 std::cerr << "ERROR: " << e.what() << std::endl;
76 }
77
78 return 0;
79}