pingserver: allow setting payload size
refs #2699
Change-Id: I45181845e196ea390f0b6b39165097df510f9116
diff --git a/tools/ping/server/ndn-ping-server.cpp b/tools/ping/server/ndn-ping-server.cpp
index 998c40d..a642ed1 100644
--- a/tools/ping/server/ndn-ping-server.cpp
+++ b/tools/ping/server/ndn-ping-server.cpp
@@ -86,6 +86,7 @@
options.shouldLimitSatisfied = false;
options.nMaxPings = 0;
options.shouldPrintTimestamp = false;
+ options.payloadSize = 0;
namespace po = boost::program_options;
@@ -98,6 +99,7 @@
std::to_string(getMinimumFreshnessPeriod().count()) + " ms)").c_str())
("satisfy,p", po::value<int>(&options.nMaxPings), "set maximum number of pings to be satisfied")
("timestamp,t", "log timestamp with responses")
+ ("size,s", po::value<int>(&options.payloadSize), "specify size of response payload")
;
po::options_description hiddenOptDesc("Hidden options");
hiddenOptDesc.add_options()
@@ -154,6 +156,13 @@
if (optVm.count("timestamp") > 0) {
options.shouldPrintTimestamp = true;
}
+
+ if (optVm.count("size") > 0) {
+ if (options.payloadSize < 0) {
+ std::cerr << "ERROR: Payload size must be greater than or equal to 0" << std::endl;
+ usage(visibleOptDesc);
+ }
+ }
}
catch (const po::error& e) {
std::cerr << "ERROR: " << e.what() << std::endl;
diff --git a/tools/ping/server/ping-server.cpp b/tools/ping/server/ping-server.cpp
index e75f649..e0d0beb 100644
--- a/tools/ping/server/ping-server.cpp
+++ b/tools/ping/server/ping-server.cpp
@@ -32,6 +32,9 @@
, m_nPings(0)
, m_face(face)
{
+ shared_ptr<Buffer> b = make_shared<Buffer>();
+ b->assign(m_options.payloadSize, 'a');
+ m_payload = Block(tlv::Content, b);
}
void
@@ -60,11 +63,9 @@
afterReceive(interestName);
- char responseContent[] = "NDN TLV Ping Response";
shared_ptr<Data> data = make_shared<Data>(interestName);
data->setFreshnessPeriod(m_options.freshnessPeriod);
- data->setContent(reinterpret_cast<const uint8_t*>(responseContent),
- sizeof(responseContent));
+ data->setContent(m_payload);
m_keyChain.sign(*data);
m_face.put(*data);
diff --git a/tools/ping/server/ping-server.hpp b/tools/ping/server/ping-server.hpp
index ddc3a19..c5e9634 100644
--- a/tools/ping/server/ping-server.hpp
+++ b/tools/ping/server/ping-server.hpp
@@ -39,6 +39,7 @@
bool shouldLimitSatisfied; //!< should limit the number of pings satisfied
int nMaxPings; //!< max number of pings to satisfy
bool shouldPrintTimestamp; //!< print timestamp when response sent
+ int payloadSize; //!< user specified payload size
};
/**
@@ -90,6 +91,7 @@
KeyChain m_keyChain;
int m_nPings;
Face& m_face;
+ Block m_payload;
};
} // namespace server