blob: d7657fa96cbb9c8e74e91d85003b3431dc60fdcd [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/>.
19 **/
akmhoquefdbddb12014-05-02 18:35:19 -050020#include <boost/cstdint.hpp>
Yingdi Yu40cd1c32014-04-17 15:02:17 -070021#include "nlsr.hpp"
akmhoque53353462014-04-22 08:43:45 -050022#include "conf-file-processor.hpp"
Yingdi Yu40cd1c32014-04-17 15:02:17 -070023
24using namespace nlsr;
25
akmhoquefdbddb12014-05-02 18:35:19 -050026int32_t
27main(int32_t argc, char** argv)
Yingdi Yu40cd1c32014-04-17 15:02:17 -070028{
akmhoqueb6450b12014-04-24 00:01:03 -050029 nlsr::Nlsr nlsr;
akmhoquefdbddb12014-05-02 18:35:19 -050030 std::string programName(argv[0]);
akmhoqueb6450b12014-04-24 00:01:03 -050031 nlsr.setConfFileName("nlsr.conf");
akmhoquefdbddb12014-05-02 18:35:19 -050032 int32_t opt;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070033 while ((opt = getopt(argc, argv, "df:p:h")) != -1)
34 {
35 switch (opt)
akmhoquec8a10f72014-04-25 18:42:55 -050036 {
Yingdi Yu40cd1c32014-04-17 15:02:17 -070037 case 'f':
akmhoqueb6450b12014-04-24 00:01:03 -050038 nlsr.setConfFileName(optarg);
Yingdi Yu40cd1c32014-04-17 15:02:17 -070039 break;
40 case 'd':
akmhoqueb6450b12014-04-24 00:01:03 -050041 nlsr.setIsDaemonProcess(optarg);
Yingdi Yu40cd1c32014-04-17 15:02:17 -070042 break;
43 case 'p':
akmhoque53353462014-04-22 08:43:45 -050044 {
akmhoquefdbddb12014-05-02 18:35:19 -050045 std::stringstream sst(optarg);
akmhoque53353462014-04-22 08:43:45 -050046 int ap;
47 sst >> ap;
akmhoqueb6450b12014-04-24 00:01:03 -050048 nlsr.setApiPort(ap);
akmhoque53353462014-04-22 08:43:45 -050049 }
50 break;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070051 case 'h':
52 default:
akmhoqueb6450b12014-04-24 00:01:03 -050053 nlsr.usage(programName);
Yingdi Yu40cd1c32014-04-17 15:02:17 -070054 return EXIT_FAILURE;
akmhoquec8a10f72014-04-25 18:42:55 -050055 }
Yingdi Yu40cd1c32014-04-17 15:02:17 -070056 }
akmhoqueb6450b12014-04-24 00:01:03 -050057 ConfFileProcessor cfp(nlsr, nlsr.getConfFileName());
akmhoquefdbddb12014-05-02 18:35:19 -050058 int32_t res = cfp.processConfFile();
akmhoque53353462014-04-22 08:43:45 -050059 if (res < 0)
Yingdi Yu40cd1c32014-04-17 15:02:17 -070060 {
akmhoque53353462014-04-22 08:43:45 -050061 std::cerr << "Error in configuration file processing! Exiting from NLSR" <<
62 std::endl;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070063 return EXIT_FAILURE;
64 }
akmhoqueb6450b12014-04-24 00:01:03 -050065 nlsr.initialize();
akmhoquefdbddb12014-05-02 18:35:19 -050066 try {
akmhoqueb6450b12014-04-24 00:01:03 -050067 nlsr.startEventLoop();
Yingdi Yu40cd1c32014-04-17 15:02:17 -070068 }
akmhoquefdbddb12014-05-02 18:35:19 -050069 catch (std::exception& e){
Yingdi Yu40cd1c32014-04-17 15:02:17 -070070 std::cerr << "ERROR: " << e.what() << std::endl;
akmhoquefdbddb12014-05-02 18:35:19 -050071 nlsr.getFib().clean(nlsr);
Yingdi Yu40cd1c32014-04-17 15:02:17 -070072 }
73 return EXIT_SUCCESS;
74}