blob: 99f5ccdfd6c6dff6ad30aa5471379a3686811aa4 [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>
Junxiao Shi25c6ce42016-09-09 13:49:59 +000037#include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
38#include <ndn-cxx/mgmt/nfd/controller.hpp>
39#include <ndn-cxx/mgmt/nfd/control-command.hpp>
40#include <ndn-cxx/mgmt/nfd/control-response.hpp>
41#include <ndn-cxx/mgmt/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
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700118 onFetchActiveFacesFailure(uint32_t code, const std::string& reason);
Vince Lehmancd613c52014-07-30 14:34:49 -0500119
Yanbiao Licf0db022016-01-29 00:54:25 -0800120 void
121 onFaceDestroyedEvent(uint64_t faceId);
122
Vince Lehman281ded72014-08-21 12:17:08 -0500123PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yanbiao Licf0db022016-01-29 00:54:25 -0800124 void
125 scheduleActiveFaceFetch(const time::seconds& timeToWait);
126
127 /**
128 * @brief remove invalid faces
129 *
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700130 * @param status Face dataset
Vince Lehman26b215c2014-08-17 15:00:41 -0500131 */
132 void
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700133 removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces);
Vince Lehman26b215c2014-08-17 15:00:41 -0500134
Yanbiao Licf0db022016-01-29 00:54:25 -0800135 /**
136 * @brief response to face events
137 *
138 * @param notification
139 */
140 void
141 onNotification(const FaceEventNotification& notification);
142
143private:
144 void
Junxiao Shib2600172016-07-11 08:53:53 +0000145 onCommandPrefixAddNextHopSuccess(const Name& prefix,
146 const ndn::nfd::ControlParameters& result);
Yanbiao Licf0db022016-01-29 00:54:25 -0800147
148 void
Junxiao Shi29b41282016-08-22 03:47:02 +0000149 onCommandPrefixAddNextHopError(const Name& name, const ndn::nfd::ControlResponse& response);
Yanbiao Licf0db022016-01-29 00:54:25 -0800150
151 void
152 onControlHeaderSuccess();
153
154 void
Junxiao Shi29b41282016-08-22 03:47:02 +0000155 onControlHeaderError(const ndn::nfd::ControlResponse& response);
Vince Lehman281ded72014-08-21 12:17:08 -0500156
157private:
Vince Lehman72446ec2014-07-09 10:50:02 -0500158 ndn::Face& m_face;
Vince Lehmanc1dfdb42015-07-16 12:17:36 -0500159 ndn::KeyChain& m_keyChain;
Alexander Afanasyevb3893c92014-05-15 01:49:54 -0700160 ndn::nfd::Controller m_nfdController;
Yanbiao Licf0db022016-01-29 00:54:25 -0800161 ndn::nfd::FaceMonitor m_faceMonitor;
Yingdi Yue5224e92014-04-29 18:04:02 -0700162 ndn::ValidatorConfig m_localhostValidator;
163 ndn::ValidatorConfig m_localhopValidator;
Yingdi Yue5224e92014-04-29 18:04:02 -0700164 bool m_isLocalhopEnabled;
Yanbiao Lid7c96362015-01-30 23:58:24 -0800165 AutoPrefixPropagator m_prefixPropagator;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700166
Vince Lehman76c751c2014-11-18 17:36:38 -0600167PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yanbiao Licf0db022016-01-29 00:54:25 -0800168 Rib m_rib;
Vince Lehman76c751c2014-11-18 17:36:38 -0600169 FibUpdater m_fibUpdater;
Vince Lehman4387e782014-06-19 16:57:45 -0500170
Vince Lehman76c751c2014-11-18 17:36:38 -0600171private:
Yanbiao Licf0db022016-01-29 00:54:25 -0800172 static const Name LOCAL_HOST_TOP_PREFIX;
173 static const Name LOCAL_HOP_TOP_PREFIX;
Junxiao Shifde3f542016-07-10 19:54:53 +0000174 static const std::string MGMT_MODULE_NAME;
Vince Lehmancd613c52014-07-30 14:34:49 -0500175 static const Name FACES_LIST_DATASET_PREFIX;
Vince Lehman26b215c2014-08-17 15:00:41 -0500176 static const time::seconds ACTIVE_FACE_FETCH_INTERVAL;
Junxiao Shi1e46be32015-01-08 20:18:05 -0700177 scheduler::EventId m_activeFaceFetchEvent;
Vince Lehman26b215c2014-08-17 15:00:41 -0500178
179 typedef std::set<uint64_t> FaceIdSet;
180 /** \brief contains FaceIds with one or more Routes in the RIB
181 */
182 FaceIdSet m_registeredFaces;
Yanbiao Licf0db022016-01-29 00:54:25 -0800183
184 std::function<void(const Name& topPrefix)> m_addTopPrefix;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700185};
186
187} // namespace rib
188} // namespace nfd
189
190#endif // NFD_RIB_RIB_MANAGER_HPP