blob: 9d9232e3737c4a77e660f7925cf8f27f03b98585 [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
Eric Newberry8b367fb2018-06-06 22:48:28 -070018#include <iostream>
19
Eric Newberry608211e2017-11-27 21:59:37 -070020using namespace ndn;
21
22class TestCongestionMarkProducer
23{
24public:
25 void
26 run(std::string prefix)
27 {
28 m_face.setInterestFilter(prefix,
29 bind(&TestCongestionMarkProducer::onInterest, this, _1, _2),
30 RegisterPrefixSuccessCallback(),
31 bind(&TestCongestionMarkProducer::onRegisterFailed, this, _1, _2));
32 m_face.processEvents();
33 }
34
35private:
36 void
37 onInterest(const InterestFilter& filter, const Interest& i)
38 {
39 static const std::string content = "0123456789";
40 shared_ptr<Data> data = make_shared<Data>();
41 data->setName(i.getName());
42 data->setFreshnessPeriod(time::seconds(10));
43 data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size());
44 data->setCongestionMark(i.getCongestionMark());
45 m_keyChain.sign(*data);
46 m_face.put(*data);
47 }
48
49 void
50 onRegisterFailed(const Name& prefix, const std::string& reason)
51 {
52 std::cerr << "Failed to register prefix " << prefix << " (reason: " + reason + ")" << std::endl;
53 m_face.shutdown();
54 }
55
56private:
57 Face m_face;
58 KeyChain m_keyChain;
59};
60
61int
62main(int argc, char** argv)
63{
64 if (argc != 2) {
65 return 2;
66 }
67
68 try {
69 TestCongestionMarkProducer producer;
70 producer.run(argv[1]);
71 }
72 catch (const std::exception& e) {
73 std::cerr << "ERROR: " << e.what() << std::endl;
74 return 1;
75 }
76
77 return 0;
78}