blob: a32d996eaee0f8510e67e0c4844ad96a9d17686c [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
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000029#include "rib.hpp"
Alexander Afanasyev31367922015-02-09 20:51:10 -080030#include "core/config-file.hpp"
Alexander Afanasyev31367922015-02-09 20:51:10 -080031
32#include <ndn-cxx/face.hpp>
Davide Pesaventoa3148082018-04-12 18:21:54 -040033#include <ndn-cxx/mgmt/dispatcher.hpp>
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000034#include <ndn-cxx/mgmt/nfd/controller.hpp>
Alexander Afanasyev31367922015-02-09 20:51:10 -080035#include <ndn-cxx/security/key-chain.hpp>
36#include <ndn-cxx/transport/transport.hpp>
37
38namespace nfd {
39namespace rib {
40
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000041class AutoPrefixPropagator;
42class FibUpdater;
43class Readvertise;
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080044class RibManager;
45
Alexander Afanasyev31367922015-02-09 20:51:10 -080046/**
Junxiao Shib2600172016-07-11 08:53:53 +000047 * \brief initializes and executes NFD-RIB service thread
Teng Liang04d5ce62018-08-06 10:20:24 +080048 *
49 * Only one instance of this class can be created at any time
Alexander Afanasyev31367922015-02-09 20:51:10 -080050 */
Junxiao Shib2600172016-07-11 08:53:53 +000051class Service : noncopyable
Alexander Afanasyev31367922015-02-09 20:51:10 -080052{
53public:
54 class Error : public std::runtime_error
55 {
56 public:
57 explicit
58 Error(const std::string& what)
59 : std::runtime_error(what)
60 {
61 }
62 };
63
64 /**
Junxiao Shib2600172016-07-11 08:53:53 +000065 * \brief create NFD-RIB service
66 * \param configFile absolute or relative path of configuration file
67 * \param keyChain the KeyChain
Teng Liang04d5ce62018-08-06 10:20:24 +080068 * \throw std::logic_error Instance of rib::Service has been already constructed
69 * \throw std::logic_error Instance of rib::Service is not constructed on RIB thread
Alexander Afanasyev31367922015-02-09 20:51:10 -080070 */
Junxiao Shib2600172016-07-11 08:53:53 +000071 Service(const std::string& configFile, ndn::KeyChain& keyChain);
Alexander Afanasyev31367922015-02-09 20:51:10 -080072
73 /**
Junxiao Shib2600172016-07-11 08:53:53 +000074 * \brief create NFD-RIB service
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000075 * \param configSection parsed configuration section
Junxiao Shib2600172016-07-11 08:53:53 +000076 * \param keyChain the KeyChain
77 * \note This constructor overload is more appropriate for integrated environments,
78 * such as NS-3 or android. Error messages related to configuration file
79 * will use "internal://nfd.conf" as configuration filename.
Teng Liang04d5ce62018-08-06 10:20:24 +080080 * \throw std::logic_error Instance of rib::Service has been already constructed
81 * \throw std::logic_error Instance of rib::Service is not constructed on RIB thread
Alexander Afanasyev31367922015-02-09 20:51:10 -080082 */
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000083 Service(const ConfigSection& configSection, ndn::KeyChain& keyChain);
Alexander Afanasyev31367922015-02-09 20:51:10 -080084
85 /**
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080086 * \brief Destructor
87 */
Junxiao Shib2600172016-07-11 08:53:53 +000088 ~Service();
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080089
90 /**
Junxiao Shib2600172016-07-11 08:53:53 +000091 * \brief Perform initialization of NFD-RIB instance
92 *
93 * After initialization, NFD-RIB instance can be started by running the global io_service
Alexander Afanasyev31367922015-02-09 20:51:10 -080094 */
95 void
96 initialize();
97
Teng Liang04d5ce62018-08-06 10:20:24 +080098 /**
99 * \brief Get a reference to the only instance of this class
100 * \throw std::logic_error No instance has been constructed
101 * \throw std::logic_error This function is invoked on a thread other than the RIB thread
102 */
103 static Service&
104 get();
105
Alexander Afanasyev31367922015-02-09 20:51:10 -0800106private:
Alexander Afanasyev31367922015-02-09 20:51:10 -0800107 /**
108 * \brief Look into the config file and construct appropriate transport to communicate with NFD
Junxiao Shib2600172016-07-11 08:53:53 +0000109 * If NFD-RIB instance was initialized with config file, INFO format is assumed
Alexander Afanasyev31367922015-02-09 20:51:10 -0800110 */
111 shared_ptr<ndn::Transport>
112 getLocalNfdTransport();
113
114private:
Teng Liang04d5ce62018-08-06 10:20:24 +0800115 static Service* s_instance;
116
Alexander Afanasyev31367922015-02-09 20:51:10 -0800117 std::string m_configFile;
118 ConfigSection m_configSection;
119
120 ndn::KeyChain& m_keyChain;
Davide Pesavento9f8b10e2018-08-22 08:45:37 +0000121 Rib m_rib;
122
Alexander Afanasyev31367922015-02-09 20:51:10 -0800123 unique_ptr<ndn::Face> m_face;
Davide Pesavento9f8b10e2018-08-22 08:45:37 +0000124 unique_ptr<ndn::nfd::Controller> m_nfdController;
125 unique_ptr<FibUpdater> m_fibUpdater;
126 unique_ptr<AutoPrefixPropagator> m_prefixPropagator;
127 unique_ptr<Readvertise> m_readvertiseNlsr;
Yanbiao Licf0db022016-01-29 00:54:25 -0800128 unique_ptr<ndn::mgmt::Dispatcher> m_dispatcher;
Alexander Afanasyev31367922015-02-09 20:51:10 -0800129 unique_ptr<RibManager> m_ribManager;
130};
131
132} // namespace rib
133} // namespace nfd
134
Junxiao Shib2600172016-07-11 08:53:53 +0000135#endif // NFD_RIB_SERVICE_HPP