blob: 7e1473ef716d8cb7bf6347bfa348cf5572ec0a3a [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:
18 Nrd();
19
20 void
21 onRibRequest(const Interest& request);
22
23 void
24 enableLocalControlHeader();
25
26 void
27 listen();
28
29private:
30 void
31 sendResponse(const Name& name,
32 const nfd::ControlResponse& response);
33
34 void
35 sendResponse(const Name& name,
36 uint32_t code,
37 const std::string& text);
38 void
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070039 onCommandError(uint32_t code, const std::string& error,
40 const ndn::Interest& interest,
Obaid3f48fe52014-02-27 21:45:23 -060041 const PrefixRegOptions& options);
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070042
Obaid3f48fe52014-02-27 21:45:23 -060043 void
44 onRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
45
46 void
47 onUnRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options);
48
49 void
50 onControlHeaderSuccess();
51
52 void
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070053 onControlHeaderError(uint32_t code, const std::string& reason);
Obaid3f48fe52014-02-27 21:45:23 -060054
55 void
Obaidea56c612014-03-17 22:50:47 -050056 setInterestFilterFailed(const Name& name, const std::string& msg);
Alexander Afanasyevd9e98732014-03-27 16:09:10 -070057
Obaidea56c612014-03-17 22:50:47 -050058 void
Obaid3f48fe52014-02-27 21:45:23 -060059 insertEntry(const Interest& request, const PrefixRegOptions& options);
60
61 void
62 deleteEntry(const Interest& request, const PrefixRegOptions& options);
63
64 bool
65 extractOptions(const Interest& request,
66 PrefixRegOptions& extractedOptions);
67private:
68 Rib m_managedRib;
69 ndn::Face m_face;
70 ndn::KeyChain m_keyChain;
71 shared_ptr<nfd::Controller> m_nfdController;
72
73 typedef boost::function<void(Nrd*,
74 const Interest&,
75 const PrefixRegOptions&)> VerbProcessor;
76
77 typedef std::map<Name::Component, VerbProcessor> VerbDispatchTable;
78
79 typedef std::pair<Name::Component, VerbProcessor> VerbAndProcessor;
80
81
82 const VerbDispatchTable m_verbDispatch;
83
84 static const Name COMMAND_PREFIX; // /localhost/nrd
Obaidea56c612014-03-17 22:50:47 -050085 static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
Obaid3f48fe52014-02-27 21:45:23 -060086
87 // number of components in an invalid, but not malformed, unsigned command.
88 // (/localhost/nrd + verb + options) = 4
89 static const size_t COMMAND_UNSIGNED_NCOMPS;
90
91 // number of components in a valid signed Interest.
92 // 5 in mock (see UNSIGNED_NCOMPS), 8 with signed Interest support.
93 static const size_t COMMAND_SIGNED_NCOMPS;
94
95 static const VerbAndProcessor COMMAND_VERBS[];
96};
97
98} // namespace nrd
99} // namespace ndn
100
101#endif // NRD_HPP