blob: 1407fb20c12151f0748da89ee3e7015966bdc299 [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 Regents of the University of California,
4 * 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
26#ifndef NFD_RIB_RIB_MANAGER_HPP
27#define NFD_RIB_RIB_MANAGER_HPP
28
29#include "rib.hpp"
30#include "face-monitor.hpp"
31#include "core/config-file.hpp"
32
Alexander Afanasyev4a771362014-04-24 21:29:33 -070033#include <ndn-cxx/security/validator-config.hpp>
34#include <ndn-cxx/management/nfd-controller.hpp>
35#include <ndn-cxx/management/nfd-control-command.hpp>
36#include <ndn-cxx/management/nfd-control-response.hpp>
37#include <ndn-cxx/management/nfd-control-parameters.hpp>
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070038
39namespace nfd {
40namespace rib {
41
42using ndn::nfd::ControlCommand;
43using ndn::nfd::ControlResponse;
44using ndn::nfd::ControlParameters;
45
46class RibManager : noncopyable
47{
48public:
Yingdi Yue5224e92014-04-29 18:04:02 -070049 class Error : public std::runtime_error
50 {
51 public:
52 explicit
53 Error(const std::string& what)
54 : std::runtime_error(what)
55 {
56 }
57 };
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070058
Yingdi Yue5224e92014-04-29 18:04:02 -070059 RibManager();
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070060
61 void
62 registerWithNfd();
63
64 void
65 enableLocalControlHeader();
66
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070067 void
68 setConfigFile(ConfigFile& configFile);
69
70private:
71 void
72 onConfig(const ConfigSection& configSection,
73 bool isDryRun,
74 const std::string& filename);
75
76 void
Yingdi Yue5224e92014-04-29 18:04:02 -070077 onLocalhopRequest(const Interest& request);
78
79 void
80 onLocalhostRequest(const Interest& request);
81
82 void
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070083 sendResponse(const Name& name,
84 const ControlResponse& response);
85
86 void
87 sendResponse(const Name& name,
88 uint32_t code,
89 const std::string& text);
90
91 void
Alexander Afanasyev20d31442014-04-19 17:00:53 -070092 registerEntry(const shared_ptr<const Interest>& request,
93 ControlParameters& parameters);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070094
95 void
Alexander Afanasyev20d31442014-04-19 17:00:53 -070096 unregisterEntry(const shared_ptr<const Interest>& request,
97 ControlParameters& parameters);
98
99 void
100 onCommandValidated(const shared_ptr<const Interest>& request);
101
102 void
103 onCommandValidationFailed(const shared_ptr<const Interest>& request,
104 const std::string& failureInfo);
105
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700106
107 void
108 onCommandError(uint32_t code, const std::string& error,
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700109 const shared_ptr<const Interest>& request,
110 const RibEntry& ribEntry);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700111
112 void
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700113 onRegSuccess(const shared_ptr<const Interest>& request,
114 const ControlParameters& parameters,
115 const RibEntry& ribEntry);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700116
117 void
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700118 onUnRegSuccess(const shared_ptr<const Interest>& request,
119 const ControlParameters& parameters,
120 const RibEntry& ribEntry);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700121
122 void
Alexander Afanasyevb3893c92014-05-15 01:49:54 -0700123 onNrdCommandPrefixAddNextHopSuccess(const Name& prefix);
124
125 void
126 onNrdCommandPrefixAddNextHopError(const Name& name, const std::string& msg);
127
128 void
129 onAddNextHopSuccess(const Name& prefix);
130
131 void
132 onAddNextHopError(const Name& name, const std::string& msg);
133
134 void
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700135 onControlHeaderSuccess();
136
137 void
138 onControlHeaderError(uint32_t code, const std::string& reason);
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700139 static bool
140 extractParameters(const Name::Component& parameterComponent,
141 ControlParameters& extractedParameters);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700142
143 bool
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700144 validateParameters(const ControlCommand& command,
145 ControlParameters& parameters);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700146
147 void
148 onNotification(const FaceEventNotification& notification);
149
150private:
151 Rib m_managedRib;
Yingdi Yuf4db0b52014-04-17 13:17:39 -0700152 ndn::Face m_face;
Alexander Afanasyevb3893c92014-05-15 01:49:54 -0700153 ndn::nfd::Controller m_nfdController;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700154 ndn::KeyChain m_keyChain;
Yingdi Yue5224e92014-04-29 18:04:02 -0700155 ndn::ValidatorConfig m_localhostValidator;
156 ndn::ValidatorConfig m_localhopValidator;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700157 FaceMonitor m_faceMonitor;
Yingdi Yue5224e92014-04-29 18:04:02 -0700158 bool m_isLocalhopEnabled;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700159
Alexander Afanasyevf6980282014-05-13 18:28:40 -0700160 typedef function<void(RibManager*,
161 const shared_ptr<const Interest>& request,
162 ControlParameters& parameters)> VerbProcessor;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700163
164 typedef std::map<name::Component, VerbProcessor> VerbDispatchTable;
165
166 typedef std::pair<name::Component, VerbProcessor> VerbAndProcessor;
167
168
169 const VerbDispatchTable m_verbDispatch;
170
171 static const Name COMMAND_PREFIX; // /localhost/nrd
172 static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
173
174 // number of components in an invalid, but not malformed, unsigned command.
175 // (/localhost/nrd + verb + options) = 4
176 static const size_t COMMAND_UNSIGNED_NCOMPS;
177
178 // number of components in a valid signed Interest.
179 // 8 with signed Interest support.
180 static const size_t COMMAND_SIGNED_NCOMPS;
181
182 static const VerbAndProcessor COMMAND_VERBS[];
183};
184
185} // namespace rib
186} // namespace nfd
187
188#endif // NFD_RIB_RIB_MANAGER_HPP