ping+peek: change namespace and class names

refs #2525

Change-Id: I772ad90cdbaee8569be3ed96a5951f3cb89d018c
diff --git a/tools/peek/ndn-peek.cpp b/tools/peek/ndn-peek.cpp
index 5460096..4caba0a 100644
--- a/tools/peek/ndn-peek.cpp
+++ b/tools/peek/ndn-peek.cpp
@@ -31,13 +31,14 @@
 
 #include <ndn-cxx/face.hpp>
 
-namespace ndntlvpeek {
+namespace ndn {
+namespace peek {
 
-class NdnTlvPeek : boost::noncopyable
+class NdnPeek : boost::noncopyable
 {
 public:
   explicit
-  NdnTlvPeek(char* programName)
+  NdnPeek(char* programName)
     : m_programName(programName)
     , m_mustBeFresh(false)
     , m_isChildSelectorRightmost(false)
@@ -87,6 +88,7 @@
   {
     if (minSuffixComponents < 0)
       usage();
+
     m_minSuffixComponents = minSuffixComponents;
   }
 
@@ -95,6 +97,7 @@
   {
     if (maxSuffixComponents < 0)
       usage();
+
     m_maxSuffixComponents = maxSuffixComponents;
   }
 
@@ -103,7 +106,8 @@
   {
     if (interestLifetime < 0)
       usage();
-    m_interestLifetime = ndn::time::milliseconds(interestLifetime);
+
+    m_interestLifetime = time::milliseconds(interestLifetime);
   }
 
   void
@@ -117,87 +121,90 @@
   {
     if (timeout < 0)
       usage();
-    m_timeout = ndn::time::milliseconds(timeout);
+
+    m_timeout = time::milliseconds(timeout);
   }
 
   void
   setPrefixName(char* prefixName)
   {
     m_prefixName = prefixName;
+
     if (m_prefixName.length() == 0)
       usage();
   }
 
-  ndn::time::milliseconds
+  time::milliseconds
   getDefaultInterestLifetime()
   {
-    return ndn::time::seconds(4);
+    return time::seconds(4);
   }
 
-  ndn::Interest
+  Interest
   createInterestPacket()
   {
-    ndn::Name interestName(m_prefixName);
-    ndn::Interest interestPacket(interestName);
+    Name interestName(m_prefixName);
+    Interest interestPacket(interestName);
+
     if (m_mustBeFresh)
       interestPacket.setMustBeFresh(true);
+
     if (m_isChildSelectorRightmost)
       interestPacket.setChildSelector(1);
+
     if (m_minSuffixComponents >= 0)
       interestPacket.setMinSuffixComponents(m_minSuffixComponents);
+
     if (m_maxSuffixComponents >= 0)
       interestPacket.setMaxSuffixComponents(m_maxSuffixComponents);
-    if (m_interestLifetime < ndn::time::milliseconds::zero())
+
+    if (m_interestLifetime < time::milliseconds::zero())
       interestPacket.setInterestLifetime(getDefaultInterestLifetime());
     else
       interestPacket.setInterestLifetime(m_interestLifetime);
+
     return interestPacket;
   }
 
   void
-  onData(const ndn::Interest& interest, ndn::Data& data)
+  onData(const Interest& interest, Data& data)
   {
     m_isDataReceived = true;
-    if (m_isPayloadOnlySet)
-      {
-        const ndn::Block& block = data.getContent();
-        std::cout.write(reinterpret_cast<const char*>(block.value()), block.value_size());
-      }
-    else
-      {
-        const ndn::Block& block = data.wireEncode();
-        std::cout.write(reinterpret_cast<const char*>(block.wire()), block.size());
-      }
+    if (m_isPayloadOnlySet) {
+      const Block& block = data.getContent();
+      std::cout.write(reinterpret_cast<const char*>(block.value()), block.value_size());
+    }
+    else {
+      const Block& block = data.wireEncode();
+      std::cout.write(reinterpret_cast<const char*>(block.wire()), block.size());
+    }
   }
 
   void
-  onTimeout(const ndn::Interest& interest)
+  onTimeout(const Interest& interest)
   {
   }
 
   void
   run()
   {
-    try
-      {
-        m_face.expressInterest(createInterestPacket(),
-                               bind(&NdnTlvPeek::onData, this, _1, _2),
-                               bind(&NdnTlvPeek::onTimeout, this, _1));
-        if (m_timeout < ndn::time::milliseconds::zero())
-          {
-            if (m_interestLifetime < ndn::time::milliseconds::zero())
-              m_face.processEvents(getDefaultInterestLifetime());
-            else
-              m_face.processEvents(m_interestLifetime);
-          }
+    try {
+      m_face.expressInterest(createInterestPacket(),
+                             bind(&NdnPeek::onData, this, _1, _2),
+                             bind(&NdnPeek::onTimeout, this, _1));
+      if (m_timeout < time::milliseconds::zero()) {
+        if (m_interestLifetime < time::milliseconds::zero())
+          m_face.processEvents(getDefaultInterestLifetime());
         else
-          m_face.processEvents(m_timeout);
+          m_face.processEvents(m_interestLifetime);
       }
-    catch (std::exception& e)
-      {
-        std::cerr << "ERROR: " << e.what() << "\n" << std::endl;
-        exit(1);
-      }
+      else
+        m_face.processEvents(m_timeout);
+    }
+    catch (std::exception& e) {
+      std::cerr << "ERROR: " << e.what() << "\n" << std::endl;
+      exit(1);
+    }
   }
 
   bool
@@ -207,58 +214,55 @@
   }
 
 private:
-
   std::string m_programName;
   bool m_mustBeFresh;
   bool m_isChildSelectorRightmost;
   int m_minSuffixComponents;
   int m_maxSuffixComponents;
-  ndn::time::milliseconds m_interestLifetime;
+  time::milliseconds m_interestLifetime;
   bool m_isPayloadOnlySet;
-  ndn::time::milliseconds m_timeout;
+  time::milliseconds m_timeout;
   std::string m_prefixName;
   bool m_isDataReceived;
-  ndn::Face m_face;
+  Face m_face;
 };
 
-}
-
 int
 main(int argc, char* argv[])
 {
-  ndntlvpeek::NdnTlvPeek ndnTlvPeek(argv[0]);
+  NdnPeek program(argv[0]);
   int option;
   while ((option = getopt(argc, argv, "hfrm:M:l:pw:V")) != -1) {
     switch (option) {
     case 'h':
-      ndnTlvPeek.usage();
+      program.usage();
       break;
     case 'f':
-      ndnTlvPeek.setMustBeFresh();
+      program.setMustBeFresh();
       break;
     case 'r':
-      ndnTlvPeek.setRightmostChildSelector();
+      program.setRightmostChildSelector();
       break;
     case 'm':
-      ndnTlvPeek.setMinSuffixComponents(atoi(optarg));
+      program.setMinSuffixComponents(atoi(optarg));
       break;
     case 'M':
-      ndnTlvPeek.setMaxSuffixComponents(atoi(optarg));
+      program.setMaxSuffixComponents(atoi(optarg));
       break;
     case 'l':
-      ndnTlvPeek.setInterestLifetime(atoi(optarg));
+      program.setInterestLifetime(atoi(optarg));
       break;
     case 'p':
-      ndnTlvPeek.setPayloadOnly();
+      program.setPayloadOnly();
       break;
     case 'w':
-      ndnTlvPeek.setTimeout(atoi(optarg));
+      program.setTimeout(atoi(optarg));
       break;
     case 'V':
       std::cout << NFD_VERSION_BUILD_STRING << std::endl;
       return 0;
     default:
-      ndnTlvPeek.usage();
+      program.usage();
       break;
     }
   }
@@ -267,13 +271,22 @@
   argv += optind;
 
   if (argv[0] == 0)
-    ndnTlvPeek.usage();
+    program.usage();
 
-  ndnTlvPeek.setPrefixName(argv[0]);
-  ndnTlvPeek.run();
+  program.setPrefixName(argv[0]);
+  program.run();
 
-  if (ndnTlvPeek.isDataReceived())
+  if (program.isDataReceived())
     return 0;
   else
     return 1;
 }
+
+} // namespace peek
+} // namespace ndn
+
+int
+main(int argc, char** argv)
+{
+  return ndn::peek::main(argc, argv);
+}
diff --git a/tools/peek/ndn-poke.cpp b/tools/peek/ndn-poke.cpp
index 45db702..a4a635d 100644
--- a/tools/peek/ndn-poke.cpp
+++ b/tools/peek/ndn-poke.cpp
@@ -32,13 +32,14 @@
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
 
-namespace ndntlvpoke {
+namespace ndn {
+namespace peek {
 
-class NdnTlvPoke : boost::noncopyable
+class NdnPoke : boost::noncopyable
 {
 public:
   explicit
-  NdnTlvPoke(char* programName)
+  NdnPoke(char* programName)
     : m_programName(programName)
     , m_isForceDataSet(false)
     , m_isUseDigestSha256Set(false)
@@ -84,7 +85,7 @@
   void
   setIdentityName(char* identityName)
   {
-    m_identityName = ndn::make_shared<ndn::Name>(identityName);
+    m_identityName = make_shared<Name>(identityName);
   }
 
   void
@@ -98,7 +99,8 @@
   {
     if (freshnessPeriod < 0)
       usage();
-    m_freshnessPeriod = ndn::time::milliseconds(freshnessPeriod);
+
+    m_freshnessPeriod = time::milliseconds(freshnessPeriod);
   }
 
   void
@@ -106,57 +108,60 @@
   {
     if (timeout < 0)
       usage();
-    m_timeout = ndn::time::milliseconds(timeout);
+
+    m_timeout = time::milliseconds(timeout);
   }
 
   void
   setPrefixName(char* prefixName)
   {
-    m_prefixName = ndn::Name(prefixName);
+    m_prefixName = Name(prefixName);
   }
 
-  ndn::time::milliseconds
+  time::milliseconds
   getDefaultTimeout()
   {
-    return ndn::time::seconds(10);
+    return time::seconds(10);
   }
 
-  ndn::Data
+  Data
   createDataPacket()
   {
-    ndn::Data dataPacket(m_prefixName);
+    Data dataPacket(m_prefixName);
+
     std::stringstream payloadStream;
     payloadStream << std::cin.rdbuf();
     std::string payload = payloadStream.str();
     dataPacket.setContent(reinterpret_cast<const uint8_t*>(payload.c_str()), payload.length());
-    if (m_freshnessPeriod >= ndn::time::milliseconds::zero())
+
+    if (m_freshnessPeriod >= time::milliseconds::zero())
       dataPacket.setFreshnessPeriod(m_freshnessPeriod);
-    if (m_isLastAsFinalBlockIdSet)
-      {
-        if (!m_prefixName.empty())
-          dataPacket.setFinalBlockId(m_prefixName.get(-1));
-        else
-          {
-            std::cerr << "Name Provided Has 0 Components" << std::endl;
-            exit(1);
-          }
+
+    if (m_isLastAsFinalBlockIdSet) {
+      if (!m_prefixName.empty())
+        dataPacket.setFinalBlockId(m_prefixName.get(-1));
+      else {
+        std::cerr << "Name Provided Has 0 Components" << std::endl;
+        exit(1);
       }
+    }
+
     if (m_isUseDigestSha256Set)
       m_keyChain.signWithSha256(dataPacket);
-    else
-      {
-        if (!static_cast<bool>(m_identityName))
-          m_keyChain.sign(dataPacket);
-        else
-          m_keyChain.signByIdentity(dataPacket, *m_identityName);
-      }
+    else {
+      if (m_identityName == nullptr)
+        m_keyChain.sign(dataPacket);
+      else
+        m_keyChain.signByIdentity(dataPacket, *m_identityName);
+    }
+
     return dataPacket;
   }
 
   void
-  onInterest(const ndn::Name& name,
-             const ndn::Interest& interest,
-             const ndn::Data& dataPacket)
+  onInterest(const Name& name,
+             const Interest& interest,
+             const Data& dataPacket)
   {
     m_face.put(dataPacket);
     m_isDataSent = true;
@@ -164,7 +169,7 @@
   }
 
   void
-  onRegisterFailed(const ndn::Name& prefix, const std::string& reason)
+  onRegisterFailed(const Name& prefix, const std::string& reason)
   {
     std::cerr << "Prefix Registration Failure." << std::endl;
     std::cerr << "Reason = " << reason << std::endl;
@@ -173,31 +178,28 @@
   void
   run()
   {
-    try
-      {
-        ndn::Data dataPacket = createDataPacket();
-        if (m_isForceDataSet)
-          {
-            m_face.put(dataPacket);
-            m_isDataSent = true;
-          }
-        else
-          {
-            m_face.setInterestFilter(m_prefixName,
-                                     bind(&NdnTlvPoke::onInterest, this, _1, _2, dataPacket),
-                                     ndn::RegisterPrefixSuccessCallback(),
-                                     bind(&NdnTlvPoke::onRegisterFailed, this, _1, _2));
-          }
-        if (m_timeout < ndn::time::milliseconds::zero())
-          m_face.processEvents(getDefaultTimeout());
-        else
-          m_face.processEvents(m_timeout);
+    try {
+      Data dataPacket = createDataPacket();
+      if (m_isForceDataSet) {
+        m_face.put(dataPacket);
+        m_isDataSent = true;
       }
-    catch (std::exception& e)
-      {
-        std::cerr << "ERROR: " << e.what() << "\n" << std::endl;
-        exit(1);
+      else {
+        m_face.setInterestFilter(m_prefixName,
+                                 bind(&NdnPoke::onInterest, this, _1, _2, dataPacket),
+                                 RegisterPrefixSuccessCallback(),
+                                 bind(&NdnPoke::onRegisterFailed, this, _1, _2));
       }
+
+      if (m_timeout < time::milliseconds::zero())
+        m_face.processEvents(getDefaultTimeout());
+      else
+        m_face.processEvents(m_timeout);
+    }
+    catch (std::exception& e) {
+      std::cerr << "ERROR: " << e.what() << "\n" << std::endl;
+      exit(1);
+    }
   }
 
   bool
@@ -207,56 +209,52 @@
   }
 
 private:
-
-  ndn::KeyChain m_keyChain;
+  KeyChain m_keyChain;
   std::string m_programName;
   bool m_isForceDataSet;
   bool m_isUseDigestSha256Set;
-  ndn::shared_ptr<ndn::Name> m_identityName;
+  shared_ptr<Name> m_identityName;
   bool m_isLastAsFinalBlockIdSet;
-  ndn::time::milliseconds m_freshnessPeriod;
-  ndn::time::milliseconds m_timeout;
-  ndn::Name m_prefixName;
+  time::milliseconds m_freshnessPeriod;
+  time::milliseconds m_timeout;
+  Name m_prefixName;
   bool m_isDataSent;
-  ndn::Face m_face;
-
+  Face m_face;
 };
 
-}
-
 int
 main(int argc, char* argv[])
 {
   int option;
-  ndntlvpoke::NdnTlvPoke ndnTlvPoke(argv[0]);
+  NdnPoke program(argv[0]);
   while ((option = getopt(argc, argv, "hfDi:Fx:w:V")) != -1) {
     switch (option) {
     case 'h':
-      ndnTlvPoke.usage();
+      program.usage();
       break;
     case 'f':
-      ndnTlvPoke.setForceData();
+      program.setForceData();
       break;
     case 'D':
-      ndnTlvPoke.setUseDigestSha256();
+      program.setUseDigestSha256();
       break;
     case 'i':
-      ndnTlvPoke.setIdentityName(optarg);
+      program.setIdentityName(optarg);
       break;
     case 'F':
-      ndnTlvPoke.setLastAsFinalBlockId();
+      program.setLastAsFinalBlockId();
       break;
     case 'x':
-      ndnTlvPoke.setFreshnessPeriod(atoi(optarg));
+      program.setFreshnessPeriod(atoi(optarg));
       break;
     case 'w':
-      ndnTlvPoke.setTimeout(atoi(optarg));
+      program.setTimeout(atoi(optarg));
       break;
     case 'V':
       std::cout << NFD_VERSION_BUILD_STRING << std::endl;
       return 0;
     default:
-      ndnTlvPoke.usage();
+      program.usage();
       break;
     }
   }
@@ -265,13 +263,22 @@
   argv += optind;
 
   if (argv[0] == 0)
-    ndnTlvPoke.usage();
+    program.usage();
 
-  ndnTlvPoke.setPrefixName(argv[0]);
-  ndnTlvPoke.run();
+  program.setPrefixName(argv[0]);
+  program.run();
 
-  if (ndnTlvPoke.isDataSent())
+  if (program.isDataSent())
     return 0;
   else
     return 1;
 }
+
+} // namespace peek
+} // namespace ndn
+
+int
+main(int argc, char** argv)
+{
+  return ndn::peek::main(argc, argv);
+}
diff --git a/tools/ping/ndn-ping-server.cpp b/tools/ping/ndn-ping-server.cpp
index dfe6538..684891c 100644
--- a/tools/ping/ndn-ping-server.cpp
+++ b/tools/ping/ndn-ping-server.cpp
@@ -26,13 +26,13 @@
 #include <boost/noncopyable.hpp>
 
 namespace ndn {
+namespace ping {
 
-class NdnTlvPingServer : boost::noncopyable
+class NdnPingServer : boost::noncopyable
 {
 public:
-
   explicit
-  NdnTlvPingServer(char* programName)
+  NdnPingServer(char* programName)
     : m_programName(programName)
     , m_hasError(false)
     , m_isPrintTimestampSet(false)
@@ -66,6 +66,7 @@
   setFreshnessPeriod(int freshnessPeriod)
   {
     if (freshnessPeriod <= 0)
+      usage();
 
     m_freshnessPeriod = time::milliseconds(freshnessPeriod);
   }
@@ -75,6 +76,7 @@
   {
     if (maximumPings <= 0)
       usage();
+
     m_maximumPings = maximumPings;
   }
 
@@ -100,10 +102,12 @@
   onInterest(const Name& name, const Interest& interest)
   {
     Name interestName = interest.getName();
+
     if (m_isPrintTimestampSet)
       std::cout << time::toIsoString(time::system_clock::now())  << " - ";
     std::cout << "Interest Received - Ping Reference = "
               << interestName.at(-1).toUri() << std::endl;
+
     char responseContent[] = "NDN TLV Ping Response";
     shared_ptr<Data> data = make_shared<Data>(interestName);
     data->setFreshnessPeriod(m_freshnessPeriod);
@@ -111,6 +115,7 @@
                      sizeof(responseContent));
     m_keyChain.sign(*data);
     m_face.put(*data);
+
     ++m_totalPings;
     if (m_maximumPings > 0 && m_maximumPings == m_totalPings) {
       std::cout << "\n\nTotal Ping Interests Processed = " << m_totalPings << std::endl;
@@ -146,13 +151,15 @@
 
     boost::asio::signal_set signalSet(m_ioService, SIGINT, SIGTERM);
     signalSet.async_wait(bind([this]() { signalHandler(); }));
+
     m_name = m_prefix;
     m_name.append("ping");
     m_face.setInterestFilter(m_name,
-                             bind(&NdnTlvPingServer::onInterest,
+                             bind(&NdnPingServer::onInterest,
                                   this, _1, _2),
-                             bind(&NdnTlvPingServer::onRegisterFailed,
+                             bind(&NdnPingServer::onRegisterFailed,
                                   this, _1,_2));
+
     try {
       m_face.processEvents();
     }
@@ -179,31 +186,29 @@
   Face m_face;
 };
 
-}
-
 int
 main(int argc, char* argv[])
 {
   int res;
 
-  ndn::NdnTlvPingServer ndnTlvPingServer(argv[0]);
+  NdnPingServer program(argv[0]);
   while ((res = getopt(argc, argv, "hdtp:x:")) != -1)
     {
       switch (res) {
       case 'h':
-        ndnTlvPingServer.usage();
+        program.usage();
         break;
       case 'p':
-        ndnTlvPingServer.setMaximumPings(atoi(optarg));
+        program.setMaximumPings(atoi(optarg));
         break;
       case 'x':
-        ndnTlvPingServer.setFreshnessPeriod(atoi(optarg));
+        program.setFreshnessPeriod(atoi(optarg));
         break;
       case 't':
-        ndnTlvPingServer.setPrintTimestamp();
+        program.setPrintTimestamp();
         break;
       default:
-        ndnTlvPingServer.usage();
+        program.usage();
         break;
       }
     }
@@ -212,15 +217,24 @@
   argv += optind;
 
   if (argv[0] == 0)
-    ndnTlvPingServer.usage();
+    program.usage();
 
-  ndnTlvPingServer.setPrefix(argv[0]);
-  ndnTlvPingServer.run();
+  program.setPrefix(argv[0]);
+  program.run();
 
   std::cout << std::endl;
 
-  if (ndnTlvPingServer.hasError())
+  if (program.hasError())
     return 1;
   else
     return 0;
 }
+
+} // namespace ping
+} // namespace ndn
+
+int
+main(int argc, char** argv)
+{
+  return ndn::ping::main(argc, argv);
+}
diff --git a/tools/ping/ndn-ping.cpp b/tools/ping/ndn-ping.cpp
index 3479e73..4abfcec 100644
--- a/tools/ping/ndn-ping.cpp
+++ b/tools/ping/ndn-ping.cpp
@@ -27,13 +27,13 @@
 #include <boost/noncopyable.hpp>
 
 namespace ndn {
+namespace ping {
 
-class NdnTlvPing : boost::noncopyable
+class NdnPing : boost::noncopyable
 {
 public:
-
   explicit
-  NdnTlvPing(char* programName)
+  NdnPing(char* programName)
     : m_programName(programName)
     , m_isAllowCachingSet(false)
     , m_isPrintTimestampSet(false)
@@ -53,7 +53,6 @@
   class PingStatistics : boost::noncopyable
   {
   public:
-
     explicit
     PingStatistics()
       : m_sentPings(0)
@@ -73,10 +72,12 @@
         m_minimumRoundTripTime = roundTripTime;
       if (roundTripTime > m_maximumRoundTripTime)
         m_maximumRoundTripTime = roundTripTime;
+
       m_averageRoundTripTimeData += roundTripTime;
-      m_standardDeviationRoundTripTimeData += roundTripTime*roundTripTime;
+      m_standardDeviationRoundTripTimeData += roundTripTime * roundTripTime;
     }
 
+  public:
     int m_sentPings;
     int m_receivedPings;
     time::steady_clock::TimePoint m_pingStartTime;
@@ -124,6 +125,7 @@
   {
     if (totalPings <= 0)
       usage();
+
     m_totalPings = totalPings;
   }
 
@@ -132,6 +134,7 @@
   {
     if (pingInterval < getPingMinimumInterval().count())
       usage();
+
     m_pingInterval = time::milliseconds(pingInterval);
   }
 
@@ -140,6 +143,7 @@
   {
     if (startPingNumber < 0)
       usage();
+
     m_startPingNumber = startPingNumber;
   }
 
@@ -159,10 +163,12 @@
   setClientIdentifier(char* clientIdentifier)
   {
     m_clientIdentifier = clientIdentifier;
+
     if (strlen(clientIdentifier) == 0)
       usage();
+
     while (*clientIdentifier != '\0') {
-      if( isalnum(*clientIdentifier) == 0 )
+      if (isalnum(*clientIdentifier) == 0)
         usage();
       clientIdentifier++;
     }
@@ -186,12 +192,11 @@
          Data& data,
          time::steady_clock::TimePoint timePoint)
   {
-    std::string pingReference;
-    time::nanoseconds roundTripTime;
-    pingReference = interest.getName().toUri();
+    std::string pingReference = interest.getName().toUri();
     m_pingsReceived++;
     m_pingStatistics.m_receivedPings++;
-    roundTripTime = time::steady_clock::now() - timePoint;
+    time::nanoseconds roundTripTime = time::steady_clock::now() - timePoint;
+
     if (m_isPrintTimestampSet)
       std::cout << time::toIsoString(time::system_clock::now())  << " - ";
     std::cout << "Content From " << m_prefix;
@@ -199,6 +204,7 @@
       interest.getName().getSubName(interest.getName().size()-1).toUri().substr(1);
     std::cout << "  \t- Round Trip Time = " <<
       roundTripTime.count() / 1000000.0 << " ms" << std::endl;
+
     m_pingStatistics.addToPingStatistics(roundTripTime);
     this->finish();
   }
@@ -212,6 +218,7 @@
     std::cout << " - Ping Reference = " <<
       interest.getName().getSubName(interest.getName().size()-1).toUri().substr(1);
     std::cout << std::endl;
+
     this->finish();
   }
 
@@ -246,45 +253,49 @@
   void
   performPing(boost::asio::deadline_timer* deadlineTimer)
   {
-    if ((m_totalPings < 0) || (m_pingsSent < m_totalPings))
-      {
-        m_pingsSent++;
-        m_pingStatistics.m_sentPings++;
+    if ((m_totalPings < 0) || (m_pingsSent < m_totalPings)) {
+      m_pingsSent++;
+      m_pingStatistics.m_sentPings++;
 
-        //Perform Ping
-        char pingNumberString[20];
-        Name pingPacketName(m_prefix);
-        pingPacketName.append("ping");
-        if(m_clientIdentifier != 0)
-          pingPacketName.append(m_clientIdentifier);
-        std::memset(pingNumberString, 0, 20);
-        if (m_startPingNumber < 0)
-            m_startPingNumber = std::rand();
-        sprintf(pingNumberString, "%lld", static_cast<long long int>(m_startPingNumber));
-        pingPacketName.append(pingNumberString);
-        ndn::Interest interest(pingPacketName);
-        if (m_isAllowCachingSet)
-          interest.setMustBeFresh(false);
-        else
-          interest.setMustBeFresh(true);
-        interest.setInterestLifetime(m_pingTimeoutThreshold);
-        interest.setNonce(m_startPingNumber);
-        m_startPingNumber++;
-         try {
-          m_face.expressInterest(interest,
-                                 std::bind(&NdnTlvPing::onData, this, _1, _2,
-                                           time::steady_clock::now()),
-                                 std::bind(&NdnTlvPing::onTimeout, this, _1));
-          deadlineTimer->expires_at(deadlineTimer->expires_at() +
-                                    boost::posix_time::millisec(m_pingInterval.count()));
-          deadlineTimer->async_wait(bind(&NdnTlvPing::performPing,
-                                         this,
-                                         deadlineTimer));
-        }
-        catch (std::exception& e) {
-            std::cerr << "ERROR: " << e.what() << std::endl;
-        }
-        ++m_outstanding;
+      //Perform Ping
+      char pingNumberString[20];
+      Name pingPacketName(m_prefix);
+      pingPacketName.append("ping");
+      if (m_clientIdentifier != 0)
+        pingPacketName.append(m_clientIdentifier);
+      std::memset(pingNumberString, 0, 20);
+      if (m_startPingNumber < 0)
+        m_startPingNumber = std::rand();
+      sprintf(pingNumberString, "%lld", static_cast<long long int>(m_startPingNumber));
+      pingPacketName.append(pingNumberString);
+
+      ndn::Interest interest(pingPacketName);
+
+      if (m_isAllowCachingSet)
+        interest.setMustBeFresh(false);
+      else
+        interest.setMustBeFresh(true);
+
+      interest.setInterestLifetime(m_pingTimeoutThreshold);
+      interest.setNonce(m_startPingNumber);
+
+      m_startPingNumber++;
+ 
+      try {
+        m_face.expressInterest(interest,
+                               std::bind(&NdnPing::onData, this, _1, _2,
+                                         time::steady_clock::now()),
+                               std::bind(&NdnPing::onTimeout, this, _1));
+        deadlineTimer->expires_at(deadlineTimer->expires_at() +
+                                  boost::posix_time::millisec(m_pingInterval.count()));
+        deadlineTimer->async_wait(bind(&NdnPing::performPing,
+                                       this,
+                                       deadlineTimer));
+      }
+      catch (std::exception& e) {
+        std::cerr << "ERROR: " << e.what() << std::endl;
+      }
+      ++m_outstanding;
     }
     else {
       this->finish();
@@ -316,12 +327,12 @@
     std::cout << "\n=== Pinging " << m_prefix  << " ===\n" <<std::endl;
 
     boost::asio::signal_set signalSet(m_ioService, SIGINT, SIGTERM);
-    signalSet.async_wait(bind(&NdnTlvPing::signalHandler, this));
+    signalSet.async_wait(bind(&NdnPing::signalHandler, this));
 
     boost::asio::deadline_timer deadlineTimer(m_ioService,
                                               boost::posix_time::millisec(0));
 
-    deadlineTimer.async_wait(bind(&NdnTlvPing::performPing,
+    deadlineTimer.async_wait(bind(&NdnPing::performPing,
                                   this,
                                   &deadlineTimer));
     try {
@@ -354,47 +365,44 @@
   Face m_face;
 };
 
-}
-
-
 int
 main(int argc, char* argv[])
 {
   std::srand(::time(0));
   int res;
 
-  ndn::NdnTlvPing ndnTlvPing(argv[0]);
+  NdnPing program(argv[0]);
   while ((res = getopt(argc, argv, "htai:c:n:p:")) != -1)
     {
       switch (res) {
       case 'a':
-        ndnTlvPing.setAllowCaching();
+        program.setAllowCaching();
         break;
       case 'c':
-        ndnTlvPing.setTotalPings(atoi(optarg));
+        program.setTotalPings(atoi(optarg));
         break;
       case 'h':
-        ndnTlvPing.usage();
+        program.usage();
         break;
       case 'i':
-        ndnTlvPing.setPingInterval(atoi(optarg));
+        program.setPingInterval(atoi(optarg));
         break;
       case 'n':
         try {
-          ndnTlvPing.setStartPingNumber(boost::lexical_cast<int64_t>(optarg));
+          program.setStartPingNumber(boost::lexical_cast<int64_t>(optarg));
         }
         catch (boost::bad_lexical_cast&) {
-          ndnTlvPing.usage();
+          program.usage();
         }
         break;
       case 'p':
-        ndnTlvPing.setClientIdentifier(optarg);
+        program.setClientIdentifier(optarg);
         break;
       case 't':
-        ndnTlvPing.setPrintTimestamp();
+        program.setPrintTimestamp();
         break;
       default:
-        ndnTlvPing.usage();
+        program.usage();
         break;
       }
     }
@@ -403,15 +411,24 @@
   argv += optind;
 
   if (argv[0] == 0)
-    ndnTlvPing.usage();
+    program.usage();
 
-  ndnTlvPing.setPrefix(argv[0]);
-  ndnTlvPing.run();
+  program.setPrefix(argv[0]);
+  program.run();
 
   std::cout << std::endl;
 
-  if (ndnTlvPing.hasError())
+  if (program.hasError())
     return 1;
   else
     return 0;
 }
+
+} // namespace ping
+} // namespace ndn
+
+int
+main(int argc, char** argv)
+{
+  return ndn::ping::main(argc, argv);
+}