blob: 44299e6e041f7173dbb4c286cac7da5f1cc17fdd [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
79 onRibRequestValidated(const shared_ptr<const Interest>& request);
80
81 void
82 onRibRequestValidationFailed(const shared_ptr<const Interest>& request,
83 const std::string& failureInfo);
84
85 void
86 onCommandError(uint32_t code, const std::string& error,
87 const ndn::Interest& interest,
88 const PrefixRegOptions& options);
89
90 void
91 onRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
92
93 void
94 onUnRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
95
96 void
97 onControlHeaderSuccess();
98
99 void
100 onControlHeaderError(uint32_t code, const std::string& reason);
101
102 void
103 setInterestFilterFailed(const Name& name, const std::string& msg);
104
105 void
106 insertEntry(const Interest& request, const PrefixRegOptions& options);
107
108 void
109 deleteEntry(const Interest& request, const PrefixRegOptions& options);
110
111 bool
112 extractOptions(const Interest& request,
113 PrefixRegOptions& extractedOptions);
114
115 void
116 onNotification(const FaceEventNotification& notification);
117
118private:
119 Rib m_managedRib;
Yingdi Yuf4db0b52014-04-17 13:17:39 -0700120 ndn::Face m_face;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700121 ndn::shared_ptr<ndn::nfd::Controller> m_nfdController;
122 ndn::KeyChain m_keyChain;
123 ndn::ValidatorConfig m_validator;
124 FaceMonitor m_faceMonitor;
125
126 typedef boost::function<void(RibManager*,
127 const Interest&,
128 const PrefixRegOptions&)> VerbProcessor;
129
130 typedef std::map<name::Component, VerbProcessor> VerbDispatchTable;
131
132 typedef std::pair<name::Component, VerbProcessor> VerbAndProcessor;
133
134
135 const VerbDispatchTable m_verbDispatch;
136
137 static const Name COMMAND_PREFIX; // /localhost/nrd
138 static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
139
140 // number of components in an invalid, but not malformed, unsigned command.
141 // (/localhost/nrd + verb + options) = 4
142 static const size_t COMMAND_UNSIGNED_NCOMPS;
143
144 // number of components in a valid signed Interest.
145 // 8 with signed Interest support.
146 static const size_t COMMAND_SIGNED_NCOMPS;
147
148 static const VerbAndProcessor COMMAND_VERBS[];
149};
150
151} // namespace rib
152} // namespace nfd
153
154#endif // NFD_RIB_RIB_MANAGER_HPP