blob: c83d15d28db5b413649c52c22017b4ff30c2f5cc [file] [log] [blame]
Eric Newberry608211e2017-11-27 21:59:37 -07001/*
2 * Producer for CongestionMark test (test_congestionmark)
3 *
4 * Receives Interests for a specified prefix and returns a Data packet with the same congestion mark
5 * as the corresponding Interest.
6 *
7 * Author: Eric Newberry <enewberry@cs.arizona.edu>
8 *
9 * Based on ndn-cxx example producer
10 */
11
12#include <ndn-cxx/face.hpp>
13#include <ndn-cxx/interest.hpp>
14#include <ndn-cxx/interest-filter.hpp>
15#include <ndn-cxx/lp/tags.hpp>
16#include <ndn-cxx/security/key-chain.hpp>
17
18using namespace ndn;
19
20class TestCongestionMarkProducer
21{
22public:
23 void
24 run(std::string prefix)
25 {
26 m_face.setInterestFilter(prefix,
27 bind(&TestCongestionMarkProducer::onInterest, this, _1, _2),
28 RegisterPrefixSuccessCallback(),
29 bind(&TestCongestionMarkProducer::onRegisterFailed, this, _1, _2));
30 m_face.processEvents();
31 }
32
33private:
34 void
35 onInterest(const InterestFilter& filter, const Interest& i)
36 {
37 static const std::string content = "0123456789";
38 shared_ptr<Data> data = make_shared<Data>();
39 data->setName(i.getName());
40 data->setFreshnessPeriod(time::seconds(10));
41 data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size());
42 data->setCongestionMark(i.getCongestionMark());
43 m_keyChain.sign(*data);
44 m_face.put(*data);
45 }
46
47 void
48 onRegisterFailed(const Name& prefix, const std::string& reason)
49 {
50 std::cerr << "Failed to register prefix " << prefix << " (reason: " + reason + ")" << std::endl;
51 m_face.shutdown();
52 }
53
54private:
55 Face m_face;
56 KeyChain m_keyChain;
57};
58
59int
60main(int argc, char** argv)
61{
62 if (argc != 2) {
63 return 2;
64 }
65
66 try {
67 TestCongestionMarkProducer producer;
68 producer.run(argv[1]);
69 }
70 catch (const std::exception& e) {
71 std::cerr << "ERROR: " << e.what() << std::endl;
72 return 1;
73 }
74
75 return 0;
76}