blob: 5cb60d93053fdace94d9a6e68e7220219f8788fb [file] [log] [blame]
Alexander Afanasyev31367922015-02-09 20:51:10 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yanbiao Licf0db022016-01-29 00:54:25 -08003 * Copyright (c) 2014-2016, Regents of the University of California,
Alexander Afanasyev31367922015-02-09 20:51:10 -08004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
Junxiao Shib2600172016-07-11 08:53:53 +000026#ifndef NFD_RIB_SERVICE_HPP
27#define NFD_RIB_SERVICE_HPP
Alexander Afanasyev31367922015-02-09 20:51:10 -080028
29#include "common.hpp"
30#include "core/config-file.hpp"
Alexander Afanasyev31367922015-02-09 20:51:10 -080031
32#include <ndn-cxx/face.hpp>
33#include <ndn-cxx/security/key-chain.hpp>
34#include <ndn-cxx/transport/transport.hpp>
Yanbiao Licf0db022016-01-29 00:54:25 -080035#include <ndn-cxx/mgmt/dispatcher.hpp>
Alexander Afanasyev31367922015-02-09 20:51:10 -080036
37namespace nfd {
38namespace rib {
39
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080040class RibManager;
41
Alexander Afanasyev31367922015-02-09 20:51:10 -080042/**
Junxiao Shib2600172016-07-11 08:53:53 +000043 * \brief initializes and executes NFD-RIB service thread
Alexander Afanasyev31367922015-02-09 20:51:10 -080044 */
Junxiao Shib2600172016-07-11 08:53:53 +000045class Service : noncopyable
Alexander Afanasyev31367922015-02-09 20:51:10 -080046{
47public:
48 class Error : public std::runtime_error
49 {
50 public:
51 explicit
52 Error(const std::string& what)
53 : std::runtime_error(what)
54 {
55 }
56 };
57
58 /**
Junxiao Shib2600172016-07-11 08:53:53 +000059 * \brief create NFD-RIB service
60 * \param configFile absolute or relative path of configuration file
61 * \param keyChain the KeyChain
Alexander Afanasyev31367922015-02-09 20:51:10 -080062 */
Junxiao Shib2600172016-07-11 08:53:53 +000063 Service(const std::string& configFile, ndn::KeyChain& keyChain);
Alexander Afanasyev31367922015-02-09 20:51:10 -080064
65 /**
Junxiao Shib2600172016-07-11 08:53:53 +000066 * \brief create NFD-RIB service
67 * \param config parsed configuration section
68 * \param keyChain the KeyChain
69 * \note This constructor overload is more appropriate for integrated environments,
70 * such as NS-3 or android. Error messages related to configuration file
71 * will use "internal://nfd.conf" as configuration filename.
Alexander Afanasyev31367922015-02-09 20:51:10 -080072 */
Junxiao Shib2600172016-07-11 08:53:53 +000073 Service(const ConfigSection& config, ndn::KeyChain& keyChain);
Alexander Afanasyev31367922015-02-09 20:51:10 -080074
75 /**
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080076 * \brief Destructor
77 */
Junxiao Shib2600172016-07-11 08:53:53 +000078 ~Service();
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080079
80 /**
Junxiao Shib2600172016-07-11 08:53:53 +000081 * \brief Perform initialization of NFD-RIB instance
82 *
83 * After initialization, NFD-RIB instance can be started by running the global io_service
Alexander Afanasyev31367922015-02-09 20:51:10 -080084 */
85 void
86 initialize();
87
88private:
89 void
90 initializeLogging();
91
92 /**
93 * \brief Look into the config file and construct appropriate transport to communicate with NFD
Junxiao Shib2600172016-07-11 08:53:53 +000094 * If NFD-RIB instance was initialized with config file, INFO format is assumed
Alexander Afanasyev31367922015-02-09 20:51:10 -080095 */
96 shared_ptr<ndn::Transport>
97 getLocalNfdTransport();
98
99private:
100 std::string m_configFile;
101 ConfigSection m_configSection;
102
103 ndn::KeyChain& m_keyChain;
104 unique_ptr<ndn::Face> m_face;
Yanbiao Licf0db022016-01-29 00:54:25 -0800105 unique_ptr<ndn::mgmt::Dispatcher> m_dispatcher;
Alexander Afanasyev31367922015-02-09 20:51:10 -0800106 unique_ptr<RibManager> m_ribManager;
107};
108
109} // namespace rib
110} // namespace nfd
111
Junxiao Shib2600172016-07-11 08:53:53 +0000112#endif // NFD_RIB_SERVICE_HPP