blob: 600133d2a9a080172159097e6ef546e001be63cc [file] [log] [blame]
Eric Newberry608211e2017-11-27 21:59:37 -07001/*
2 * Consumer for CongestionMark test (test_congestionmark)
3 *
4 * Sends an Interest for a specified prefix and prints the returned congestion mark (or whether
5 * there was a Nack or Timeout).
6 *
7 * Author: Eric Newberry <enewberry@cs.arizona.edu>
8 *
9 * Based on ndn-cxx example consumer
10 */
11
12#include <ndn-cxx/data.hpp>
13#include <ndn-cxx/face.hpp>
14#include <ndn-cxx/interest.hpp>
15#include <ndn-cxx/lp/nack.hpp>
16
Eric Newberry8b367fb2018-06-06 22:48:28 -070017#include <iostream>
18
Eric Newberry608211e2017-11-27 21:59:37 -070019using namespace ndn;
20
21class TestCongestionMarkConsumer
22{
23public:
24 void
25 run(Name name)
26 {
27 Interest interest(name);
28
29 m_face.expressInterest(interest,
30 [] (const Interest& interest, const Data& data) {
31 std::cout << "CongestionMark=" << data.getCongestionMark() << std::endl;
32 },
33 [] (const Interest& interest, const lp::Nack& nack) {
34 std::cout << "Nack" << std::endl;
35 },
36 [] (const Interest& interest) {
37 std::cout << "Timeout" << std::endl;
38 });
39 m_face.processEvents();
40 }
41
42private:
43 Face m_face;
44};
45
46int
47main(int argc, char** argv)
48{
49 if (argc != 2) {
50 return 2;
51 }
52
53 try {
54 TestCongestionMarkConsumer consumer;
55 consumer.run(Name(argv[1]));
56 }
57 catch (const std::exception& e) {
58 std::cerr << "ERROR: " << e.what() << std::endl;
59 return 1;
60 }
61
62 return 0;
63}