blob: 49df0b55f77e8ae506a2fb88c41641d9eb6cdd43 [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"
11
12namespace ndn {
13namespace nrd {
14
15class Nrd
16{
17public:
Yingdi Yudefb5e42014-03-31 18:18:09 -070018 explicit
19 Nrd(const std::string& validatorConfig);
Obaid3f48fe52014-02-27 21:45:23 -060020
21 void
22 onRibRequest(const Interest& request);
23
24 void
25 enableLocalControlHeader();
26
27 void
28 listen();
29
30private:
31 void
32 sendResponse(const Name& name,
33 const nfd::ControlResponse& response);
34
35 void
36 sendResponse(const Name& name,
37 uint32_t code,
38 const std::string& text);
Yingdi Yudefb5e42014-03-31 18:18:09 -070039
40 void
41 onRibRequestValidated(const shared_ptr<const Interest>& request);
42
43 void
44 onRibRequestValidationFailed(const shared_ptr<const Interest>& request,
45 const std::string& failureInfo);
46
Obaid3f48fe52014-02-27 21:45:23 -060047 void
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070048 onCommandError(uint32_t code, const std::string& error,
49 const ndn::Interest& interest,
Obaid3f48fe52014-02-27 21:45:23 -060050 const PrefixRegOptions& options);
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070051
Obaid3f48fe52014-02-27 21:45:23 -060052 void
53 onRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
54
55 void
56 onUnRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
57
58 void
59 onControlHeaderSuccess();
60
61 void
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070062 onControlHeaderError(uint32_t code, const std::string& reason);
Obaid3f48fe52014-02-27 21:45:23 -060063
64 void
Obaidea56c612014-03-17 22:50:47 -050065 setInterestFilterFailed(const Name& name, const std::string& msg);
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070066
Obaidea56c612014-03-17 22:50:47 -050067 void
Obaid3f48fe52014-02-27 21:45:23 -060068 insertEntry(const Interest& request, const PrefixRegOptions& options);
69
70 void
71 deleteEntry(const Interest& request, const PrefixRegOptions& options);
72
73 bool
74 extractOptions(const Interest& request,
75 PrefixRegOptions& extractedOptions);
76private:
77 Rib m_managedRib;
Yingdi Yudefb5e42014-03-31 18:18:09 -070078 ndn::shared_ptr<ndn::Face> m_face;
Obaid3f48fe52014-02-27 21:45:23 -060079 ndn::KeyChain m_keyChain;
Yingdi Yudefb5e42014-03-31 18:18:09 -070080 ndn::ValidatorConfig m_validator;
Obaid3f48fe52014-02-27 21:45:23 -060081 shared_ptr<nfd::Controller> m_nfdController;
82
83 typedef boost::function<void(Nrd*,
84 const Interest&,
85 const PrefixRegOptions&)> VerbProcessor;
86
87 typedef std::map<Name::Component, VerbProcessor> VerbDispatchTable;
88
89 typedef std::pair<Name::Component, VerbProcessor> VerbAndProcessor;
90
91
92 const VerbDispatchTable m_verbDispatch;
93
94 static const Name COMMAND_PREFIX; // /localhost/nrd
Obaidea56c612014-03-17 22:50:47 -050095 static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
Obaid3f48fe52014-02-27 21:45:23 -060096
97 // number of components in an invalid, but not malformed, unsigned command.
98 // (/localhost/nrd + verb + options) = 4
99 static const size_t COMMAND_UNSIGNED_NCOMPS;
100
101 // number of components in a valid signed Interest.
102 // 5 in mock (see UNSIGNED_NCOMPS), 8 with signed Interest support.
103 static const size_t COMMAND_SIGNED_NCOMPS;
104
105 static const VerbAndProcessor COMMAND_VERBS[];
106};
107
108} // namespace nrd
109} // namespace ndn
110
111#endif // NRD_HPP