/*
 * Consumer for CongestionMark test (test_congestionmark)
 *
 * Sends an Interest for a specified prefix and prints the returned congestion mark (or whether
 * there was a Nack or Timeout).
 *
 * Author: Eric Newberry <enewberry@cs.arizona.edu>
 *
 * Based on ndn-cxx example consumer
 */

#include <ndn-cxx/data.hpp>
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/interest.hpp>
#include <ndn-cxx/lp/nack.hpp>

using namespace ndn;

class TestCongestionMarkConsumer
{
public:
  void
  run(Name name)
  {
    Interest interest(name);

    m_face.expressInterest(interest,
                           [] (const Interest& interest, const Data& data) {
                             std::cout << "CongestionMark=" << data.getCongestionMark() << std::endl;
                           },
                           [] (const Interest& interest, const lp::Nack& nack) {
                             std::cout << "Nack" << std::endl;
                           },
                           [] (const Interest& interest) {
                             std::cout << "Timeout" << std::endl;
                           });
    m_face.processEvents();
  }

private:
  Face m_face;
};

int
main(int argc, char** argv)
{
  if (argc != 2) {
    return 2;
  }

  try {
    TestCongestionMarkConsumer consumer;
    consumer.run(Name(argv[1]));
  }
  catch (const std::exception& e) {
    std::cerr << "ERROR: " << e.what() << std::endl;
    return 1;
  }

  return 0;
}
