Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 5923bf8 | 2018-08-09 01:55:44 -0400 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2015-2018, Arizona Board of Regents. |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 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 | /** |
Davide Pesavento | 5923bf8 | 2018-08-09 01:55:44 -0400 | [diff] [blame^] | 33 | * @brief Options for PingServer |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 34 | */ |
| 35 | struct Options |
| 36 | { |
Davide Pesavento | 5923bf8 | 2018-08-09 01:55:44 -0400 | [diff] [blame^] | 37 | Name prefix; //!< prefix to register |
| 38 | time::milliseconds freshnessPeriod = 1_s; //!< data freshness period |
| 39 | size_t nMaxPings = 0; //!< max number of pings to satisfy (0 == no limit) |
| 40 | size_t payloadSize = 0; //!< response payload size (0 == no payload) |
| 41 | bool wantTimestamp = false; //!< print timestamp when response sent |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * @brief NDN modular ping server |
| 46 | */ |
| 47 | class PingServer : noncopyable |
| 48 | { |
| 49 | public: |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 50 | PingServer(Face& face, KeyChain& keyChain, const Options& options); |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 53 | * @brief Signals when Interest received |
| 54 | * |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 55 | * @param name incoming interest name |
| 56 | */ |
| 57 | signal::Signal<PingServer, Name> afterReceive; |
| 58 | |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 59 | /** |
| 60 | * @brief Signals when finished pinging |
| 61 | */ |
| 62 | signal::Signal<PingServer> afterFinish; |
| 63 | |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 64 | /** @brief starts ping server |
| 65 | * |
| 66 | * If options.shouldLimitSatisfied is false, this method does not return unless there's an error. |
| 67 | * Otherwise, this method returns when options.nMaxPings Interests are processed. |
| 68 | */ |
| 69 | void |
| 70 | run(); |
| 71 | |
| 72 | /** |
Eric Newberry | a93680e | 2015-07-15 19:25:29 -0700 | [diff] [blame] | 73 | * @brief starts the Interest filter |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 74 | * |
| 75 | * @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] | 76 | */ |
| 77 | void |
| 78 | start(); |
| 79 | |
| 80 | /** |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 81 | * @brief Unregister set interest filter |
| 82 | */ |
| 83 | void |
| 84 | stop(); |
| 85 | |
| 86 | /** |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 87 | * @brief gets the number of pings received |
| 88 | */ |
Davide Pesavento | 5923bf8 | 2018-08-09 01:55:44 -0400 | [diff] [blame^] | 89 | size_t |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 90 | getNPings() const; |
| 91 | |
| 92 | private: |
| 93 | /** |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 94 | * @brief Called when interest received |
| 95 | * |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 96 | * @param interest incoming interest |
| 97 | */ |
| 98 | void |
| 99 | onInterest(const Interest& interest); |
| 100 | |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 101 | private: |
| 102 | const Options& m_options; |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 103 | Face& m_face; |
Davide Pesavento | 5923bf8 | 2018-08-09 01:55:44 -0400 | [diff] [blame^] | 104 | KeyChain& m_keyChain; |
| 105 | size_t m_nPings; |
Eric Newberry | 62f7f71 | 2015-05-17 12:15:52 -0700 | [diff] [blame] | 106 | Block m_payload; |
Davide Pesavento | 5923bf8 | 2018-08-09 01:55:44 -0400 | [diff] [blame^] | 107 | const RegisteredPrefixId* m_regPrefixId; |
Eric Newberry | 94996d6 | 2015-05-07 13:48:46 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | } // namespace server |
| 111 | } // namespace ping |
| 112 | } // namespace ndn |
| 113 | |
Davide Pesavento | 5923bf8 | 2018-08-09 01:55:44 -0400 | [diff] [blame^] | 114 | #endif // NDN_TOOLS_PING_SERVER_PING_SERVER_HPP |