Eradicate all uses of std::bind()

Change-Id: I6e1ccf2d87b76142e6d519c1a288d03022e4d167
This commit is contained in:
Davide Pesavento committed 2021-07-30 20:35:06 -04:00
1 parent e8c82ef8a1
commit f8d9a531dd
24 files changed
+166 -192

No files matched your search

+3
View File
@@ -76,4 +76,7 @@ using boost::noncopyable;
} // namespace ndn
#define FORWARD_TO_MEM_FN(func) \
[this] (auto&&... args) { this->func(std::forward<decltype(args)>(args)...); }
#endif // NDN_TOOLS_CORE_COMMON_HPP
+9 -9
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2020, Arizona Board of Regents.
* Copyright (c) 2014-2021, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -32,9 +32,9 @@ namespace tests {
using namespace ndn::tests;
BOOST_AUTO_TEST_SUITE(Ping)
BOOST_AUTO_TEST_SUITE(TestPing)
BOOST_AUTO_TEST_SUITE(TestClient)
using ping::client::Ping;
using client::Ping;
BOOST_FIXTURE_TEST_CASE(Basic, IoFixture)
{
@@ -55,10 +55,10 @@ BOOST_FIXTURE_TEST_CASE(Basic, IoFixture)
std::vector<uint64_t> nackSeqs;
std::vector<uint64_t> timeoutSeqs;
ping.afterData.connect(bind([&] (uint64_t seq) { dataSeqs.push_back(seq); }, _1));
ping.afterNack.connect(bind([&] (uint64_t seq) { nackSeqs.push_back(seq); }, _1));
ping.afterTimeout.connect(bind([&] (uint64_t seq) { timeoutSeqs.push_back(seq); }, _1));
ping.afterFinish.connect(bind([&] {
ping.afterData.connect([&] (uint64_t seq, auto&&...) { dataSeqs.push_back(seq); });
ping.afterNack.connect([&] (uint64_t seq, auto&&...) { nackSeqs.push_back(seq); });
ping.afterTimeout.connect([&] (uint64_t seq, auto&&...) { timeoutSeqs.push_back(seq); });
ping.afterFinish.connect([&] {
BOOST_REQUIRE_EQUAL(dataSeqs.size(), 2);
BOOST_REQUIRE_EQUAL(nackSeqs.size(), 1);
BOOST_REQUIRE_EQUAL(timeoutSeqs.size(), 1);
@@ -69,7 +69,7 @@ BOOST_FIXTURE_TEST_CASE(Basic, IoFixture)
BOOST_CHECK_EQUAL(timeoutSeqs[0], 1003);
nFinishSignals++;
}));
});
ping.start();
@@ -93,7 +93,7 @@ BOOST_FIXTURE_TEST_CASE(Basic, IoFixture)
BOOST_CHECK_EQUAL(nFinishSignals, 1);
}
BOOST_AUTO_TEST_SUITE_END() // TestPing
BOOST_AUTO_TEST_SUITE_END() // TestClient
BOOST_AUTO_TEST_SUITE_END() // Ping
} // namespace tests
+8 -8
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2020, Arizona Board of Regents.
* Copyright (c) 2014-2021, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -33,12 +33,12 @@ namespace tests {
using namespace ndn::tests;
BOOST_AUTO_TEST_SUITE(Ping)
BOOST_AUTO_TEST_SUITE(TestPingServer)
BOOST_AUTO_TEST_SUITE(TestServer)
class CreatePingServerFixture : public IoFixture, public KeyChainFixture
class PingServerFixture : public IoFixture, public KeyChainFixture
{
protected:
CreatePingServerFixture()
PingServerFixture()
: face(m_io, m_keyChain, {false, true})
, pingOptions(makeOptions())
, pingServer(face, m_keyChain, pingOptions)
@@ -78,9 +78,9 @@ protected:
PingServer pingServer;
};
BOOST_FIXTURE_TEST_CASE(CreatePingServer, CreatePingServerFixture)
BOOST_FIXTURE_TEST_CASE(Receive, PingServerFixture)
{
BOOST_REQUIRE_EQUAL(0, pingServer.getNPings());
BOOST_TEST(pingServer.getNPings() == 0);
pingServer.start();
advanceClocks(1_ms, 200);
@@ -90,10 +90,10 @@ BOOST_FIXTURE_TEST_CASE(CreatePingServer, CreatePingServerFixture)
m_io.run();
BOOST_CHECK_EQUAL(2, pingServer.getNPings());
BOOST_TEST(pingServer.getNPings() == 2);
}
BOOST_AUTO_TEST_SUITE_END() // TestPingServer
BOOST_AUTO_TEST_SUITE_END() // TestServer
BOOST_AUTO_TEST_SUITE_END() // Ping
} // namespace tests
+1 -1
View File
@@ -46,7 +46,7 @@ Consumer::run(unique_ptr<DiscoverVersion> discover, unique_ptr<PipelineInterests
m_discover->onDiscoverySuccess.connect([this] (const Name& versionedName) {
m_pipeline->run(versionedName,
[this] (const Data& data) { handleData(data); },
FORWARD_TO_MEM_FN(handleData),
[] (const std::string& msg) { NDN_THROW(std::runtime_error(msg)); });
});
m_discover->onDiscoveryFailure.connect([] (const std::string& msg) {
+6 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2019, Regents of the University of California,
* Copyright (c) 2016-2021, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
@@ -85,9 +85,9 @@ DataFetcher::expressInterest(const Interest& interest, const shared_ptr<DataFetc
{
m_nCongestionRetries = 0;
m_pendingInterest = m_face.expressInterest(interest,
bind(&DataFetcher::handleData, this, _1, _2, self),
bind(&DataFetcher::handleNack, this, _1, _2, self),
bind(&DataFetcher::handleTimeout, this, _1, self));
[=] (auto&&... args) { handleData(std::forward<decltype(args)>(args)..., self); },
[=] (auto&&... args) { handleNack(std::forward<decltype(args)>(args)..., self); },
[=] (auto&&... args) { handleTimeout(std::forward<decltype(args)>(args)..., self); });
}
void
@@ -113,7 +113,7 @@ DataFetcher::handleNack(const Interest& interest, const lp::Nack& nack,
if (m_isVerbose)
std::cerr << "Received Nack with reason " << nack.getReason()
<< " for Interest " << interest << std::endl;
<< " for Interest " << interest << "\n";
if (m_nNacks <= m_maxNackRetries || m_maxNackRetries == MAX_RETRIES_INFINITE) {
Interest newInterest(interest);
@@ -162,7 +162,7 @@ DataFetcher::handleTimeout(const Interest& interest, const shared_ptr<DataFetche
++m_nTimeouts;
if (m_isVerbose)
std::cerr << "Timeout for Interest " << interest << std::endl;
std::cerr << "Timeout for Interest " << interest << "\n";
if (m_nTimeouts <= m_maxTimeoutRetries || m_maxTimeoutRetries == MAX_RETRIES_INFINITE) {
Interest newInterest(interest);
+8 -7
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2019, Regents of the University of California,
* Copyright (c) 2016-2021, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
@@ -53,12 +53,13 @@ DiscoverVersion::run()
.setInterestLifetime(m_options.interestLifetime);
m_fetcher = DataFetcher::fetch(m_face, interest,
m_options.maxRetriesOnTimeoutOrNack, m_options.maxRetriesOnTimeoutOrNack,
bind(&DiscoverVersion::handleData, this, _1, _2),
[this] (const Interest&, const std::string& reason) {
m_options.maxRetriesOnTimeoutOrNack,
m_options.maxRetriesOnTimeoutOrNack,
FORWARD_TO_MEM_FN(handleData),
[this] (const auto&, const auto& reason) {
onDiscoveryFailure(reason);
},
[this] (const Interest&, const std::string& reason) {
[this] (const auto&, const auto& reason) {
onDiscoveryFailure(reason);
},
m_options.isVerbose);
@@ -68,7 +69,7 @@ void
DiscoverVersion::handleData(const Interest& interest, const Data& data)
{
if (m_options.isVerbose)
std::cerr << "Data: " << data << std::endl;
std::cerr << "Data: " << data << "\n";
// make a metadata object from received metadata packet
MetadataObject mobject;
@@ -86,7 +87,7 @@ DiscoverVersion::handleData(const Interest& interest, const Data& data)
}
if (m_options.isVerbose) {
std::cerr << "Discovered Data version: " << mobject.getVersionedName()[-1] << std::endl;
std::cerr << "Discovered Data version: " << mobject.getVersionedName()[-1] << "\n";
}
onDiscoverySuccess(mobject.getVersionedName());
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2019, Regents of the University of California,
* Copyright (c) 2016-2021, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
@@ -133,7 +133,7 @@ PipelineInterestsAdaptive::sendInterest(uint64_t segNo, bool isRetransmission)
if (m_options.isVerbose) {
std::cerr << (isRetransmission ? "Retransmitting" : "Requesting")
<< " segment #" << segNo << std::endl;
<< " segment #" << segNo << "\n";
}
if (isRetransmission) {
@@ -150,7 +150,7 @@ PipelineInterestsAdaptive::sendInterest(uint64_t segNo, bool isRetransmission)
if (m_options.isVerbose) {
std::cerr << "# of retries for segment #" << segNo
<< " is " << m_retxCount[segNo] << std::endl;
<< " is " << m_retxCount[segNo] << "\n";
}
}
}
@@ -163,9 +163,9 @@ PipelineInterestsAdaptive::sendInterest(uint64_t segNo, bool isRetransmission)
SegmentInfo& segInfo = m_segmentInfo[segNo];
segInfo.interestHdl = m_face.expressInterest(interest,
bind(&PipelineInterestsAdaptive::handleData, this, _1, _2),
bind(&PipelineInterestsAdaptive::handleNack, this, _1, _2),
bind(&PipelineInterestsAdaptive::handleLifetimeExpiration, this, _1));
FORWARD_TO_MEM_FN(handleData),
FORWARD_TO_MEM_FN(handleNack),
FORWARD_TO_MEM_FN(handleLifetimeExpiration));
segInfo.timeSent = time::steady_clock::now();
segInfo.rto = m_rttEstimator.getEstimatedRto();
@@ -239,7 +239,7 @@ PipelineInterestsAdaptive::handleData(const Interest& interest, const Data& data
if (m_options.isVerbose) {
std::cerr << "Received segment #" << recvSegNo
<< ", rtt=" << rtt.count() / 1e6 << "ms"
<< ", rto=" << segInfo.rto.count() / 1e6 << "ms" << std::endl;
<< ", rto=" << segInfo.rto.count() / 1e6 << "ms\n";
}
if (m_highData < recvSegNo) {
@@ -265,7 +265,7 @@ PipelineInterestsAdaptive::handleData(const Interest& interest, const Data& data
if (m_options.isVerbose) {
std::cerr << "Received congestion mark, value = " << data.getCongestionMark()
<< ", new cwnd = " << m_cwnd << std::endl;
<< ", new cwnd = " << m_cwnd << "\n";
}
}
}
@@ -314,7 +314,7 @@ PipelineInterestsAdaptive::handleNack(const Interest& interest, const lp::Nack&
if (m_options.isVerbose)
std::cerr << "Received Nack with reason " << nack.getReason()
<< " for Interest " << interest << std::endl;
<< " for Interest " << interest << "\n";
uint64_t segNo = getSegmentFromPacket(interest);
@@ -360,7 +360,7 @@ PipelineInterestsAdaptive::recordTimeout()
if (m_options.isVerbose) {
std::cerr << "Packet loss event, new cwnd = " << m_cwnd
<< ", ssthresh = " << m_ssthresh << std::endl;
<< ", ssthresh = " << m_ssthresh << "\n";
}
}
}
@@ -60,7 +60,7 @@ operator<<(std::ostream& os, SegmentState state);
struct SegmentInfo
{
ScopedPendingInterestHandle interestHdl;
time::steady_clock::TimePoint timeSent;
time::steady_clock::time_point timeSent;
time::nanoseconds rto;
SegmentState state;
};
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2019, Regents of the University of California,
* Copyright (c) 2016-2021, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
@@ -52,7 +52,7 @@ private:
private:
double m_wmax = 0.0; ///< window size before last window decrease
double m_lastWmax = 0.0; ///< last wmax
time::steady_clock::TimePoint m_lastDecrease; ///< time of last window decrease
time::steady_clock::time_point m_lastDecrease; ///< time of last window decrease
};
} // namespace chunks
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2019, Regents of the University of California,
* Copyright (c) 2016-2021, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
@@ -79,7 +79,7 @@ PipelineInterestsFixed::fetchNextSegment(std::size_t pipeNo)
// send interest for next segment
if (m_options.isVerbose)
std::cerr << "Requesting segment #" << nextSegmentNo << std::endl;
std::cerr << "Requesting segment #" << nextSegmentNo << "\n";
auto interest = Interest()
.setName(Name(m_prefix).appendSegment(nextSegmentNo))
@@ -90,9 +90,15 @@ PipelineInterestsFixed::fetchNextSegment(std::size_t pipeNo)
auto fetcher = DataFetcher::fetch(m_face, interest,
m_options.maxRetriesOnTimeoutOrNack,
m_options.maxRetriesOnTimeoutOrNack,
bind(&PipelineInterestsFixed::handleData, this, _1, _2, pipeNo),
bind(&PipelineInterestsFixed::handleFail, this, _2, pipeNo),
bind(&PipelineInterestsFixed::handleFail, this, _2, pipeNo),
[=] (const auto& interest, const auto& data) {
handleData(interest, data, pipeNo);
},
[=] (const auto&, const auto& reason) {
handleFail(reason, pipeNo);
},
[=] (const auto&, const auto& reason) {
handleFail(reason, pipeNo);
},
m_options.isVerbose);
BOOST_ASSERT(!m_segmentFetchers[pipeNo].first || !m_segmentFetchers[pipeNo].first->isRunning());
@@ -122,7 +128,7 @@ PipelineInterestsFixed::handleData(const Interest& interest, const Data& data, s
BOOST_ASSERT(data.getName().equals(interest.getName()));
if (m_options.isVerbose)
std::cerr << "Received segment #" << getSegmentFromPacket(data) << std::endl;
std::cerr << "Received segment #" << getSegmentFromPacket(data) << "\n";
onData(data);
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2019, Regents of the University of California,
* Copyright (c) 2016-2021, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
@@ -80,7 +80,7 @@ public:
cancel();
protected:
time::steady_clock::TimePoint
time::steady_clock::time_point
getStartTime() const
{
return m_startTime;
@@ -166,7 +166,7 @@ private:
DataCallback m_onData;
FailureCallback m_onFailure;
uint64_t m_nextSegmentNo;
time::steady_clock::TimePoint m_startTime;
time::steady_clock::time_point m_startTime;
bool m_isStopping;
};
+25 -25
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2016-2019, Regents of the University of California,
* Copyright (c) 2016-2021, Regents of the University of California,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University.
*
@@ -53,24 +53,32 @@ Producer::Producer(const Name& prefix, Face& face, KeyChain& keyChain, std::istr
populateStore(is);
if (m_options.wantShowVersion)
std::cout << m_versionedPrefix[-1] << std::endl;
std::cout << m_versionedPrefix[-1] << "\n";
// register m_prefix without interest handler
m_face.registerPrefix(m_prefix, nullptr, bind(&Producer::onRegisterFailed, this, _1, _2));
m_face.registerPrefix(m_prefix, nullptr, [this] (const Name& prefix, const auto& reason) {
std::cerr << "ERROR: Failed to register prefix '" << prefix << "' (" << reason << ")\n";
m_face.shutdown();
});
// match Interests whose name starts with m_versionedPrefix
face.setInterestFilter(m_versionedPrefix, bind(&Producer::processSegmentInterest, this, _2));
face.setInterestFilter(m_versionedPrefix, [this] (const auto&, const auto& interest) {
processSegmentInterest(interest);
});
// match Interests whose name is exactly m_prefix
face.setInterestFilter(InterestFilter(m_prefix, ""),
bind(&Producer::processSegmentInterest, this, _2));
face.setInterestFilter(InterestFilter(m_prefix, ""), [this] (const auto&, const auto& interest) {
processSegmentInterest(interest);
});
// match discovery Interests
face.setInterestFilter(MetadataObject::makeDiscoveryInterest(m_prefix).getName(),
bind(&Producer::processDiscoveryInterest, this, _2));
auto discoveryName = MetadataObject::makeDiscoveryInterest(m_prefix).getName();
face.setInterestFilter(discoveryName, [this] (const auto&, const auto& interest) {
processDiscoveryInterest(interest);
});
if (!m_options.isQuiet)
std::cerr << "Data published with name: " << m_versionedPrefix << std::endl;
std::cerr << "Data published with name: " << m_versionedPrefix << "\n";
}
void
@@ -83,11 +91,11 @@ void
Producer::processDiscoveryInterest(const Interest& interest)
{
if (m_options.isVerbose)
std::cerr << "Discovery Interest: " << interest << std::endl;
std::cerr << "Discovery Interest: " << interest << "\n";
if (!interest.getCanBePrefix()) {
if (m_options.isVerbose)
std::cerr << "Discovery Interest lacks CanBePrefix, sending Nack" << std::endl;
std::cerr << "Discovery Interest lacks CanBePrefix, sending Nack\n";
m_face.put(lp::Nack(interest));
return;
}
@@ -99,7 +107,7 @@ Producer::processDiscoveryInterest(const Interest& interest)
Data mdata(mobject.makeData(interest.getName(), m_keyChain, m_options.signingInfo));
if (m_options.isVerbose)
std::cerr << "Sending metadata: " << mdata << std::endl;
std::cerr << "Sending metadata: " << mdata << "\n";
m_face.put(mdata);
}
@@ -110,7 +118,7 @@ Producer::processSegmentInterest(const Interest& interest)
BOOST_ASSERT(m_store.size() > 0);
if (m_options.isVerbose)
std::cerr << "Interest: " << interest << std::endl;
std::cerr << "Interest: " << interest << "\n";
const Name& name = interest.getName();
shared_ptr<Data> data;
@@ -129,13 +137,13 @@ Producer::processSegmentInterest(const Interest& interest)
if (data != nullptr) {
if (m_options.isVerbose)
std::cerr << "Data: " << *data << std::endl;
std::cerr << "Data: " << *data << "\n";
m_face.put(*data);
}
else {
if (m_options.isVerbose)
std::cerr << "Interest cannot be satisfied, sending Nack" << std::endl;
std::cerr << "Interest cannot be satisfied, sending Nack\n";
m_face.put(lp::Nack(interest));
}
}
@@ -146,7 +154,7 @@ Producer::populateStore(std::istream& is)
BOOST_ASSERT(m_store.empty());
if (!m_options.isQuiet)
std::cerr << "Loading input ..." << std::endl;
std::cerr << "Loading input ...\n";
std::vector<uint8_t> buffer(m_options.maxSegmentSize);
while (is.good()) {
@@ -174,15 +182,7 @@ Producer::populateStore(std::istream& is)
}
if (!m_options.isQuiet)
std::cerr << "Created " << m_store.size() << " chunks for prefix " << m_prefix << std::endl;
}
void
Producer::onRegisterFailed(const Name& prefix, const std::string& reason)
{
std::cerr << "ERROR: Failed to register prefix '"
<< prefix << "' (" << reason << ")" << std::endl;
m_face.shutdown();
std::cerr << "Created " << m_store.size() << " chunks for prefix " << m_prefix << "\n";
}
} // namespace chunks
-3
View File
@@ -96,9 +96,6 @@ private:
void
processSegmentInterest(const Interest& interest);
void
onRegisterFailed(const Name& prefix, const std::string& reason);
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
std::vector<shared_ptr<Data>> m_store;
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2021, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -113,7 +113,7 @@ private:
const PeekOptions m_options;
Face& m_face;
Scheduler m_scheduler;
time::steady_clock::TimePoint m_sendTime;
time::steady_clock::time_point m_sendTime;
ScopedPendingInterestHandle m_pendingInterest;
scheduler::ScopedEventId m_timeoutEvent;
Result m_result = Result::UNKNOWN;
+15 -19
View File
@@ -47,12 +47,9 @@ public:
, m_signalSetInt(m_face.getIoService(), SIGINT)
, m_signalSetQuit(m_face.getIoService(), SIGQUIT)
{
m_signalSetInt.async_wait(bind(&Runner::afterIntSignal, this, _1));
m_signalSetQuit.async_wait(bind(&Runner::afterQuitSignal, this, _1));
m_ping.afterFinish.connect([this] {
this->cancel();
});
m_signalSetInt.async_wait([this] (const auto& err, int) { onInterruptSignal(err); });
m_signalSetQuit.async_wait([this] (const auto& err, int) { onQuitSignal(err); });
m_ping.afterFinish.connect([this] { cancel(); });
}
int
@@ -68,8 +65,7 @@ public:
}
Statistics statistics = m_statisticsCollector.computeStatistics();
std::cout << statistics << std::endl;
std::cout << statistics << "\n";
if (statistics.nReceived == statistics.nSent) {
return 0;
@@ -89,7 +85,7 @@ private:
}
void
afterIntSignal(const boost::system::error_code& errorCode)
onInterruptSignal(const boost::system::error_code& errorCode)
{
if (errorCode == boost::asio::error::operation_aborted) {
return;
@@ -99,14 +95,14 @@ private:
}
void
afterQuitSignal(const boost::system::error_code& errorCode)
onQuitSignal(const boost::system::error_code& errorCode)
{
if (errorCode == boost::asio::error::operation_aborted) {
return;
}
m_statisticsCollector.computeStatistics().printSummary(std::cout);
m_signalSetQuit.async_wait(bind(&Runner::afterQuitSignal, this, _1));
m_signalSetQuit.async_wait([this] (const auto& err, int) { onQuitSignal(err); });
}
private:
@@ -203,7 +199,7 @@ main(int argc, char* argv[])
}
if (optVm.count("version") > 0) {
std::cout << "ndnping " << tools::VERSION << std::endl;
std::cout << "ndnping " << tools::VERSION << "\n";
exit(0);
}
@@ -211,14 +207,14 @@ main(int argc, char* argv[])
options.prefix = Name(optVm["prefix"].as<std::string>());
}
else {
std::cerr << "ERROR: No prefix specified" << std::endl;
std::cerr << "ERROR: No prefix specified\n";
usage(visibleOptDesc);
}
options.interval = time::milliseconds(optVm["interval"].as<time::milliseconds::rep>());
if (options.interval < getMinimumPingInterval()) {
std::cerr << "ERROR: Specified ping interval is less than the minimum " <<
getMinimumPingInterval() << std::endl;
std::cerr << "ERROR: Specified ping interval is less than the minimum "
<< getMinimumPingInterval() << "\n";
usage(visibleOptDesc);
}
@@ -226,7 +222,7 @@ main(int argc, char* argv[])
if (optVm.count("count") > 0) {
if (options.nPings <= 0) {
std::cerr << "ERROR: Number of ping must be positive" << std::endl;
std::cerr << "ERROR: Number of ping must be positive\n";
usage(visibleOptDesc);
}
}
@@ -238,7 +234,7 @@ main(int argc, char* argv[])
if (optVm.count("identifier") > 0) {
bool isIdentifierAcceptable = std::all_of(identifier.begin(), identifier.end(), &isalnum);
if (identifier.empty() || !isIdentifierAcceptable) {
std::cerr << "ERROR: Unacceptable client identifier" << std::endl;
std::cerr << "ERROR: Unacceptable client identifier\n";
usage(visibleOptDesc);
}
@@ -254,11 +250,11 @@ main(int argc, char* argv[])
}
}
catch (const po::error& e) {
std::cerr << "ERROR: " << e.what() << std::endl;
std::cerr << "ERROR: " << e.what() << "\n";
usage(visibleOptDesc);
}
std::cout << "PING " << options.prefix << std::endl;
std::cout << "PING " << options.prefix << "\n";
return Runner(options).run();
}
+7 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Arizona Board of Regents.
* Copyright (c) 2014-2021, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -22,6 +22,7 @@
*/
#include "ping.hpp"
#include <ndn-cxx/util/random.hpp>
namespace ndn {
@@ -65,9 +66,9 @@ Ping::performPing()
auto now = time::steady_clock::now();
m_face.expressInterest(interest,
bind(&Ping::onData, this, m_nextSeq, now),
bind(&Ping::onNack, this, _2, m_nextSeq, now),
bind(&Ping::onTimeout, this, m_nextSeq));
[=, seq = m_nextSeq] (auto&&...) { onData(seq, now); },
[=, seq = m_nextSeq] (auto&&, const auto& nack) { onNack(seq, now, nack); },
[=, seq = m_nextSeq] (auto&&...) { onTimeout(seq); });
++m_nSent;
++m_nextSeq;
@@ -82,7 +83,7 @@ Ping::performPing()
}
void
Ping::onData(uint64_t seq, const time::steady_clock::TimePoint& sendTime)
Ping::onData(uint64_t seq, const time::steady_clock::time_point& sendTime)
{
time::nanoseconds rtt = time::steady_clock::now() - sendTime;
afterData(seq, rtt);
@@ -90,7 +91,7 @@ Ping::onData(uint64_t seq, const time::steady_clock::TimePoint& sendTime)
}
void
Ping::onNack(const lp::Nack& nack, uint64_t seq, const time::steady_clock::TimePoint& sendTime)
Ping::onNack(uint64_t seq, const time::steady_clock::time_point& sendTime, const lp::Nack& nack)
{
time::nanoseconds rtt = time::steady_clock::now() - sendTime;
afterNack(seq, rtt, nack.getHeader());
+2 -16
View File
@@ -108,8 +108,6 @@ public:
private:
/**
* @brief Creates a ping Name from the sequence number
*
* @param seq ping sequence number
*/
Name
makePingName(uint64_t seq) const;
@@ -122,30 +120,18 @@ private:
/**
* @brief Called when a Data packet is received in response to a ping
*
* @param seq ping sequence number
* @param sendTime time ping sent
*/
void
onData(uint64_t seq, const time::steady_clock::TimePoint& sendTime);
onData(uint64_t seq, const time::steady_clock::time_point& sendTime);
/**
* @brief Called when a Nack is received in response to a ping
*
* @param interest NDN interest
* @param nack returned nack
* @param seq ping sequence number
* @param sendTime time ping sent
*/
void
onNack(const lp::Nack& nack, uint64_t seq,
const time::steady_clock::TimePoint& sendTime);
onNack(uint64_t seq, const time::steady_clock::time_point& sendTime, const lp::Nack& nack);
/**
* @brief Called when ping timed out
*
* @param interest NDN interest
* @param seq ping sequence number
*/
void
onTimeout(uint64_t seq);
+10 -11
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2015-2016, Arizona Board of Regents.
/*
* Copyright (c) 2015-2021, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -16,9 +16,9 @@
* You should have received a copy of the GNU General Public License along with
* ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* @author: Eric Newberry <enewberry@email.arizona.edu>
* @author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
* @author: Teng Liang <philoliang@email.arizona.edu>
* @author Eric Newberry <enewberry@email.arizona.edu>
* @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
* @author Teng Liang <philoliang@email.arizona.edu>
*/
#include "statistics-collector.hpp"
@@ -39,9 +39,9 @@ StatisticsCollector::StatisticsCollector(Ping& ping, const Options& options)
, m_sumRtt(0.0)
, m_sumRttSquared(0.0)
{
m_ping.afterData.connect(bind(&StatisticsCollector::recordData, this, _2));
m_ping.afterNack.connect(bind(&StatisticsCollector::recordNack, this));
m_ping.afterTimeout.connect(bind(&StatisticsCollector::recordTimeout, this));
m_ping.afterData.connect([this] (auto&&, Rtt rtt) { recordData(rtt); });
m_ping.afterNack.connect([this] (auto&&...) { recordNack(); });
m_ping.afterTimeout.connect([this] (auto&&...) { recordTimeout(); });
}
void
@@ -53,7 +53,6 @@ StatisticsCollector::recordData(Rtt rtt)
double rttMs = rtt.count();
m_minRtt = std::min(m_minRtt, rttMs);
m_maxRtt = std::max(m_maxRtt, rttMs);
m_sumRtt += rttMs;
@@ -74,7 +73,7 @@ StatisticsCollector::recordTimeout()
}
Statistics
StatisticsCollector::computeStatistics()
StatisticsCollector::computeStatistics() const
{
Statistics statistics;
@@ -123,7 +122,7 @@ Statistics::printSummary(std::ostream& os) const
<< " ms";
}
return os << std::endl;
return os << "\n";
}
std::ostream&
+9 -11
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2015-2016, Arizona Board of Regents.
/*
* Copyright (c) 2015-2021, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -16,9 +16,9 @@
* You should have received a copy of the GNU General Public License along with
* ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* @author: Eric Newberry <enewberry@email.arizona.edu>
* @author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
* @author: Teng Liang <philoliang@email.arizona.edu>
* @author Eric Newberry <enewberry@email.arizona.edu>
* @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
* @author Teng Liang <philoliang@email.arizona.edu>
*/
#ifndef NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP
@@ -41,7 +41,7 @@ struct Statistics
int nSent; //!< number of pings sent
int nReceived; //!< number of pings received
int nNacked; //!< number of nacks received
time::steady_clock::TimePoint pingStartTime; //!< time pings started
time::steady_clock::time_point pingStartTime; //!< time pings started
double minRtt; //!< minimum round trip time
double maxRtt; //!< maximum round trip time
double packetLossRate; //!< packet loss rate
@@ -67,16 +67,14 @@ public:
StatisticsCollector(Ping& ping, const Options& options);
/**
* @brief Compute ping statistics as structure
* @brief Compute and return ping statistics as structure
*/
Statistics
computeStatistics();
computeStatistics() const;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/**
* @brief Called when a Data packet is received
*
* @param rtt round trip time
*/
void
recordData(Rtt rtt);
@@ -99,7 +97,7 @@ private:
int m_nSent;
int m_nReceived;
int m_nNacked;
time::steady_clock::TimePoint m_pingStartTime;
time::steady_clock::time_point m_pingStartTime;
double m_minRtt;
double m_maxRtt;
double m_sumRtt;
+12 -12
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2015-2016, Arizona Board of Regents.
/*
* Copyright (c) 2015-2021, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -16,8 +16,8 @@
* You should have received a copy of the GNU General Public License along with
* ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* @author: Eric Newberry <enewberry@email.arizona.edu>
* @author: Teng Liang <philoliang@email.arizona.edu>
* @author Eric Newberry <enewberry@email.arizona.edu>
* @author Teng Liang <philoliang@email.arizona.edu>
*/
#include "tracer.hpp"
@@ -29,9 +29,9 @@ namespace client {
Tracer::Tracer(Ping& ping, const Options& options)
: m_options(options)
{
ping.afterData.connect(bind(&Tracer::onData, this, _1, _2));
ping.afterNack.connect(bind(&Tracer::onNack, this, _1, _2, _3));
ping.afterTimeout.connect(bind(&Tracer::onTimeout, this, _1));
ping.afterData.connect(FORWARD_TO_MEM_FN(onData));
ping.afterNack.connect(FORWARD_TO_MEM_FN(onNack));
ping.afterTimeout.connect(FORWARD_TO_MEM_FN(onTimeout));
}
void
@@ -42,7 +42,7 @@ Tracer::onData(uint64_t seq, Rtt rtt)
}
std::cout << "content from " << m_options.prefix << ": seq=" << seq << " time="
<< rtt.count() << " ms" << std::endl;
<< rtt.count() << " ms\n";
}
void
@@ -53,7 +53,7 @@ Tracer::onNack(uint64_t seq, Rtt rtt, const lp::NackHeader& header)
}
std::cout << "nack from " << m_options.prefix << ": seq=" << seq << " time="
<< rtt.count() << " ms" << " reason=" << header.getReason() << std::endl;
<< rtt.count() << " ms" << " reason=" << header.getReason() << "\n";
}
void
@@ -63,13 +63,13 @@ Tracer::onTimeout(uint64_t seq)
std::cout << time::toIsoString(time::system_clock::now()) << " - ";
}
std::cout << "timeout from " << m_options.prefix << ": seq=" << seq << std::endl;
std::cout << "timeout from " << m_options.prefix << ": seq=" << seq << "\n";
}
void
Tracer::onError(std::string msg)
Tracer::onError(const std::string& msg)
{
std::cerr << "ERROR: " << msg << std::endl;
std::cerr << "ERROR: " << msg << "\n";
}
} // namespace client
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2015-2016, Arizona Board of Regents.
/*
* Copyright (c) 2015-2021, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -16,8 +16,8 @@
* You should have received a copy of the GNU General Public License along with
* ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* @author: Eric Newberry <enewberry@email.arizona.edu>
* @author: Teng Liang <philoliang@email.arizona.edu>
* @author Eric Newberry <enewberry@email.arizona.edu>
* @author Teng Liang <philoliang@email.arizona.edu>
*/
#ifndef NDN_TOOLS_PING_CLIENT_TRACER_HPP
@@ -74,7 +74,7 @@ public:
* @brief Outputs ping errors to cerr
*/
void
onError(std::string msg);
onError(const std::string& msg);
private:
const Options& m_options;
+6 -7
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2015-2019, Arizona Board of Regents.
* Copyright (c) 2015-2021, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -42,12 +42,11 @@ PingServer::PingServer(Face& face, KeyChain& keyChain, const Options& options)
void
PingServer::start()
{
m_registeredPrefix = m_face.setInterestFilter(
Name(m_options.prefix).append("ping"),
bind(&PingServer::onInterest, this, _2),
[] (const auto&, const auto& reason) {
NDN_THROW(std::runtime_error("Failed to register prefix: " + reason));
});
m_registeredPrefix = m_face.setInterestFilter(Name(m_options.prefix).append("ping"),
[this] (const auto&, const auto& interest) { onInterest(interest); },
[] (const auto&, const auto& reason) {
NDN_THROW(std::runtime_error("Failed to register prefix: " + reason));
});
}
void
+7 -12
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2015-2018, Arizona Board of Regents.
* Copyright (c) 2015-2021, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -29,20 +29,15 @@ Tracer::Tracer(PingServer& pingServer, const Options& options)
: m_options(options)
{
if (!m_options.wantQuiet) {
pingServer.afterReceive.connect([this] (const Name& name) { onReceive(name); });
pingServer.afterReceive.connect([this] (const Name& name) {
if (m_options.wantTimestamp) {
std::cout << time::toIsoString(time::system_clock::now()) << " - ";
}
std::cout << "interest received: seq=" << name.at(-1) << "\n";
});
}
}
void
Tracer::onReceive(const Name& name)
{
if (m_options.wantTimestamp) {
std::cout << time::toIsoString(time::system_clock::now()) << " - ";
}
std::cout << "interest received: seq=" << name.at(-1) << std::endl;
}
} // namespace server
} // namespace ping
} // namespace ndn
+3 -10
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2015, Arizona Board of Regents.
/*
* Copyright (c) 2015-2021, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -31,20 +31,13 @@ namespace ping {
namespace server {
/**
* @brief logs ping responses
* @brief Logs ping responses
*/
class Tracer : noncopyable
{
public:
Tracer(PingServer& pingServer, const Options& options);
/**
* @brief Prints ping information when interest received
* @param name interest name received
*/
void
onReceive(const Name& name);
private:
const Options& m_options;
};