blob: ddc3a195d66820a2b05768e07a4af6518de03d0f [file] [log] [blame]
Eric Newberry94996d62015-05-07 13:48:46 -07001/* -*- 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
28namespace ndn {
29namespace ping {
30namespace server {
31
32/**
33 * @brief options for ndnping server
34 */
35struct 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
42};
43
44/**
45 * @brief NDN modular ping server
46 */
47class PingServer : noncopyable
48{
49public:
50 PingServer(Face& face, const Options& options);
51
52 /**
53 * Signals when Interest received
54 * @param name incoming interest name
55 */
56 signal::Signal<PingServer, Name> afterReceive;
57
58 /** @brief starts ping server
59 *
60 * If options.shouldLimitSatisfied is false, this method does not return unless there's an error.
61 * Otherwise, this method returns when options.nMaxPings Interests are processed.
62 */
63 void
64 run();
65
66 /**
67 * @brief gets the number of pings received
68 */
69 int
70 getNPings() const;
71
72private:
73 /**
74 * Called when interest received
75 * @param interest incoming interest
76 */
77 void
78 onInterest(const Interest& interest);
79
80 /**
81 * Called when prefix registration failed
82 * @param reason reason for failure
83 */
84 void
85 onRegisterFailed(const std::string& reason);
86
87private:
88 const Options& m_options;
89 Name m_name;
90 KeyChain m_keyChain;
91 int m_nPings;
92 Face& m_face;
93};
94
95} // namespace server
96} // namespace ping
97} // namespace ndn
98
99#endif //NDN_TOOLS_PING_SERVER_PING_SERVER_HPP