blob: b441de89050d1f560356fb2961a8fe5e60619e28 [file] [log] [blame]
Obaid3f48fe52014-02-27 21:45:23 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NRD_HPP
8#define NRD_HPP
9
10#include "rib.hpp"
Obaid68711872014-04-08 03:16:40 -050011#include "face-monitor.hpp"
Obaid3f48fe52014-02-27 21:45:23 -060012
13namespace ndn {
14namespace nrd {
15
16class Nrd
17{
18public:
Yingdi Yudefb5e42014-03-31 18:18:09 -070019 explicit
20 Nrd(const std::string& validatorConfig);
Obaid3f48fe52014-02-27 21:45:23 -060021
22 void
23 onRibRequest(const Interest& request);
24
25 void
26 enableLocalControlHeader();
27
28 void
29 listen();
30
31private:
32 void
33 sendResponse(const Name& name,
34 const nfd::ControlResponse& response);
35
36 void
37 sendResponse(const Name& name,
38 uint32_t code,
39 const std::string& text);
Yingdi Yudefb5e42014-03-31 18:18:09 -070040
41 void
42 onRibRequestValidated(const shared_ptr<const Interest>& request);
43
44 void
45 onRibRequestValidationFailed(const shared_ptr<const Interest>& request,
46 const std::string& failureInfo);
47
Obaid3f48fe52014-02-27 21:45:23 -060048 void
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070049 onCommandError(uint32_t code, const std::string& error,
50 const ndn::Interest& interest,
Obaid3f48fe52014-02-27 21:45:23 -060051 const PrefixRegOptions& options);
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070052
Obaid3f48fe52014-02-27 21:45:23 -060053 void
54 onRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
55
56 void
57 onUnRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
58
59 void
60 onControlHeaderSuccess();
61
62 void
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070063 onControlHeaderError(uint32_t code, const std::string& reason);
Obaid3f48fe52014-02-27 21:45:23 -060064
65 void
Obaidea56c612014-03-17 22:50:47 -050066 setInterestFilterFailed(const Name& name, const std::string& msg);
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070067
Obaidea56c612014-03-17 22:50:47 -050068 void
Obaid3f48fe52014-02-27 21:45:23 -060069 insertEntry(const Interest& request, const PrefixRegOptions& options);
70
71 void
72 deleteEntry(const Interest& request, const PrefixRegOptions& options);
73
74 bool
75 extractOptions(const Interest& request,
76 PrefixRegOptions& extractedOptions);
Obaid68711872014-04-08 03:16:40 -050077
78 void
79 onNotification(const nfd::FaceEventNotification& notification);
80
Obaid3f48fe52014-02-27 21:45:23 -060081private:
82 Rib m_managedRib;
Yingdi Yudefb5e42014-03-31 18:18:09 -070083 ndn::shared_ptr<ndn::Face> m_face;
Obaid68711872014-04-08 03:16:40 -050084 ndn::shared_ptr<nfd::Controller> m_nfdController;
Obaid3f48fe52014-02-27 21:45:23 -060085 ndn::KeyChain m_keyChain;
Yingdi Yudefb5e42014-03-31 18:18:09 -070086 ndn::ValidatorConfig m_validator;
Obaid68711872014-04-08 03:16:40 -050087 ndn::FaceMonitor m_faceMonitor;
Obaid3f48fe52014-02-27 21:45:23 -060088
89 typedef boost::function<void(Nrd*,
90 const Interest&,
91 const PrefixRegOptions&)> VerbProcessor;
92
93 typedef std::map<Name::Component, VerbProcessor> VerbDispatchTable;
94
95 typedef std::pair<Name::Component, VerbProcessor> VerbAndProcessor;
96
97
98 const VerbDispatchTable m_verbDispatch;
99
100 static const Name COMMAND_PREFIX; // /localhost/nrd
Obaidea56c612014-03-17 22:50:47 -0500101 static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
Obaid3f48fe52014-02-27 21:45:23 -0600102
103 // number of components in an invalid, but not malformed, unsigned command.
104 // (/localhost/nrd + verb + options) = 4
105 static const size_t COMMAND_UNSIGNED_NCOMPS;
106
107 // number of components in a valid signed Interest.
108 // 5 in mock (see UNSIGNED_NCOMPS), 8 with signed Interest support.
109 static const size_t COMMAND_SIGNED_NCOMPS;
110
111 static const VerbAndProcessor COMMAND_VERBS[];
112};
113
114} // namespace nrd
115} // namespace ndn
116
117#endif // NRD_HPP