Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 4 | * 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 Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 26 | #ifndef NFD_RIB_SERVICE_HPP |
| 27 | #define NFD_RIB_SERVICE_HPP |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 29 | #include "core/config-file.hpp" |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 30 | |
| 31 | #include <ndn-cxx/face.hpp> |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 32 | #include <ndn-cxx/mgmt/dispatcher.hpp> |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 33 | #include <ndn-cxx/security/key-chain.hpp> |
| 34 | #include <ndn-cxx/transport/transport.hpp> |
| 35 | |
| 36 | namespace nfd { |
| 37 | namespace rib { |
| 38 | |
Alexander Afanasyev | c3ea5a7 | 2015-02-12 20:14:16 -0800 | [diff] [blame] | 39 | class RibManager; |
| 40 | |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 41 | /** |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 42 | * \brief initializes and executes NFD-RIB service thread |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 43 | */ |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 44 | class Service : noncopyable |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 45 | { |
| 46 | public: |
| 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 Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 58 | * \brief create NFD-RIB service |
| 59 | * \param configFile absolute or relative path of configuration file |
| 60 | * \param keyChain the KeyChain |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 61 | */ |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 62 | Service(const std::string& configFile, ndn::KeyChain& keyChain); |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 63 | |
| 64 | /** |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 65 | * \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 Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 71 | */ |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 72 | Service(const ConfigSection& config, ndn::KeyChain& keyChain); |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 73 | |
| 74 | /** |
Alexander Afanasyev | c3ea5a7 | 2015-02-12 20:14:16 -0800 | [diff] [blame] | 75 | * \brief Destructor |
| 76 | */ |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 77 | ~Service(); |
Alexander Afanasyev | c3ea5a7 | 2015-02-12 20:14:16 -0800 | [diff] [blame] | 78 | |
| 79 | /** |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 80 | * \brief Perform initialization of NFD-RIB instance |
| 81 | * |
| 82 | * After initialization, NFD-RIB instance can be started by running the global io_service |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 83 | */ |
| 84 | void |
| 85 | initialize(); |
| 86 | |
| 87 | private: |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 88 | /** |
| 89 | * \brief Look into the config file and construct appropriate transport to communicate with NFD |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 90 | * If NFD-RIB instance was initialized with config file, INFO format is assumed |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 91 | */ |
| 92 | shared_ptr<ndn::Transport> |
| 93 | getLocalNfdTransport(); |
| 94 | |
| 95 | private: |
| 96 | std::string m_configFile; |
| 97 | ConfigSection m_configSection; |
| 98 | |
| 99 | ndn::KeyChain& m_keyChain; |
| 100 | unique_ptr<ndn::Face> m_face; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 101 | unique_ptr<ndn::mgmt::Dispatcher> m_dispatcher; |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 102 | unique_ptr<RibManager> m_ribManager; |
| 103 | }; |
| 104 | |
| 105 | } // namespace rib |
| 106 | } // namespace nfd |
| 107 | |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 108 | #endif // NFD_RIB_SERVICE_HPP |