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: |
Yingdi Yu | defb5e4 | 2014-03-31 18:18:09 -0700 | [diff] [blame] | 18 | explicit |
| 19 | Nrd(const std::string& validatorConfig); |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 20 | |
| 21 | void |
| 22 | onRibRequest(const Interest& request); |
| 23 | |
| 24 | void |
| 25 | enableLocalControlHeader(); |
| 26 | |
| 27 | void |
| 28 | listen(); |
| 29 | |
| 30 | private: |
| 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 Yu | defb5e4 | 2014-03-31 18:18:09 -0700 | [diff] [blame] | 39 | |
| 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 | |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 47 | void |
Alexander Afanasyev | d9e9873 | 2014-03-27 16:09:10 -0700 | [diff] [blame] | 48 | onCommandError(uint32_t code, const std::string& error, |
| 49 | const ndn::Interest& interest, |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 50 | const PrefixRegOptions& options); |
Alexander Afanasyev | d9e9873 | 2014-03-27 16:09:10 -0700 | [diff] [blame] | 51 | |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 52 | 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 Afanasyev | d9e9873 | 2014-03-27 16:09:10 -0700 | [diff] [blame] | 62 | onControlHeaderError(uint32_t code, const std::string& reason); |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 63 | |
| 64 | void |
Obaid | ea56c61 | 2014-03-17 22:50:47 -0500 | [diff] [blame] | 65 | setInterestFilterFailed(const Name& name, const std::string& msg); |
Alexander Afanasyev | d9e9873 | 2014-03-27 16:09:10 -0700 | [diff] [blame] | 66 | |
Obaid | ea56c61 | 2014-03-17 22:50:47 -0500 | [diff] [blame] | 67 | void |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 68 | 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); |
| 76 | private: |
| 77 | Rib m_managedRib; |
Yingdi Yu | defb5e4 | 2014-03-31 18:18:09 -0700 | [diff] [blame] | 78 | ndn::shared_ptr<ndn::Face> m_face; |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 79 | ndn::KeyChain m_keyChain; |
Yingdi Yu | defb5e4 | 2014-03-31 18:18:09 -0700 | [diff] [blame] | 80 | ndn::ValidatorConfig m_validator; |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 81 | 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 |
Obaid | ea56c61 | 2014-03-17 22:50:47 -0500 | [diff] [blame] | 95 | static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 96 | |
| 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 |