Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 1 | /* -*- 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 | |
| 12 | namespace ndn { |
| 13 | namespace nrd { |
| 14 | |
| 15 | class Nrd |
| 16 | { |
| 17 | public: |
| 18 | Nrd(); |
| 19 | |
| 20 | void |
| 21 | onRibRequest(const Interest& request); |
| 22 | |
| 23 | void |
| 24 | enableLocalControlHeader(); |
| 25 | |
| 26 | void |
| 27 | listen(); |
| 28 | |
| 29 | private: |
| 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 Afanasyev | d9e9873 | 2014-03-27 16:09:10 -0700 | [diff] [blame^] | 39 | onCommandError(uint32_t code, const std::string& error, |
| 40 | const ndn::Interest& interest, |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 41 | const PrefixRegOptions& options); |
Alexander Afanasyev | d9e9873 | 2014-03-27 16:09:10 -0700 | [diff] [blame^] | 42 | |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 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 |
Alexander Afanasyev | d9e9873 | 2014-03-27 16:09:10 -0700 | [diff] [blame^] | 53 | onControlHeaderError(uint32_t code, const std::string& reason); |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 54 | |
| 55 | void |
Obaid | ea56c61 | 2014-03-17 22:50:47 -0500 | [diff] [blame] | 56 | setInterestFilterFailed(const Name& name, const std::string& msg); |
Alexander Afanasyev | d9e9873 | 2014-03-27 16:09:10 -0700 | [diff] [blame^] | 57 | |
Obaid | ea56c61 | 2014-03-17 22:50:47 -0500 | [diff] [blame] | 58 | void |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 59 | 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); |
| 67 | private: |
| 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 |
Obaid | ea56c61 | 2014-03-17 22:50:47 -0500 | [diff] [blame] | 85 | static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 86 | |
| 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 |