blob: 0b060131032192fed5e3e0263531765bbd43f931 [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
Junxiao Shif4cfed12018-08-22 23:26:29 +000029#include "rib-manager.hpp"
30
Alexander Afanasyev31367922015-02-09 20:51:10 -080031#include "core/config-file.hpp"
Alexander Afanasyev31367922015-02-09 20:51:10 -080032
33#include <ndn-cxx/face.hpp>
Davide Pesaventoa3148082018-04-12 18:21:54 -040034#include <ndn-cxx/mgmt/dispatcher.hpp>
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000035#include <ndn-cxx/mgmt/nfd/controller.hpp>
Alexander Afanasyev31367922015-02-09 20:51:10 -080036#include <ndn-cxx/security/key-chain.hpp>
37#include <ndn-cxx/transport/transport.hpp>
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040038#include <ndn-cxx/util/scheduler.hpp>
Alexander Afanasyev31367922015-02-09 20:51:10 -080039
40namespace nfd {
41namespace rib {
42
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000043class AutoPrefixPropagator;
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000044class Readvertise;
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080045
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 *
Junxiao Shif4cfed12018-08-22 23:26:29 +000049 * Only one instance of this class can be created at any time.
50 * After initialization, NFD-RIB instance can be started by running the global io_service.
Alexander Afanasyev31367922015-02-09 20:51:10 -080051 */
Junxiao Shib2600172016-07-11 08:53:53 +000052class Service : noncopyable
Alexander Afanasyev31367922015-02-09 20:51:10 -080053{
54public:
Alexander Afanasyev31367922015-02-09 20:51:10 -080055 /**
Junxiao Shib2600172016-07-11 08:53:53 +000056 * \brief create NFD-RIB service
57 * \param configFile absolute or relative path of configuration file
58 * \param keyChain the KeyChain
Teng Liang04d5ce62018-08-06 10:20:24 +080059 * \throw std::logic_error Instance of rib::Service has been already constructed
60 * \throw std::logic_error Instance of rib::Service is not constructed on RIB thread
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
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000066 * \param configSection parsed configuration section
Junxiao Shib2600172016-07-11 08:53:53 +000067 * \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.
Teng Liang04d5ce62018-08-06 10:20:24 +080071 * \throw std::logic_error Instance of rib::Service has been already constructed
72 * \throw std::logic_error Instance of rib::Service is not constructed on RIB thread
Alexander Afanasyev31367922015-02-09 20:51:10 -080073 */
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000074 Service(const ConfigSection& configSection, ndn::KeyChain& keyChain);
Alexander Afanasyev31367922015-02-09 20:51:10 -080075
76 /**
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080077 * \brief Destructor
78 */
Junxiao Shib2600172016-07-11 08:53:53 +000079 ~Service();
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080080
81 /**
Teng Liang04d5ce62018-08-06 10:20:24 +080082 * \brief Get a reference to the only instance of this class
83 * \throw std::logic_error No instance has been constructed
84 * \throw std::logic_error This function is invoked on a thread other than the RIB thread
85 */
86 static Service&
87 get();
88
Junxiao Shi5ba7dfc2018-09-26 14:24:05 +000089 RibManager&
90 getRibManager()
91 {
92 return m_ribManager;
93 }
94
Alexander Afanasyev31367922015-02-09 20:51:10 -080095private:
Ashlesh Gawandef84bac52018-08-27 07:39:31 +000096 template<typename ConfigParseFunc>
97 Service(ndn::KeyChain& keyChain, shared_ptr<ndn::Transport> localNfdTransport,
98 const ConfigParseFunc& configParse);
Junxiao Shif4cfed12018-08-22 23:26:29 +000099
100 void
101 processConfig(const ConfigSection& section, bool isDryRun, const std::string& filename);
102
103 void
104 checkConfig(const ConfigSection& section, const std::string& filename);
105
106 void
107 applyConfig(const ConfigSection& section, const std::string& filename);
108
Alexander Afanasyev31367922015-02-09 20:51:10 -0800109private:
Teng Liang04d5ce62018-08-06 10:20:24 +0800110 static Service* s_instance;
111
Alexander Afanasyev31367922015-02-09 20:51:10 -0800112 ndn::KeyChain& m_keyChain;
Junxiao Shif4cfed12018-08-22 23:26:29 +0000113 ndn::Face m_face;
Davide Pesaventoe1bdc082018-10-11 21:20:23 -0400114 ndn::util::Scheduler m_scheduler;
Junxiao Shif4cfed12018-08-22 23:26:29 +0000115 ndn::nfd::Controller m_nfdController;
Davide Pesavento9f8b10e2018-08-22 08:45:37 +0000116
Junxiao Shif4cfed12018-08-22 23:26:29 +0000117 Rib m_rib;
118 FibUpdater m_fibUpdater;
Davide Pesavento9f8b10e2018-08-22 08:45:37 +0000119 unique_ptr<AutoPrefixPropagator> m_prefixPropagator;
120 unique_ptr<Readvertise> m_readvertiseNlsr;
Junxiao Shif4cfed12018-08-22 23:26:29 +0000121 ndn::mgmt::Dispatcher m_dispatcher;
122 RibManager m_ribManager;
Alexander Afanasyev31367922015-02-09 20:51:10 -0800123};
124
125} // namespace rib
126} // namespace nfd
127
Junxiao Shib2600172016-07-11 08:53:53 +0000128#endif // NFD_RIB_SERVICE_HPP