blob: 7f63745d9aa6fbaa00c8c35238fff3f353a27d36 [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yanbiao Licf0db022016-01-29 00:54:25 -08003 * Copyright (c) 2014-2016, Regents of the University of California,
Junxiao Shi1e46be32015-01-08 20:18:05 -07004 * 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.
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070010 *
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/>.
Vince12e49462014-06-09 13:29:32 -050024 */
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070025
26#ifndef NFD_RIB_RIB_MANAGER_HPP
27#define NFD_RIB_RIB_MANAGER_HPP
28
29#include "rib.hpp"
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070030#include "core/config-file.hpp"
Yanbiao Licf0db022016-01-29 00:54:25 -080031#include "core/manager-base.hpp"
Vince Lehmancd16c832014-07-23 15:14:55 -070032#include "rib-status-publisher.hpp"
Yanbiao Lid7c96362015-01-30 23:58:24 -080033#include "auto-prefix-propagator.hpp"
Vince Lehman76c751c2014-11-18 17:36:38 -060034#include "fib-updater.hpp"
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070035
Junxiao Shi06d6ba62016-08-22 15:59:03 +000036#include <ndn-cxx/encoding/buffer-stream.hpp>
Alexander Afanasyev4a771362014-04-24 21:29:33 -070037#include <ndn-cxx/security/validator-config.hpp>
Alexander Afanasyev585e5a62014-08-12 11:49:31 -070038#include <ndn-cxx/management/nfd-face-monitor.hpp>
Alexander Afanasyev4a771362014-04-24 21:29:33 -070039#include <ndn-cxx/management/nfd-controller.hpp>
40#include <ndn-cxx/management/nfd-control-command.hpp>
41#include <ndn-cxx/management/nfd-control-response.hpp>
42#include <ndn-cxx/management/nfd-control-parameters.hpp>
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070043
44namespace nfd {
45namespace rib {
46
47using ndn::nfd::ControlCommand;
48using ndn::nfd::ControlResponse;
49using ndn::nfd::ControlParameters;
50
Alexander Afanasyev585e5a62014-08-12 11:49:31 -070051using ndn::nfd::FaceEventNotification;
52
Yanbiao Licf0db022016-01-29 00:54:25 -080053class RibManager : public nfd::ManagerBase
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070054{
55public:
Yingdi Yue5224e92014-04-29 18:04:02 -070056 class Error : public std::runtime_error
57 {
58 public:
59 explicit
60 Error(const std::string& what)
61 : std::runtime_error(what)
62 {
63 }
64 };
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070065
Yanbiao Licf0db022016-01-29 00:54:25 -080066public:
67 RibManager(Dispatcher& dispatcher, ndn::Face& face, ndn::KeyChain& keyChain);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070068
Vince Lehman26b215c2014-08-17 15:00:41 -050069 ~RibManager();
70
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070071 void
72 registerWithNfd();
73
74 void
75 enableLocalControlHeader();
76
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070077 void
78 setConfigFile(ConfigFile& configFile);
79
Vince Lehman76c751c2014-11-18 17:36:38 -060080 void
81 onRibUpdateSuccess(const RibUpdate& update);
Vince Lehman4387e782014-06-19 16:57:45 -050082
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070083 void
Vince Lehman76c751c2014-11-18 17:36:38 -060084 onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error);
85
Yanbiao Licf0db022016-01-29 00:54:25 -080086private: // initialization helpers
Vince Lehman76c751c2014-11-18 17:36:38 -060087 void
Yanbiao Licf0db022016-01-29 00:54:25 -080088 onConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070089
90 void
Yanbiao Licf0db022016-01-29 00:54:25 -080091 registerTopPrefix(const Name& topPrefix);
92
93private: // ControlCommand and StatusDataset
94 void
95 registerEntry(const Name& topPrefix, const Interest& interest,
96 ControlParameters parameters,
97 const ndn::mgmt::CommandContinuation& done);
Junxiao Shia3295742014-05-16 22:40:10 -070098
99 void
Yanbiao Licf0db022016-01-29 00:54:25 -0800100 unregisterEntry(const Name& topPrefix, const Interest& interest,
101 ControlParameters parameters,
102 const ndn::mgmt::CommandContinuation& done);
Yingdi Yue5224e92014-04-29 18:04:02 -0700103
104 void
Yanbiao Licf0db022016-01-29 00:54:25 -0800105 listEntries(const Name& topPrefix, const Interest& interest,
106 ndn::mgmt::StatusDatasetContext& context);
Yingdi Yue5224e92014-04-29 18:04:02 -0700107
108 void
Yanbiao Licf0db022016-01-29 00:54:25 -0800109 setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700110
Junxiao Shi21738402016-08-19 19:48:00 +0000111 virtual ndn::mgmt::Authorization
112 makeAuthorization(const std::string& verb) override;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700113
Yanbiao Licf0db022016-01-29 00:54:25 -0800114private: // Face monitor
Vince Lehman26b215c2014-08-17 15:00:41 -0500115 void
Vince Lehmancd613c52014-07-30 14:34:49 -0500116 fetchActiveFaces();
117
118 void
119 fetchSegments(const Data& data, shared_ptr<ndn::OBufferStream> buffer);
120
121 void
Vince Lehmancd613c52014-07-30 14:34:49 -0500122 onFetchFaceStatusTimeout();
123
Yanbiao Licf0db022016-01-29 00:54:25 -0800124 void
125 onFaceDestroyedEvent(uint64_t faceId);
126
Vince Lehman281ded72014-08-21 12:17:08 -0500127PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yanbiao Licf0db022016-01-29 00:54:25 -0800128 void
129 scheduleActiveFaceFetch(const time::seconds& timeToWait);
130
131 /**
132 * @brief remove invalid faces
133 *
134 * @param buffer Face dataset contents
Vince Lehman26b215c2014-08-17 15:00:41 -0500135 */
136 void
137 removeInvalidFaces(shared_ptr<ndn::OBufferStream> buffer);
138
Yanbiao Licf0db022016-01-29 00:54:25 -0800139 /**
140 * @brief response to face events
141 *
142 * @param notification
143 */
144 void
145 onNotification(const FaceEventNotification& notification);
146
147private:
148 void
Junxiao Shib2600172016-07-11 08:53:53 +0000149 onCommandPrefixAddNextHopSuccess(const Name& prefix,
150 const ndn::nfd::ControlParameters& result);
Yanbiao Licf0db022016-01-29 00:54:25 -0800151
152 void
Junxiao Shi29b41282016-08-22 03:47:02 +0000153 onCommandPrefixAddNextHopError(const Name& name, const ndn::nfd::ControlResponse& response);
Yanbiao Licf0db022016-01-29 00:54:25 -0800154
155 void
156 onControlHeaderSuccess();
157
158 void
Junxiao Shi29b41282016-08-22 03:47:02 +0000159 onControlHeaderError(const ndn::nfd::ControlResponse& response);
Vince Lehman281ded72014-08-21 12:17:08 -0500160
161private:
Vince Lehman72446ec2014-07-09 10:50:02 -0500162 ndn::Face& m_face;
Vince Lehmanc1dfdb42015-07-16 12:17:36 -0500163 ndn::KeyChain& m_keyChain;
Alexander Afanasyevb3893c92014-05-15 01:49:54 -0700164 ndn::nfd::Controller m_nfdController;
Yanbiao Licf0db022016-01-29 00:54:25 -0800165 ndn::nfd::FaceMonitor m_faceMonitor;
Yingdi Yue5224e92014-04-29 18:04:02 -0700166 ndn::ValidatorConfig m_localhostValidator;
167 ndn::ValidatorConfig m_localhopValidator;
Yingdi Yue5224e92014-04-29 18:04:02 -0700168 bool m_isLocalhopEnabled;
Yanbiao Lid7c96362015-01-30 23:58:24 -0800169 AutoPrefixPropagator m_prefixPropagator;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700170
Vince Lehman76c751c2014-11-18 17:36:38 -0600171PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yanbiao Licf0db022016-01-29 00:54:25 -0800172 Rib m_rib;
Vince Lehman76c751c2014-11-18 17:36:38 -0600173 FibUpdater m_fibUpdater;
Vince Lehman4387e782014-06-19 16:57:45 -0500174
Vince Lehman76c751c2014-11-18 17:36:38 -0600175private:
Yanbiao Licf0db022016-01-29 00:54:25 -0800176 static const Name LOCAL_HOST_TOP_PREFIX;
177 static const Name LOCAL_HOP_TOP_PREFIX;
Junxiao Shifde3f542016-07-10 19:54:53 +0000178 static const std::string MGMT_MODULE_NAME;
Vince Lehmancd613c52014-07-30 14:34:49 -0500179 static const Name FACES_LIST_DATASET_PREFIX;
Vince Lehman26b215c2014-08-17 15:00:41 -0500180 static const time::seconds ACTIVE_FACE_FETCH_INTERVAL;
Junxiao Shi1e46be32015-01-08 20:18:05 -0700181 scheduler::EventId m_activeFaceFetchEvent;
Vince Lehman26b215c2014-08-17 15:00:41 -0500182
183 typedef std::set<uint64_t> FaceIdSet;
184 /** \brief contains FaceIds with one or more Routes in the RIB
185 */
186 FaceIdSet m_registeredFaces;
Yanbiao Licf0db022016-01-29 00:54:25 -0800187
188 std::function<void(const Name& topPrefix)> m_addTopPrefix;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700189};
190
191} // namespace rib
192} // namespace nfd
193
194#endif // NFD_RIB_RIB_MANAGER_HPP