blob: 35223dc7220b2b5798aa5d30cf6d97449f493bf9 [file] [log] [blame]
Alexander Afanasyev31367922015-02-09 20:51:10 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoa3148082018-04-12 18:21:54 -04002/*
3 * Copyright (c) 2014-2018, 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
Alexander Afanasyev31367922015-02-09 20:51:10 -080029#include "core/config-file.hpp"
Alexander Afanasyev31367922015-02-09 20:51:10 -080030
31#include <ndn-cxx/face.hpp>
Davide Pesaventoa3148082018-04-12 18:21:54 -040032#include <ndn-cxx/mgmt/dispatcher.hpp>
Alexander Afanasyev31367922015-02-09 20:51:10 -080033#include <ndn-cxx/security/key-chain.hpp>
34#include <ndn-cxx/transport/transport.hpp>
35
36namespace nfd {
37namespace rib {
38
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080039class RibManager;
40
Alexander Afanasyev31367922015-02-09 20:51:10 -080041/**
Junxiao Shib2600172016-07-11 08:53:53 +000042 * \brief initializes and executes NFD-RIB service thread
Alexander Afanasyev31367922015-02-09 20:51:10 -080043 */
Junxiao Shib2600172016-07-11 08:53:53 +000044class Service : noncopyable
Alexander Afanasyev31367922015-02-09 20:51:10 -080045{
46public:
47 class Error : public std::runtime_error
48 {
49 public:
50 explicit
51 Error(const std::string& what)
52 : std::runtime_error(what)
53 {
54 }
55 };
56
57 /**
Junxiao Shib2600172016-07-11 08:53:53 +000058 * \brief create NFD-RIB service
59 * \param configFile absolute or relative path of configuration file
60 * \param keyChain the KeyChain
Alexander Afanasyev31367922015-02-09 20:51:10 -080061 */
Junxiao Shib2600172016-07-11 08:53:53 +000062 Service(const std::string& configFile, ndn::KeyChain& keyChain);
Alexander Afanasyev31367922015-02-09 20:51:10 -080063
64 /**
Junxiao Shib2600172016-07-11 08:53:53 +000065 * \brief create NFD-RIB service
66 * \param config parsed configuration section
67 * \param keyChain the KeyChain
68 * \note This constructor overload is more appropriate for integrated environments,
69 * such as NS-3 or android. Error messages related to configuration file
70 * will use "internal://nfd.conf" as configuration filename.
Alexander Afanasyev31367922015-02-09 20:51:10 -080071 */
Junxiao Shib2600172016-07-11 08:53:53 +000072 Service(const ConfigSection& config, ndn::KeyChain& keyChain);
Alexander Afanasyev31367922015-02-09 20:51:10 -080073
74 /**
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080075 * \brief Destructor
76 */
Junxiao Shib2600172016-07-11 08:53:53 +000077 ~Service();
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080078
79 /**
Junxiao Shib2600172016-07-11 08:53:53 +000080 * \brief Perform initialization of NFD-RIB instance
81 *
82 * After initialization, NFD-RIB instance can be started by running the global io_service
Alexander Afanasyev31367922015-02-09 20:51:10 -080083 */
84 void
85 initialize();
86
87private:
Alexander Afanasyev31367922015-02-09 20:51:10 -080088 /**
89 * \brief Look into the config file and construct appropriate transport to communicate with NFD
Junxiao Shib2600172016-07-11 08:53:53 +000090 * If NFD-RIB instance was initialized with config file, INFO format is assumed
Alexander Afanasyev31367922015-02-09 20:51:10 -080091 */
92 shared_ptr<ndn::Transport>
93 getLocalNfdTransport();
94
95private:
96 std::string m_configFile;
97 ConfigSection m_configSection;
98
99 ndn::KeyChain& m_keyChain;
100 unique_ptr<ndn::Face> m_face;
Yanbiao Licf0db022016-01-29 00:54:25 -0800101 unique_ptr<ndn::mgmt::Dispatcher> m_dispatcher;
Alexander Afanasyev31367922015-02-09 20:51:10 -0800102 unique_ptr<RibManager> m_ribManager;
103};
104
105} // namespace rib
106} // namespace nfd
107
Junxiao Shib2600172016-07-11 08:53:53 +0000108#endif // NFD_RIB_SERVICE_HPP