blob: a381737c34a57f1bf63cccd62a162a0cdcdd8123 [file] [log] [blame]
Yingdi Yu40cd1c32014-04-17 15:02:17 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince Lehman9dce0c92015-02-09 12:53:41 -06003 * Copyright (c) 2014-2015, The University of Memphis,
4 * Regents of the University of California,
5 * Arizona Board of Regents.
Yingdi Yu40cd1c32014-04-17 15:02:17 -07006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 **/
Alexander Afanasyevb669f9c2014-11-14 12:41:54 -080021
22#include <ndn-cxx/util/scheduler.hpp>
23
akmhoque53353462014-04-22 08:43:45 -050024#include "conf-file-processor.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050025#include "logger.hpp"
Vince Lehman7c603292014-09-11 17:48:16 -050026#include "nlsr.hpp"
Vince Lehmanb722b102014-08-24 16:33:49 -050027#include "version.hpp"
Yingdi Yu40cd1c32014-04-17 15:02:17 -070028
Alexander Afanasyevb669f9c2014-11-14 12:41:54 -080029// boost needs to be included after ndn-cxx, otherwise there will be conflict with _1, _2, ...
Vince Lehman7c603292014-09-11 17:48:16 -050030#include <boost/asio.hpp>
31#include <boost/cstdint.hpp>
32
Alexander Afanasyev7decbbf2014-08-24 21:29:01 -070033namespace nlsr {
Yingdi Yu40cd1c32014-04-17 15:02:17 -070034
Alexander Afanasyev7decbbf2014-08-24 21:29:01 -070035int
akmhoquefdbddb12014-05-02 18:35:19 -050036main(int32_t argc, char** argv)
Yingdi Yu40cd1c32014-04-17 15:02:17 -070037{
Vince Lehman7c603292014-09-11 17:48:16 -050038 boost::asio::io_service ioService;
39 ndn::Scheduler scheduler(ioService);
Vince Lehman904c2412014-09-23 19:36:11 -050040 ndn::Face face(ioService);
Vince Lehman7c603292014-09-11 17:48:16 -050041
Vince Lehman904c2412014-09-23 19:36:11 -050042 Nlsr nlsr(ioService, scheduler, face);
Vince Lehman7c603292014-09-11 17:48:16 -050043
akmhoquefdbddb12014-05-02 18:35:19 -050044 std::string programName(argv[0]);
akmhoqueb6450b12014-04-24 00:01:03 -050045 nlsr.setConfFileName("nlsr.conf");
akmhoquefdbddb12014-05-02 18:35:19 -050046 int32_t opt;
Vince Lehmanb722b102014-08-24 16:33:49 -050047 while ((opt = getopt(argc, argv, "df:hV")) != -1) {
Yingdi Yu40cd1c32014-04-17 15:02:17 -070048 switch (opt)
Vince Lehmanb722b102014-08-24 16:33:49 -050049 {
Yingdi Yu40cd1c32014-04-17 15:02:17 -070050 case 'f':
akmhoqueb6450b12014-04-24 00:01:03 -050051 nlsr.setConfFileName(optarg);
Yingdi Yu40cd1c32014-04-17 15:02:17 -070052 break;
53 case 'd':
akmhoque0494c252014-07-23 23:46:44 -050054 nlsr.setIsDaemonProcess(true);
Yingdi Yu40cd1c32014-04-17 15:02:17 -070055 break;
Vince Lehmanb722b102014-08-24 16:33:49 -050056 case 'V':
57 std::cout << NLSR_VERSION_BUILD_STRING << std::endl;
58 return EXIT_SUCCESS;
59 break;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070060 case 'h':
61 default:
akmhoqueb6450b12014-04-24 00:01:03 -050062 nlsr.usage(programName);
Yingdi Yu40cd1c32014-04-17 15:02:17 -070063 return EXIT_FAILURE;
Vince Lehmanb722b102014-08-24 16:33:49 -050064 }
Yingdi Yu40cd1c32014-04-17 15:02:17 -070065 }
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050066
akmhoqueb6450b12014-04-24 00:01:03 -050067 ConfFileProcessor cfp(nlsr, nlsr.getConfFileName());
Alexander Afanasyev7decbbf2014-08-24 21:29:01 -070068 if (!cfp.processConfFile()) {
akmhoquead5fe952014-06-26 13:34:12 -050069 std::cerr << "Error in configuration file processing! Exiting from NLSR" << std::endl;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070070 return EXIT_FAILURE;
71 }
Vince Lehmanf99b87f2014-08-26 15:54:27 -050072
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050073 if (nlsr.getConfParameter().isLog4CxxConfAvailable()) {
74 INIT_LOG4CXX(nlsr.getConfParameter().getLog4CxxConfPath());
75 }
76 else {
77 INIT_LOGGERS(nlsr.getConfParameter().getLogDir(), nlsr.getConfParameter().getLogLevel());
78 }
79
akmhoque674b0b12014-05-20 14:33:28 -050080 INIT_LOGGER("Main");
Vince Lehmanf99b87f2014-08-26 15:54:27 -050081
akmhoqueb6450b12014-04-24 00:01:03 -050082 nlsr.initialize();
akmhoque0494c252014-07-23 23:46:44 -050083 if (nlsr.getIsSetDaemonProcess()) {
84 nlsr.daemonize();
85 }
akmhoquefdbddb12014-05-02 18:35:19 -050086 try {
akmhoqueb6450b12014-04-24 00:01:03 -050087 nlsr.startEventLoop();
Yingdi Yu40cd1c32014-04-17 15:02:17 -070088 }
akmhoque31d1d4b2014-05-05 22:08:14 -050089 catch (std::exception& e) {
Vince Lehman9dce0c92015-02-09 12:53:41 -060090 _LOG_FATAL("ERROR: " << e.what());
Yingdi Yu40cd1c32014-04-17 15:02:17 -070091 std::cerr << "ERROR: " << e.what() << std::endl;
Vince Lehman9dce0c92015-02-09 12:53:41 -060092
akmhoque31d1d4b2014-05-05 22:08:14 -050093 nlsr.getFib().clean();
akmhoquee1765152014-06-30 11:32:01 -050094 nlsr.destroyFaces();
Yingdi Yu40cd1c32014-04-17 15:02:17 -070095 }
96 return EXIT_SUCCESS;
97}
Alexander Afanasyev7decbbf2014-08-24 21:29:01 -070098
99} // namespace nlsr
100
101int
102main(int32_t argc, char** argv)
103{
104 return nlsr::main(argc, argv);
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500105}