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