blob: 7f5ade4e039608e6c78e58e9d461cc7095dff058 [file] [log] [blame]
Eric Newberrya9907782016-11-30 13:37:14 -07001/**
2 * Consumer for the NextHopFaceId test (test_nexthopfaceid)
3 *
4 * Author: Eric Newberry <enewberry@email.arizona.edu>
5 *
6 * Based on ndn-cxx example consumer
7 */
8
Eric Newberry3d5b55d2017-08-31 13:07:06 -07009#include <ndn-cxx/face.hpp>
10#include <ndn-cxx/lp/nack.hpp>
Eric Newberrya9907782016-11-30 13:37:14 -070011#include <ndn-cxx/lp/tags.hpp>
12#include <ndn-cxx/mgmt/nfd/controller.hpp>
13
14#include <cstring>
15#include <cstdlib>
16
17using namespace ndn;
18
19class TestNextHopFaceIdConsumer : noncopyable
20{
21public:
22 void
23 run(Name name, bool enableLocalFields, int nextHopFaceId)
24 {
25 nfd::ControlParameters params;
26 params.setFlagBit(nfd::BIT_LOCAL_FIELDS_ENABLED, enableLocalFields);
27
Eric Newberry3d5b55d2017-08-31 13:07:06 -070028 nfd::Controller controller(m_face, m_keyChain);
29 controller.start<nfd::FaceUpdateCommand>(params,
30 nullptr,
31 [] (const nfd::ControlResponse& resp) {
32 BOOST_THROW_EXCEPTION(
33 std::runtime_error("Unable to toggle local fields"));
34 });
Eric Newberrya9907782016-11-30 13:37:14 -070035 m_face.processEvents();
36
37 // Now, send test case Interest
38 Interest interest(name);
39
40 if (nextHopFaceId != -1) {
41 interest.setTag(make_shared<lp::NextHopFaceIdTag>(nextHopFaceId));
42 }
43
44 m_face.expressInterest(interest,
45 [] (const Interest& interest, const Data& data) {
46 std::cout.write(reinterpret_cast<const char*>(data.getContent().value()),
47 data.getContent().value_size());
48 std::cout << std::endl;
49 },
50 [] (const Interest& interest, const lp::Nack& nack) {
51 std::cout << "Nack" << std::endl;
52 },
53 [] (const Interest& interest) {
54 std::cout << "Timeout" << std::endl;
55 });
56 m_face.processEvents();
57 }
58
59private:
60 Face m_face;
61 KeyChain m_keyChain;
62};
63
64static void
65usage(const char* name)
66{
67 std::cerr << "Usage: " << name
68 << " [prefix] [enableLocalFields - t/f] [NextHopFaceId (-1 if not set)]" << std::endl;
69}
70
71int
72main(int argc, char** argv)
73{
74 if (argc != 4) {
75 usage(argv[0]);
76 return -1;
77 }
78
79 Name name(argv[1]);
80
81 bool enableLocalFields = false;
82 if (std::strcmp(argv[2], "t") == 0) {
83 enableLocalFields = true;
84 }
85 else if (std::strcmp(argv[2], "f") == 0) {
86 enableLocalFields = false;
87 }
88 else {
89 usage(argv[0]);
90 return -1;
91 }
92
93 int nextHopFaceId = std::atoi(argv[3]);
94
95 try {
96 TestNextHopFaceIdConsumer consumer;
97 consumer.run(name, enableLocalFields, nextHopFaceId);
98 }
99 catch (const std::exception& e) {
100 std::cerr << "ERROR: " << e.what() << std::endl;
101 return -2;
102 }
103
104 return 0;
105}