blob: 9d300679186207abc479030e8b3a273143e3c5b1 [file] [log] [blame]
Eric Newberry4164b8e2015-04-23 17:29:18 -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: Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
20 * @author: Eric Newberry <enewberry@email.arizona.edu>
21 */
22
23#ifndef NDN_TOOLS_PING_CLIENT_PING_HPP
24#define NDN_TOOLS_PING_CLIENT_PING_HPP
25
26#include "core/common.hpp"
27
28namespace ndn {
29namespace ping {
30namespace client {
31
32typedef time::duration<double, time::milliseconds::period> Rtt;
33
34/**
35 * @brief options for ndnping client
36 */
37struct Options
38{
39 Name prefix; //!< prefix pinged
40 bool shouldAllowStaleData; //!< allow stale Data
41 bool shouldGenerateRandomSeq; //!< random ping sequence
42 bool shouldPrintTimestamp; //!< print timestamp
43 int nPings; //!< number of pings
44 time::milliseconds interval; //!< ping interval
45 time::milliseconds timeout; //!< timeout threshold
46 uint64_t startSeq; //!< start ping sequence number
47 name::Component clientIdentifier; //!< client identifier
48};
49
50/**
51 * @brief NDN modular ping client
52 */
53class Ping : noncopyable
54{
55public:
56 Ping(Face& face, const Options& options);
57
58 /**
59 * Signals on the successful return of a packet
60 * @param seq ping sequence number
61 * @param rtt round trip time
62 */
63 signal::Signal<Ping, uint64_t, Rtt> afterResponse;
64
65 /**
66 * Signals on timeout of a packet
67 * @param seq ping sequence number
68 */
69 signal::Signal<Ping, uint64_t> afterTimeout;
70
71 /**
72 * Signals when finished pinging
73 */
74 signal::Signal<Ping> afterFinish;
75
76 /**
77 * Executes the pings
78 */
79 void
80 run();
81
82private:
83 /**
84 * Creates a ping Name from the sequence number
85 * @param seq ping sequence number
86 */
87 Name
88 makePingName(uint64_t seq) const;
89
90 /**
91 * Performs individual ping
92 */
93 void
94 performPing();
95
96 /**
97 * Called when ping returned successfully
98 * @param interest NDN interest
99 * @param data returned data
100 * @param seq ping sequence number
101 * @param sendTime time ping sent
102 */
103 void
104 onData(const Interest& interest, Data& data, uint64_t seq, const time::steady_clock::TimePoint& sendTime);
105
106 /**
107 * Called when ping timed out
108 * @param interest NDN interest
109 * @param seq ping sequence number
110 */
111 void
112 onTimeout(const Interest& interest, uint64_t seq);
113
114 /**
115 * Called after ping received or timed out
116 */
117 void
118 finish();
119
120private:
121 const Options& m_options;
122 int m_nSent;
123 uint64_t m_nextSeq;
124 int m_nOutstanding;
125 Face& m_face;
126 scheduler::Scheduler m_scheduler;
127};
128
129} // namespace client
130} // namespace ping
131} // namespace ndn
132
133#endif // NDN_TOOLS_PING_CLIENT_PING_HPP