blob: c28ea71c8af9f6d4d547cb41748b0ccf35f7f9ce [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"
Yanbiao Lid7c96362015-01-30 23:58:24 -080032#include "auto-prefix-propagator.hpp"
Vince Lehman76c751c2014-11-18 17:36:38 -060033#include "fib-updater.hpp"
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070034
Junxiao Shi06d6ba62016-08-22 15:59:03 +000035#include <ndn-cxx/encoding/buffer-stream.hpp>
Alexander Afanasyev4a771362014-04-24 21:29:33 -070036#include <ndn-cxx/security/validator-config.hpp>
Alexander Afanasyev585e5a62014-08-12 11:49:31 -070037#include <ndn-cxx/management/nfd-face-monitor.hpp>
Alexander Afanasyev4a771362014-04-24 21:29:33 -070038#include <ndn-cxx/management/nfd-controller.hpp>
39#include <ndn-cxx/management/nfd-control-command.hpp>
40#include <ndn-cxx/management/nfd-control-response.hpp>
41#include <ndn-cxx/management/nfd-control-parameters.hpp>
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070042
43namespace nfd {
44namespace rib {
45
46using ndn::nfd::ControlCommand;
47using ndn::nfd::ControlResponse;
48using ndn::nfd::ControlParameters;
49
Alexander Afanasyev585e5a62014-08-12 11:49:31 -070050using ndn::nfd::FaceEventNotification;
51
Yanbiao Licf0db022016-01-29 00:54:25 -080052class RibManager : public nfd::ManagerBase
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070053{
54public:
Yingdi Yue5224e92014-04-29 18:04:02 -070055 class Error : public std::runtime_error
56 {
57 public:
58 explicit
59 Error(const std::string& what)
60 : std::runtime_error(what)
61 {
62 }
63 };
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070064
Yanbiao Licf0db022016-01-29 00:54:25 -080065public:
66 RibManager(Dispatcher& dispatcher, ndn::Face& face, ndn::KeyChain& keyChain);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070067
Vince Lehman26b215c2014-08-17 15:00:41 -050068 ~RibManager();
69
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070070 void
71 registerWithNfd();
72
73 void
74 enableLocalControlHeader();
75
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070076 void
77 setConfigFile(ConfigFile& configFile);
78
Vince Lehman76c751c2014-11-18 17:36:38 -060079 void
80 onRibUpdateSuccess(const RibUpdate& update);
Vince Lehman4387e782014-06-19 16:57:45 -050081
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070082 void
Vince Lehman76c751c2014-11-18 17:36:38 -060083 onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error);
84
Yanbiao Licf0db022016-01-29 00:54:25 -080085private: // initialization helpers
Vince Lehman76c751c2014-11-18 17:36:38 -060086 void
Yanbiao Licf0db022016-01-29 00:54:25 -080087 onConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070088
89 void
Yanbiao Licf0db022016-01-29 00:54:25 -080090 registerTopPrefix(const Name& topPrefix);
91
92private: // ControlCommand and StatusDataset
93 void
94 registerEntry(const Name& topPrefix, const Interest& interest,
95 ControlParameters parameters,
96 const ndn::mgmt::CommandContinuation& done);
Junxiao Shia3295742014-05-16 22:40:10 -070097
98 void
Yanbiao Licf0db022016-01-29 00:54:25 -080099 unregisterEntry(const Name& topPrefix, const Interest& interest,
100 ControlParameters parameters,
101 const ndn::mgmt::CommandContinuation& done);
Yingdi Yue5224e92014-04-29 18:04:02 -0700102
103 void
Yanbiao Licf0db022016-01-29 00:54:25 -0800104 listEntries(const Name& topPrefix, const Interest& interest,
105 ndn::mgmt::StatusDatasetContext& context);
Yingdi Yue5224e92014-04-29 18:04:02 -0700106
107 void
Yanbiao Licf0db022016-01-29 00:54:25 -0800108 setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700109
Junxiao Shi21738402016-08-19 19:48:00 +0000110 virtual ndn::mgmt::Authorization
111 makeAuthorization(const std::string& verb) override;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700112
Yanbiao Licf0db022016-01-29 00:54:25 -0800113private: // Face monitor
Vince Lehman26b215c2014-08-17 15:00:41 -0500114 void
Vince Lehmancd613c52014-07-30 14:34:49 -0500115 fetchActiveFaces();
116
117 void
118 fetchSegments(const Data& data, shared_ptr<ndn::OBufferStream> buffer);
119
120 void
Vince Lehmancd613c52014-07-30 14:34:49 -0500121 onFetchFaceStatusTimeout();
122
Yanbiao Licf0db022016-01-29 00:54:25 -0800123 void
124 onFaceDestroyedEvent(uint64_t faceId);
125
Vince Lehman281ded72014-08-21 12:17:08 -0500126PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yanbiao Licf0db022016-01-29 00:54:25 -0800127 void
128 scheduleActiveFaceFetch(const time::seconds& timeToWait);
129
130 /**
131 * @brief remove invalid faces
132 *
133 * @param buffer Face dataset contents
Vince Lehman26b215c2014-08-17 15:00:41 -0500134 */
135 void
136 removeInvalidFaces(shared_ptr<ndn::OBufferStream> buffer);
137
Yanbiao Licf0db022016-01-29 00:54:25 -0800138 /**
139 * @brief response to face events
140 *
141 * @param notification
142 */
143 void
144 onNotification(const FaceEventNotification& notification);
145
146private:
147 void
Junxiao Shib2600172016-07-11 08:53:53 +0000148 onCommandPrefixAddNextHopSuccess(const Name& prefix,
149 const ndn::nfd::ControlParameters& result);
Yanbiao Licf0db022016-01-29 00:54:25 -0800150
151 void
Junxiao Shi29b41282016-08-22 03:47:02 +0000152 onCommandPrefixAddNextHopError(const Name& name, const ndn::nfd::ControlResponse& response);
Yanbiao Licf0db022016-01-29 00:54:25 -0800153
154 void
155 onControlHeaderSuccess();
156
157 void
Junxiao Shi29b41282016-08-22 03:47:02 +0000158 onControlHeaderError(const ndn::nfd::ControlResponse& response);
Vince Lehman281ded72014-08-21 12:17:08 -0500159
160private:
Vince Lehman72446ec2014-07-09 10:50:02 -0500161 ndn::Face& m_face;
Vince Lehmanc1dfdb42015-07-16 12:17:36 -0500162 ndn::KeyChain& m_keyChain;
Alexander Afanasyevb3893c92014-05-15 01:49:54 -0700163 ndn::nfd::Controller m_nfdController;
Yanbiao Licf0db022016-01-29 00:54:25 -0800164 ndn::nfd::FaceMonitor m_faceMonitor;
Yingdi Yue5224e92014-04-29 18:04:02 -0700165 ndn::ValidatorConfig m_localhostValidator;
166 ndn::ValidatorConfig m_localhopValidator;
Yingdi Yue5224e92014-04-29 18:04:02 -0700167 bool m_isLocalhopEnabled;
Yanbiao Lid7c96362015-01-30 23:58:24 -0800168 AutoPrefixPropagator m_prefixPropagator;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700169
Vince Lehman76c751c2014-11-18 17:36:38 -0600170PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yanbiao Licf0db022016-01-29 00:54:25 -0800171 Rib m_rib;
Vince Lehman76c751c2014-11-18 17:36:38 -0600172 FibUpdater m_fibUpdater;
Vince Lehman4387e782014-06-19 16:57:45 -0500173
Vince Lehman76c751c2014-11-18 17:36:38 -0600174private:
Yanbiao Licf0db022016-01-29 00:54:25 -0800175 static const Name LOCAL_HOST_TOP_PREFIX;
176 static const Name LOCAL_HOP_TOP_PREFIX;
Junxiao Shifde3f542016-07-10 19:54:53 +0000177 static const std::string MGMT_MODULE_NAME;
Vince Lehmancd613c52014-07-30 14:34:49 -0500178 static const Name FACES_LIST_DATASET_PREFIX;
Vince Lehman26b215c2014-08-17 15:00:41 -0500179 static const time::seconds ACTIVE_FACE_FETCH_INTERVAL;
Junxiao Shi1e46be32015-01-08 20:18:05 -0700180 scheduler::EventId m_activeFaceFetchEvent;
Vince Lehman26b215c2014-08-17 15:00:41 -0500181
182 typedef std::set<uint64_t> FaceIdSet;
183 /** \brief contains FaceIds with one or more Routes in the RIB
184 */
185 FaceIdSet m_registeredFaces;
Yanbiao Licf0db022016-01-29 00:54:25 -0800186
187 std::function<void(const Name& topPrefix)> m_addTopPrefix;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700188};
189
190} // namespace rib
191} // namespace nfd
192
193#endif // NFD_RIB_RIB_MANAGER_HPP