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" |
Obaid | 6871187 | 2014-04-08 03:16:40 -0500 | [diff] [blame] | 11 | #include "face-monitor.hpp" |
Obaid | 5748c0c | 2014-04-09 18:00:42 -0500 | [diff] [blame] | 12 | #include "nrd-config.hpp" |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 13 | |
| 14 | namespace ndn { |
| 15 | namespace nrd { |
| 16 | |
Obaid | 5748c0c | 2014-04-09 18:00:42 -0500 | [diff] [blame] | 17 | class Nrd : noncopyable |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 18 | { |
| 19 | public: |
Obaid | 5748c0c | 2014-04-09 18:00:42 -0500 | [diff] [blame] | 20 | Nrd(const ndn::nrd::ConfigSection& securitySection, |
| 21 | const std::string& validatorConfig); |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 22 | |
| 23 | void |
| 24 | onRibRequest(const Interest& request); |
| 25 | |
| 26 | void |
| 27 | enableLocalControlHeader(); |
| 28 | |
| 29 | void |
| 30 | listen(); |
| 31 | |
| 32 | private: |
| 33 | void |
| 34 | sendResponse(const Name& name, |
| 35 | const nfd::ControlResponse& response); |
| 36 | |
| 37 | void |
| 38 | sendResponse(const Name& name, |
| 39 | uint32_t code, |
| 40 | const std::string& text); |
Yingdi Yu | defb5e4 | 2014-03-31 18:18:09 -0700 | [diff] [blame] | 41 | |
| 42 | void |
| 43 | onRibRequestValidated(const shared_ptr<const Interest>& request); |
| 44 | |
| 45 | void |
| 46 | onRibRequestValidationFailed(const shared_ptr<const Interest>& request, |
| 47 | const std::string& failureInfo); |
| 48 | |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 49 | void |
Alexander Afanasyev | d9e9873 | 2014-03-27 16:09:10 -0700 | [diff] [blame] | 50 | onCommandError(uint32_t code, const std::string& error, |
| 51 | const ndn::Interest& interest, |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 52 | const PrefixRegOptions& options); |
Alexander Afanasyev | d9e9873 | 2014-03-27 16:09:10 -0700 | [diff] [blame] | 53 | |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 54 | void |
| 55 | onRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options); |
| 56 | |
| 57 | void |
| 58 | onUnRegSuccess(const ndn::Interest& interest, const PrefixRegOptions& options); |
| 59 | |
| 60 | void |
| 61 | onControlHeaderSuccess(); |
| 62 | |
| 63 | void |
Alexander Afanasyev | d9e9873 | 2014-03-27 16:09:10 -0700 | [diff] [blame] | 64 | onControlHeaderError(uint32_t code, const std::string& reason); |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 65 | |
| 66 | void |
Obaid | ea56c61 | 2014-03-17 22:50:47 -0500 | [diff] [blame] | 67 | setInterestFilterFailed(const Name& name, const std::string& msg); |
Alexander Afanasyev | d9e9873 | 2014-03-27 16:09:10 -0700 | [diff] [blame] | 68 | |
Obaid | ea56c61 | 2014-03-17 22:50:47 -0500 | [diff] [blame] | 69 | void |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 70 | insertEntry(const Interest& request, const PrefixRegOptions& options); |
| 71 | |
| 72 | void |
| 73 | deleteEntry(const Interest& request, const PrefixRegOptions& options); |
| 74 | |
| 75 | bool |
| 76 | extractOptions(const Interest& request, |
| 77 | PrefixRegOptions& extractedOptions); |
Obaid | 6871187 | 2014-04-08 03:16:40 -0500 | [diff] [blame] | 78 | |
| 79 | void |
| 80 | onNotification(const nfd::FaceEventNotification& notification); |
| 81 | |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 82 | private: |
| 83 | Rib m_managedRib; |
Yingdi Yu | defb5e4 | 2014-03-31 18:18:09 -0700 | [diff] [blame] | 84 | ndn::shared_ptr<ndn::Face> m_face; |
Obaid | 6871187 | 2014-04-08 03:16:40 -0500 | [diff] [blame] | 85 | ndn::shared_ptr<nfd::Controller> m_nfdController; |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 86 | ndn::KeyChain m_keyChain; |
Yingdi Yu | defb5e4 | 2014-03-31 18:18:09 -0700 | [diff] [blame] | 87 | ndn::ValidatorConfig m_validator; |
Obaid | 6871187 | 2014-04-08 03:16:40 -0500 | [diff] [blame] | 88 | ndn::FaceMonitor m_faceMonitor; |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 89 | |
| 90 | typedef boost::function<void(Nrd*, |
| 91 | const Interest&, |
| 92 | const PrefixRegOptions&)> VerbProcessor; |
| 93 | |
| 94 | typedef std::map<Name::Component, VerbProcessor> VerbDispatchTable; |
| 95 | |
| 96 | typedef std::pair<Name::Component, VerbProcessor> VerbAndProcessor; |
| 97 | |
| 98 | |
| 99 | const VerbDispatchTable m_verbDispatch; |
| 100 | |
| 101 | static const Name COMMAND_PREFIX; // /localhost/nrd |
Obaid | ea56c61 | 2014-03-17 22:50:47 -0500 | [diff] [blame] | 102 | static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 103 | |
| 104 | // number of components in an invalid, but not malformed, unsigned command. |
| 105 | // (/localhost/nrd + verb + options) = 4 |
| 106 | static const size_t COMMAND_UNSIGNED_NCOMPS; |
| 107 | |
| 108 | // number of components in a valid signed Interest. |
| 109 | // 5 in mock (see UNSIGNED_NCOMPS), 8 with signed Interest support. |
| 110 | static const size_t COMMAND_SIGNED_NCOMPS; |
| 111 | |
| 112 | static const VerbAndProcessor COMMAND_VERBS[]; |
| 113 | }; |
| 114 | |
| 115 | } // namespace nrd |
| 116 | } // namespace ndn |
| 117 | |
| 118 | #endif // NRD_HPP |