blob: 8a7e439d8ee8715ce92fe489c0ae1891050f5328 [file] [log] [blame]
Yingdi Yu40cd1c32014-04-17 15:02:17 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
akmhoque3d06e792014-05-27 16:23:20 -050019 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 * \author Yingdi Yu <yingdi@cs.ucla.edu>
22 *
Yingdi Yu40cd1c32014-04-17 15:02:17 -070023 **/
akmhoquefdbddb12014-05-02 18:35:19 -050024#include <boost/cstdint.hpp>
Yingdi Yu40cd1c32014-04-17 15:02:17 -070025#include "nlsr.hpp"
akmhoque53353462014-04-22 08:43:45 -050026#include "conf-file-processor.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050027#include "logger.hpp"
Yingdi Yu40cd1c32014-04-17 15:02:17 -070028
29using namespace nlsr;
30
akmhoquefdbddb12014-05-02 18:35:19 -050031int32_t
32main(int32_t argc, char** argv)
Yingdi Yu40cd1c32014-04-17 15:02:17 -070033{
akmhoqueb6450b12014-04-24 00:01:03 -050034 nlsr::Nlsr nlsr;
akmhoquefdbddb12014-05-02 18:35:19 -050035 std::string programName(argv[0]);
akmhoqueb6450b12014-04-24 00:01:03 -050036 nlsr.setConfFileName("nlsr.conf");
akmhoquefdbddb12014-05-02 18:35:19 -050037 int32_t opt;
akmhoque157b0a42014-05-13 00:26:37 -050038 while ((opt = getopt(argc, argv, "df:p:h")) != -1) {
Yingdi Yu40cd1c32014-04-17 15:02:17 -070039 switch (opt)
akmhoquec8a10f72014-04-25 18:42:55 -050040 {
Yingdi Yu40cd1c32014-04-17 15:02:17 -070041 case 'f':
akmhoqueb6450b12014-04-24 00:01:03 -050042 nlsr.setConfFileName(optarg);
Yingdi Yu40cd1c32014-04-17 15:02:17 -070043 break;
44 case 'd':
akmhoqueb6450b12014-04-24 00:01:03 -050045 nlsr.setIsDaemonProcess(optarg);
Yingdi Yu40cd1c32014-04-17 15:02:17 -070046 break;
47 case 'p':
akmhoque53353462014-04-22 08:43:45 -050048 {
akmhoquefdbddb12014-05-02 18:35:19 -050049 std::stringstream sst(optarg);
akmhoque53353462014-04-22 08:43:45 -050050 int ap;
51 sst >> ap;
akmhoqueb6450b12014-04-24 00:01:03 -050052 nlsr.setApiPort(ap);
akmhoque53353462014-04-22 08:43:45 -050053 }
54 break;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070055 case 'h':
56 default:
akmhoqueb6450b12014-04-24 00:01:03 -050057 nlsr.usage(programName);
Yingdi Yu40cd1c32014-04-17 15:02:17 -070058 return EXIT_FAILURE;
akmhoquec8a10f72014-04-25 18:42:55 -050059 }
Yingdi Yu40cd1c32014-04-17 15:02:17 -070060 }
akmhoqueb6450b12014-04-24 00:01:03 -050061 ConfFileProcessor cfp(nlsr, nlsr.getConfFileName());
akmhoque674b0b12014-05-20 14:33:28 -050062 if(!cfp.processConfFile()) {
akmhoque53353462014-04-22 08:43:45 -050063 std::cerr << "Error in configuration file processing! Exiting from NLSR" <<
64 std::endl;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070065 return EXIT_FAILURE;
66 }
akmhoque674b0b12014-05-20 14:33:28 -050067 INIT_LOGGERS(nlsr.getConfParameter().getLogDir());
68 INIT_LOGGER("Main");
akmhoqueb6450b12014-04-24 00:01:03 -050069 nlsr.initialize();
akmhoquefdbddb12014-05-02 18:35:19 -050070 try {
akmhoqueb6450b12014-04-24 00:01:03 -050071 nlsr.startEventLoop();
Yingdi Yu40cd1c32014-04-17 15:02:17 -070072 }
akmhoque31d1d4b2014-05-05 22:08:14 -050073 catch (std::exception& e) {
Yingdi Yu40cd1c32014-04-17 15:02:17 -070074 std::cerr << "ERROR: " << e.what() << std::endl;
akmhoque31d1d4b2014-05-05 22:08:14 -050075 nlsr.getFib().clean();
Yingdi Yu40cd1c32014-04-17 15:02:17 -070076 }
77 return EXIT_SUCCESS;
78}