blob: d6007d7880d7caff29212fb258200b6ce3f1a304 [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"
Obaid5748c0c2014-04-09 18:00:42 -050012#include "nrd-config.hpp"
Obaid3f48fe52014-02-27 21:45:23 -060013
14namespace ndn {
15namespace nrd {
16
Obaid5748c0c2014-04-09 18:00:42 -050017class Nrd : noncopyable
Obaid3f48fe52014-02-27 21:45:23 -060018{
19public:
Obaid5748c0c2014-04-09 18:00:42 -050020 Nrd(const ndn::nrd::ConfigSection& securitySection,
21 const std::string& validatorConfig);
Obaid3f48fe52014-02-27 21:45:23 -060022
23 void
24 onRibRequest(const Interest& request);
25
26 void
27 enableLocalControlHeader();
28
29 void
30 listen();
31
32private:
33 void
34 sendResponse(const Name& name,
35 const nfd::ControlResponse& response);
36
37 void
38 sendResponse(const Name& name,
39 uint32_t code,
40 const std::string& text);
Yingdi Yudefb5e42014-03-31 18:18:09 -070041
42 void
43 onRibRequestValidated(const shared_ptr<const Interest>& request);
44
45 void
46 onRibRequestValidationFailed(const shared_ptr<const Interest>& request,
47 const std::string& failureInfo);
48
Obaid3f48fe52014-02-27 21:45:23 -060049 void
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070050 onCommandError(uint32_t code, const std::string& error,
51 const ndn::Interest& interest,
Obaid3f48fe52014-02-27 21:45:23 -060052 const PrefixRegOptions& options);
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070053
Obaid3f48fe52014-02-27 21:45:23 -060054 void
55 onRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
56
57 void
58 onUnRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
59
60 void
61 onControlHeaderSuccess();
62
63 void
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070064 onControlHeaderError(uint32_t code, const std::string& reason);
Obaid3f48fe52014-02-27 21:45:23 -060065
66 void
Obaidea56c612014-03-17 22:50:47 -050067 setInterestFilterFailed(const Name& name, const std::string& msg);
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070068
Obaidea56c612014-03-17 22:50:47 -050069 void
Obaid3f48fe52014-02-27 21:45:23 -060070 insertEntry(const Interest& request, const PrefixRegOptions& options);
71
72 void
73 deleteEntry(const Interest& request, const PrefixRegOptions& options);
74
75 bool
76 extractOptions(const Interest& request,
77 PrefixRegOptions& extractedOptions);
Obaid68711872014-04-08 03:16:40 -050078
79 void
80 onNotification(const nfd::FaceEventNotification& notification);
81
Obaid3f48fe52014-02-27 21:45:23 -060082private:
83 Rib m_managedRib;
Yingdi Yudefb5e42014-03-31 18:18:09 -070084 ndn::shared_ptr<ndn::Face> m_face;
Obaid68711872014-04-08 03:16:40 -050085 ndn::shared_ptr<nfd::Controller> m_nfdController;
Obaid3f48fe52014-02-27 21:45:23 -060086 ndn::KeyChain m_keyChain;
Yingdi Yudefb5e42014-03-31 18:18:09 -070087 ndn::ValidatorConfig m_validator;
Obaid68711872014-04-08 03:16:40 -050088 ndn::FaceMonitor m_faceMonitor;
Obaid3f48fe52014-02-27 21:45:23 -060089
90 typedef boost::function<void(Nrd*,
91 const Interest&,
92 const PrefixRegOptions&)> VerbProcessor;
93
94 typedef std::map<Name::Component, VerbProcessor> VerbDispatchTable;
95
96 typedef std::pair<Name::Component, VerbProcessor> VerbAndProcessor;
97
98
99 const VerbDispatchTable m_verbDispatch;
100
101 static const Name COMMAND_PREFIX; // /localhost/nrd
Obaidea56c612014-03-17 22:50:47 -0500102 static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
Obaid3f48fe52014-02-27 21:45:23 -0600103
104 // number of components in an invalid, but not malformed, unsigned command.
105 // (/localhost/nrd + verb + options) = 4
106 static const size_t COMMAND_UNSIGNED_NCOMPS;
107
108 // number of components in a valid signed Interest.
109 // 5 in mock (see UNSIGNED_NCOMPS), 8 with signed Interest support.
110 static const size_t COMMAND_SIGNED_NCOMPS;
111
112 static const VerbAndProcessor COMMAND_VERBS[];
113};
114
115} // namespace nrd
116} // namespace ndn
117
118#endif // NRD_HPP