blob: a8984b1679f90a6d0127c104824514bbcc184a52 [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
33#include <ndn-cpp-dev/security/validator-config.hpp>
34#include <ndn-cpp-dev/management/nfd-controller.hpp>
35#include <ndn-cpp-dev/management/nfd-control-command.hpp>
36#include <ndn-cpp-dev/management/nfd-control-response.hpp>
37#include <ndn-cpp-dev/management/nfd-control-parameters.hpp>
38
39namespace nfd {
40namespace rib {
41
42using ndn::nfd::ControlCommand;
43using ndn::nfd::ControlResponse;
44using ndn::nfd::ControlParameters;
45
46class RibManager : noncopyable
47{
48public:
49 RibManager();
50
51 void
52 onRibRequest(const Interest& request);
53
54 void
55 registerWithNfd();
56
57 void
58 enableLocalControlHeader();
59
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070060 void
61 setConfigFile(ConfigFile& configFile);
62
63private:
64 void
65 onConfig(const ConfigSection& configSection,
66 bool isDryRun,
67 const std::string& filename);
68
69 void
70 sendResponse(const Name& name,
71 const ControlResponse& response);
72
73 void
74 sendResponse(const Name& name,
75 uint32_t code,
76 const std::string& text);
77
78 void
Alexander Afanasyev20d31442014-04-19 17:00:53 -070079 registerEntry(const shared_ptr<const Interest>& request,
80 ControlParameters& parameters);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070081
82 void
Alexander Afanasyev20d31442014-04-19 17:00:53 -070083 unregisterEntry(const shared_ptr<const Interest>& request,
84 ControlParameters& parameters);
85
86 void
87 onCommandValidated(const shared_ptr<const Interest>& request);
88
89 void
90 onCommandValidationFailed(const shared_ptr<const Interest>& request,
91 const std::string& failureInfo);
92
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070093
94 void
95 onCommandError(uint32_t code, const std::string& error,
Alexander Afanasyev20d31442014-04-19 17:00:53 -070096 const shared_ptr<const Interest>& request,
97 const RibEntry& ribEntry);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070098
99 void
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700100 onRegSuccess(const shared_ptr<const Interest>& request,
101 const ControlParameters& parameters,
102 const RibEntry& ribEntry);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700103
104 void
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700105 onUnRegSuccess(const shared_ptr<const Interest>& request,
106 const ControlParameters& parameters,
107 const RibEntry& ribEntry);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700108
109 void
110 onControlHeaderSuccess();
111
112 void
113 onControlHeaderError(uint32_t code, const std::string& reason);
114
115 void
116 setInterestFilterFailed(const Name& name, const std::string& msg);
117
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700118 static bool
119 extractParameters(const Name::Component& parameterComponent,
120 ControlParameters& extractedParameters);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700121
122 bool
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700123 validateParameters(const ControlCommand& command,
124 ControlParameters& parameters);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700125
126 void
127 onNotification(const FaceEventNotification& notification);
128
129private:
130 Rib m_managedRib;
Yingdi Yuf4db0b52014-04-17 13:17:39 -0700131 ndn::Face m_face;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700132 ndn::shared_ptr<ndn::nfd::Controller> m_nfdController;
133 ndn::KeyChain m_keyChain;
134 ndn::ValidatorConfig m_validator;
135 FaceMonitor m_faceMonitor;
136
137 typedef boost::function<void(RibManager*,
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700138 const shared_ptr<const Interest>& request,
139 ControlParameters& parameters)> VerbProcessor;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700140
141 typedef std::map<name::Component, VerbProcessor> VerbDispatchTable;
142
143 typedef std::pair<name::Component, VerbProcessor> VerbAndProcessor;
144
145
146 const VerbDispatchTable m_verbDispatch;
147
148 static const Name COMMAND_PREFIX; // /localhost/nrd
149 static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
150
151 // number of components in an invalid, but not malformed, unsigned command.
152 // (/localhost/nrd + verb + options) = 4
153 static const size_t COMMAND_UNSIGNED_NCOMPS;
154
155 // number of components in a valid signed Interest.
156 // 8 with signed Interest support.
157 static const size_t COMMAND_SIGNED_NCOMPS;
158
159 static const VerbAndProcessor COMMAND_VERBS[];
160};
161
162} // namespace rib
163} // namespace nfd
164
165#endif // NFD_RIB_RIB_MANAGER_HPP