blob: 9479291987a9ac4ae0b71882c3a19b896bc4aafa [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
60 boost::asio::io_service&
61 getIoService();
62
63 void
64 setConfigFile(ConfigFile& configFile);
65
66private:
67 void
68 onConfig(const ConfigSection& configSection,
69 bool isDryRun,
70 const std::string& filename);
71
72 void
73 sendResponse(const Name& name,
74 const ControlResponse& response);
75
76 void
77 sendResponse(const Name& name,
78 uint32_t code,
79 const std::string& text);
80
81 void
82 onRibRequestValidated(const shared_ptr<const Interest>& request);
83
84 void
85 onRibRequestValidationFailed(const shared_ptr<const Interest>& request,
86 const std::string& failureInfo);
87
88 void
89 onCommandError(uint32_t code, const std::string& error,
90 const ndn::Interest& interest,
91 const PrefixRegOptions& options);
92
93 void
94 onRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
95
96 void
97 onUnRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
98
99 void
100 onControlHeaderSuccess();
101
102 void
103 onControlHeaderError(uint32_t code, const std::string& reason);
104
105 void
106 setInterestFilterFailed(const Name& name, const std::string& msg);
107
108 void
109 insertEntry(const Interest& request, const PrefixRegOptions& options);
110
111 void
112 deleteEntry(const Interest& request, const PrefixRegOptions& options);
113
114 bool
115 extractOptions(const Interest& request,
116 PrefixRegOptions& extractedOptions);
117
118 void
119 onNotification(const FaceEventNotification& notification);
120
121private:
122 Rib m_managedRib;
123 ndn::shared_ptr<ndn::Face> m_face;
124 ndn::shared_ptr<ndn::nfd::Controller> m_nfdController;
125 ndn::KeyChain m_keyChain;
126 ndn::ValidatorConfig m_validator;
127 FaceMonitor m_faceMonitor;
128
129 typedef boost::function<void(RibManager*,
130 const Interest&,
131 const PrefixRegOptions&)> VerbProcessor;
132
133 typedef std::map<name::Component, VerbProcessor> VerbDispatchTable;
134
135 typedef std::pair<name::Component, VerbProcessor> VerbAndProcessor;
136
137
138 const VerbDispatchTable m_verbDispatch;
139
140 static const Name COMMAND_PREFIX; // /localhost/nrd
141 static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
142
143 // number of components in an invalid, but not malformed, unsigned command.
144 // (/localhost/nrd + verb + options) = 4
145 static const size_t COMMAND_UNSIGNED_NCOMPS;
146
147 // number of components in a valid signed Interest.
148 // 8 with signed Interest support.
149 static const size_t COMMAND_SIGNED_NCOMPS;
150
151 static const VerbAndProcessor COMMAND_VERBS[];
152};
153
154} // namespace rib
155} // namespace nfd
156
157#endif // NFD_RIB_RIB_MANAGER_HPP