blob: eff4e47063b07131f22be74df99855334588f88d [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/*
Davide Pesavento1b077f62019-02-19 19:19:44 -05003 * Copyright (c) 2014-2019, 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
Davide Pesavento1b077f62019-02-19 19:19:44 -050026#ifndef NFD_DAEMON_RIB_SERVICE_HPP
27#define NFD_DAEMON_RIB_SERVICE_HPP
Alexander Afanasyev31367922015-02-09 20:51:10 -080028
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040029#include "common/config-file.hpp"
Davide Pesavento8a05c7f2019-02-28 02:26:19 -050030#include "mgmt/rib-manager.hpp"
31#include "rib/fib-updater.hpp"
32#include "rib/rib.hpp"
Alexander Afanasyev31367922015-02-09 20:51:10 -080033
34#include <ndn-cxx/face.hpp>
Davide Pesaventoa3148082018-04-12 18:21:54 -040035#include <ndn-cxx/mgmt/dispatcher.hpp>
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000036#include <ndn-cxx/mgmt/nfd/controller.hpp>
Alexander Afanasyev31367922015-02-09 20:51:10 -080037#include <ndn-cxx/security/key-chain.hpp>
38#include <ndn-cxx/transport/transport.hpp>
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040039#include <ndn-cxx/util/scheduler.hpp>
Alexander Afanasyev31367922015-02-09 20:51:10 -080040
41namespace nfd {
42namespace rib {
43
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 Afanasyev41b563b2019-02-17 14:16:32 -050055 Service(const ConfigSection& configSection, ndn::Face& face, ndn::KeyChain& keyChain);
Alexander Afanasyev31367922015-02-09 20:51:10 -080056
57 /**
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080058 * \brief Destructor
59 */
Junxiao Shib2600172016-07-11 08:53:53 +000060 ~Service();
Alexander Afanasyevc3ea5a72015-02-12 20:14:16 -080061
62 /**
Teng Liang04d5ce62018-08-06 10:20:24 +080063 * \brief Get a reference to the only instance of this class
64 * \throw std::logic_error No instance has been constructed
65 * \throw std::logic_error This function is invoked on a thread other than the RIB thread
66 */
67 static Service&
68 get();
69
Junxiao Shi5ba7dfc2018-09-26 14:24:05 +000070 RibManager&
71 getRibManager()
72 {
73 return m_ribManager;
74 }
75
Alexander Afanasyev31367922015-02-09 20:51:10 -080076private:
Ashlesh Gawandef84bac52018-08-27 07:39:31 +000077 template<typename ConfigParseFunc>
Alexander Afanasyev41b563b2019-02-17 14:16:32 -050078 Service(ndn::KeyChain& keyChain, ndn::Face& face,
Ashlesh Gawandef84bac52018-08-27 07:39:31 +000079 const ConfigParseFunc& configParse);
Junxiao Shif4cfed12018-08-22 23:26:29 +000080
81 void
82 processConfig(const ConfigSection& section, bool isDryRun, const std::string& filename);
83
84 void
85 checkConfig(const ConfigSection& section, const std::string& filename);
86
87 void
88 applyConfig(const ConfigSection& section, const std::string& filename);
89
Alexander Afanasyev31367922015-02-09 20:51:10 -080090private:
Alexander Afanasyev31367922015-02-09 20:51:10 -080091 ndn::KeyChain& m_keyChain;
Alexander Afanasyev41b563b2019-02-17 14:16:32 -050092 ndn::Face& m_face;
Alexander Afanasyevd1d38c82020-02-21 16:37:25 -050093 ndn::Scheduler m_scheduler;
Junxiao Shif4cfed12018-08-22 23:26:29 +000094 ndn::nfd::Controller m_nfdController;
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000095
Junxiao Shif4cfed12018-08-22 23:26:29 +000096 Rib m_rib;
97 FibUpdater m_fibUpdater;
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000098 unique_ptr<Readvertise> m_readvertiseNlsr;
Yanbiao Lif48d0802018-06-01 03:00:02 -070099 unique_ptr<Readvertise> m_readvertisePropagation;
Junxiao Shif4cfed12018-08-22 23:26:29 +0000100 ndn::mgmt::Dispatcher m_dispatcher;
101 RibManager m_ribManager;
Alexander Afanasyev31367922015-02-09 20:51:10 -0800102};
103
104} // namespace rib
105} // namespace nfd
106
Davide Pesavento1b077f62019-02-19 19:19:44 -0500107#endif // NFD_DAEMON_RIB_SERVICE_HPP