blob: f13769c0aada9ca27252c91cd13d8f62393181c3 [file] [log] [blame]
Eric Newberry94996d62015-05-07 13:48:46 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento5923bf82018-08-09 01:55:44 -04002/*
Davide Pesaventoa0e6b602021-01-21 19:47:04 -05003 * Copyright (c) 2015-2021, Arizona Board of Regents.
Eric Newberry94996d62015-05-07 13:48:46 -07004 *
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 Pesaventoa0e6b602021-01-21 19:47:04 -050028#include <ndn-cxx/util/signal.hpp>
29
Eric Newberry94996d62015-05-07 13:48:46 -070030namespace ndn {
31namespace ping {
32namespace server {
33
34/**
Davide Pesavento5923bf82018-08-09 01:55:44 -040035 * @brief Options for PingServer
Eric Newberry94996d62015-05-07 13:48:46 -070036 */
37struct Options
38{
Davide Pesavento5923bf82018-08-09 01:55:44 -040039 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 Pesavento2bdda1d2018-08-09 19:35:49 -040044 bool wantQuiet = false; //!< suppress printing per-packet log message
Eric Newberry94996d62015-05-07 13:48:46 -070045};
46
47/**
48 * @brief NDN modular ping server
49 */
50class PingServer : noncopyable
51{
52public:
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070053 PingServer(Face& face, KeyChain& keyChain, const Options& options);
Eric Newberry94996d62015-05-07 13:48:46 -070054
55 /**
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070056 * @brief Signals when Interest received
57 *
Eric Newberry94996d62015-05-07 13:48:46 -070058 * @param name incoming interest name
59 */
Davide Pesaventoa0e6b602021-01-21 19:47:04 -050060 util::Signal<PingServer, Name> afterReceive;
Eric Newberry94996d62015-05-07 13:48:46 -070061
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070062 /**
63 * @brief Signals when finished pinging
64 */
Davide Pesaventoa0e6b602021-01-21 19:47:04 -050065 util::Signal<PingServer> afterFinish;
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070066
Eric Newberry94996d62015-05-07 13:48:46 -070067 /** @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 Newberrya93680e2015-07-15 19:25:29 -070076 * @brief starts the Interest filter
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070077 *
78 * @note This method is non-blocking and caller need to call face.processEvents()
Eric Newberrya93680e2015-07-15 19:25:29 -070079 */
80 void
81 start();
82
83 /**
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070084 * @brief Unregister set interest filter
85 */
86 void
87 stop();
88
89 /**
Eric Newberry94996d62015-05-07 13:48:46 -070090 * @brief gets the number of pings received
91 */
Davide Pesavento5923bf82018-08-09 01:55:44 -040092 size_t
Eric Newberry94996d62015-05-07 13:48:46 -070093 getNPings() const;
94
95private:
96 /**
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070097 * @brief Called when interest received
98 *
Eric Newberry94996d62015-05-07 13:48:46 -070099 * @param interest incoming interest
100 */
101 void
102 onInterest(const Interest& interest);
103
Eric Newberry94996d62015-05-07 13:48:46 -0700104private:
105 const Options& m_options;
Eric Newberry94996d62015-05-07 13:48:46 -0700106 Face& m_face;
Davide Pesavento5923bf82018-08-09 01:55:44 -0400107 KeyChain& m_keyChain;
108 size_t m_nPings;
Eric Newberry62f7f712015-05-17 12:15:52 -0700109 Block m_payload;
Junxiao Shi06d008c2019-02-04 08:26:59 +0000110 RegisteredPrefixHandle m_registeredPrefix;
Eric Newberry94996d62015-05-07 13:48:46 -0700111};
112
113} // namespace server
114} // namespace ping
115} // namespace ndn
116
Davide Pesavento5923bf82018-08-09 01:55:44 -0400117#endif // NDN_TOOLS_PING_SERVER_PING_SERVER_HPP