Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2015, Arizona Board of Regents. |
| 4 | * |
| 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
| 7 | * |
| 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * @author Eric Newberry <enewberry@email.arizona.edu> |
| 20 | * @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu> |
| 21 | */ |
| 22 | |
| 23 | #ifndef NDN_TOOLS_PING_SERVER_PING_SERVER_HPP |
| 24 | #define NDN_TOOLS_PING_SERVER_PING_SERVER_HPP |
| 25 | |
| 26 | #include "core/common.hpp" |
| 27 | |
| 28 | namespace ndn { |
| 29 | namespace ping { |
| 30 | namespace server { |
| 31 | |
| 32 | /** |
| 33 | * @brief options for ndnping server |
| 34 | */ |
| 35 | struct Options |
| 36 | { |
| 37 | Name prefix; //!< prefix to register |
| 38 | time::milliseconds freshnessPeriod; //!< freshness period |
| 39 | bool shouldLimitSatisfied; //!< should limit the number of pings satisfied |
| 40 | int nMaxPings; //!< max number of pings to satisfy |
| 41 | bool shouldPrintTimestamp; //!< print timestamp when response sent |
Eric Newberry | 62f7f71 | 2015-05-17 12:15:52 -0700 | [diff] [blame] | 42 | int payloadSize; //!< user specified payload size |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | /** |
| 46 | * @brief NDN modular ping server |
| 47 | */ |
| 48 | class PingServer : noncopyable |
| 49 | { |
| 50 | public: |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 51 | PingServer(Face& face, KeyChain& keyChain, const Options& options); |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 54 | * @brief Signals when Interest received |
| 55 | * |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 56 | * @param name incoming interest name |
| 57 | */ |
| 58 | signal::Signal<PingServer, Name> afterReceive; |
| 59 | |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 60 | /** |
| 61 | * @brief Signals when finished pinging |
| 62 | */ |
| 63 | signal::Signal<PingServer> afterFinish; |
| 64 | |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 65 | /** @brief starts ping server |
| 66 | * |
| 67 | * If options.shouldLimitSatisfied is false, this method does not return unless there's an error. |
| 68 | * Otherwise, this method returns when options.nMaxPings Interests are processed. |
| 69 | */ |
| 70 | void |
| 71 | run(); |
| 72 | |
| 73 | /** |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 74 | * @brief starts the Interest filter |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 75 | * |
| 76 | * @note This method is non-blocking and caller need to call face.processEvents() |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 77 | */ |
| 78 | void |
| 79 | start(); |
| 80 | |
| 81 | /** |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 82 | * @brief Unregister set interest filter |
| 83 | */ |
| 84 | void |
| 85 | stop(); |
| 86 | |
| 87 | /** |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 88 | * @brief gets the number of pings received |
| 89 | */ |
| 90 | int |
| 91 | getNPings() const; |
| 92 | |
| 93 | private: |
| 94 | /** |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 95 | * @brief Called when interest received |
| 96 | * |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 97 | * @param interest incoming interest |
| 98 | */ |
| 99 | void |
| 100 | onInterest(const Interest& interest); |
| 101 | |
| 102 | /** |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 103 | * @brief Called when prefix registration failed |
| 104 | * |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 105 | * @param reason reason for failure |
| 106 | */ |
| 107 | void |
| 108 | onRegisterFailed(const std::string& reason); |
| 109 | |
| 110 | private: |
| 111 | const Options& m_options; |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 112 | KeyChain& m_keyChain; |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 113 | Name m_name; |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 114 | int m_nPings; |
| 115 | Face& m_face; |
Eric Newberry | 62f7f71 | 2015-05-17 12:15:52 -0700 | [diff] [blame] | 116 | Block m_payload; |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 117 | |
| 118 | const RegisteredPrefixId* m_registeredPrefixId; |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | } // namespace server |
| 122 | } // namespace ping |
| 123 | } // namespace ndn |
| 124 | |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame^] | 125 | #endif //NDN_TOOLS_PING_SERVER_PING_SERVER_HPP |