blob: 210af747b9b358f9197004a0696657ad3036154b [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
39 onCommandError(const std::string& error,
40 const ndn::Interest& interest,
41 const PrefixRegOptions& options);
42
43 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
53 onControlHeaderError();
54
55 void
56 insertEntry(const Interest& request, const PrefixRegOptions& options);
57
58 void
59 deleteEntry(const Interest& request, const PrefixRegOptions& options);
60
61 bool
62 extractOptions(const Interest& request,
63 PrefixRegOptions& extractedOptions);
64private:
65 Rib m_managedRib;
66 ndn::Face m_face;
67 ndn::KeyChain m_keyChain;
68 shared_ptr<nfd::Controller> m_nfdController;
69
70 typedef boost::function<void(Nrd*,
71 const Interest&,
72 const PrefixRegOptions&)> VerbProcessor;
73
74 typedef std::map<Name::Component, VerbProcessor> VerbDispatchTable;
75
76 typedef std::pair<Name::Component, VerbProcessor> VerbAndProcessor;
77
78
79 const VerbDispatchTable m_verbDispatch;
80
81 static const Name COMMAND_PREFIX; // /localhost/nrd
82
83 // number of components in an invalid, but not malformed, unsigned command.
84 // (/localhost/nrd + verb + options) = 4
85 static const size_t COMMAND_UNSIGNED_NCOMPS;
86
87 // number of components in a valid signed Interest.
88 // 5 in mock (see UNSIGNED_NCOMPS), 8 with signed Interest support.
89 static const size_t COMMAND_SIGNED_NCOMPS;
90
91 static const VerbAndProcessor COMMAND_VERBS[];
92};
93
94} // namespace nrd
95} // namespace ndn
96
97#endif // NRD_HPP
98