blob: 3f99fd790ef8bab9d324c13473ee0bdc0a39f1fd [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 /**
Eric Newberrya93680e2015-07-15 19:25:29 -070077 * Runs the ping client (blocking)
Eric Newberry4164b8e2015-04-23 17:29:18 -070078 */
79 void
80 run();
81
Eric Newberrya93680e2015-07-15 19:25:29 -070082 /**
83 * Runs the ping client (non-blocking)
84 */
85 void
86 start();
87
Eric Newberry4164b8e2015-04-23 17:29:18 -070088private:
89 /**
90 * Creates a ping Name from the sequence number
91 * @param seq ping sequence number
92 */
93 Name
94 makePingName(uint64_t seq) const;
95
96 /**
97 * Performs individual ping
98 */
99 void
100 performPing();
101
102 /**
103 * Called when ping returned successfully
104 * @param interest NDN interest
105 * @param data returned data
106 * @param seq ping sequence number
107 * @param sendTime time ping sent
108 */
109 void
110 onData(const Interest& interest, Data& data, uint64_t seq, const time::steady_clock::TimePoint& sendTime);
111
112 /**
113 * Called when ping timed out
114 * @param interest NDN interest
115 * @param seq ping sequence number
116 */
117 void
118 onTimeout(const Interest& interest, uint64_t seq);
119
120 /**
121 * Called after ping received or timed out
122 */
123 void
124 finish();
125
126private:
127 const Options& m_options;
128 int m_nSent;
129 uint64_t m_nextSeq;
130 int m_nOutstanding;
131 Face& m_face;
132 scheduler::Scheduler m_scheduler;
133};
134
135} // namespace client
136} // namespace ping
137} // namespace ndn
138
139#endif // NDN_TOOLS_PING_CLIENT_PING_HPP