Added Nack handling to client

refs #1942

Change-Id: If263b7717a266a1b9024ac24ebc5530cfdcf26fa
diff --git a/src/ndn-traffic-client.cpp b/src/ndn-traffic-client.cpp
index ca22e1b..be35d52 100644
--- a/src/ndn-traffic-client.cpp
+++ b/src/ndn-traffic-client.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
 /**
- * Copyright (C) 2014-2015  University of Arizona.
+ * Copyright (C) 2014-2016  The University of Arizona.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -54,6 +54,7 @@
     , m_face(m_ioService)
     , m_nInterestsSent(0)
     , m_nInterestsReceived(0)
+    , m_nNacks(0)
     , m_nContentInconsistencies(0)
     , m_minimumInterestRoundTripTime(std::numeric_limits<double>::max())
     , m_maximumInterestRoundTripTime(0)
@@ -79,6 +80,7 @@
       , m_nextHopFaceId(0)
       , m_nInterestsSent(0)
       , m_nInterestsReceived(0)
+      , m_nNacks(0)
       , m_minimumInterestRoundTripTime(std::numeric_limits<double>::max())
       , m_maximumInterestRoundTripTime(0)
       , m_totalInterestRoundTripTime(0)
@@ -239,6 +241,7 @@
     uint64_t m_nextHopFaceId;
     int m_nInterestsSent;
     int m_nInterestsReceived;
+    int m_nNacks;
 
     //round trip time is stored as milliseconds with fractional
     //sub-millisecond precision
@@ -333,6 +336,8 @@
       to_string(m_nInterestsSent), false, true);
     m_logger.log("Total Responses Received    = " +
       to_string(m_nInterestsReceived), false, true);
+    m_logger.log("Total Nacks Received        = " +
+      to_string(m_nNacks), false, true);
 
     double loss = 0;
     if (m_nInterestsSent > 0)
@@ -364,6 +369,8 @@
           to_string(m_trafficPatterns[patternId].m_nInterestsSent), false, true);
         m_logger.log("Total Responses Received    = " +
           to_string(m_trafficPatterns[patternId].m_nInterestsReceived), false, true);
+        m_logger.log("Total Nacks Received        = " +
+          to_string(m_trafficPatterns[patternId].m_nNacks), false, true);
         loss = 0;
         if (m_trafficPatterns[patternId].m_nInterestsSent > 0)
           {
@@ -527,7 +534,7 @@
 
   void
   onData(const ndn::Interest& interest,
-         ndn::Data& data,
+         const ndn::Data& data,
          int globalReference,
          int localReference,
          int patternId,
@@ -579,6 +586,31 @@
   }
 
   void
+  onNack(const ndn::Interest& interest,
+         const ndn::lp::Nack& nack,
+         int globalReference,
+         int localReference,
+         int patternId)
+  {
+    std::string logLine = "Interest Nack'd    - PatternType=" + to_string(patternId + 1);
+    logLine += ", GlobalID=" + to_string(globalReference);
+    logLine += ", LocalID=" + to_string(localReference);
+    logLine += ", Name=" + interest.getName().toUri();
+    logLine += ", NackReason=" + to_string((int)nack.getReason());
+    m_logger.log(logLine, true, false);
+
+    m_nNacks++;
+    m_trafficPatterns[patternId].m_nNacks++;
+
+    if (m_nMaximumInterests >= 0 && globalReference == m_nMaximumInterests) {
+      logStatistics();
+      m_logger.shutdownLogger();
+      m_face.shutdown();
+      m_ioService.stop();
+    }
+  }
+
+  void
   onTimeout(const ndn::Interest& interest,
             int globalReference,
             int localReference,
@@ -712,6 +744,10 @@
                                               this, _1, _2, m_nInterestsSent,
                                               m_trafficPatterns[patternId].m_nInterestsSent,
                                               patternId, sentTime),
+                                         bind(&NdnTrafficClient::onNack,
+                                              this, _1, _2, m_nInterestsSent,
+                                              m_trafficPatterns[patternId].m_nInterestsSent,
+                                              patternId),
                                          bind(&NdnTrafficClient::onTimeout,
                                               this, _1, m_nInterestsSent,
                                               m_trafficPatterns[patternId].m_nInterestsSent,
@@ -791,6 +827,7 @@
   std::vector<uint32_t> m_nonces;
   int m_nInterestsSent;
   int m_nInterestsReceived;
+  int m_nNacks;
   int m_nContentInconsistencies;
 
   //round trip time is stored as milliseconds with fractional