Eric Newberry | 608211e | 2017-11-27 21:59:37 -0700 | [diff] [blame] | 1 | /* |
| 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 Newberry | 8b367fb | 2018-06-06 22:48:28 -0700 | [diff] [blame^] | 17 | #include <iostream> |
| 18 | |
Eric Newberry | 608211e | 2017-11-27 21:59:37 -0700 | [diff] [blame] | 19 | using namespace ndn; |
| 20 | |
| 21 | class TestCongestionMarkConsumer |
| 22 | { |
| 23 | public: |
| 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 | |
| 42 | private: |
| 43 | Face m_face; |
| 44 | }; |
| 45 | |
| 46 | int |
| 47 | main(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 | } |