blob: c83d15d28db5b413649c52c22017b4ff30c2f5cc [file] [log] [blame]
/*
* Producer for CongestionMark test (test_congestionmark)
*
* Receives Interests for a specified prefix and returns a Data packet with the same congestion mark
* as the corresponding Interest.
*
* Author: Eric Newberry <enewberry@cs.arizona.edu>
*
* Based on ndn-cxx example producer
*/
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/interest.hpp>
#include <ndn-cxx/interest-filter.hpp>
#include <ndn-cxx/lp/tags.hpp>
#include <ndn-cxx/security/key-chain.hpp>
using namespace ndn;
class TestCongestionMarkProducer
{
public:
void
run(std::string prefix)
{
m_face.setInterestFilter(prefix,
bind(&TestCongestionMarkProducer::onInterest, this, _1, _2),
RegisterPrefixSuccessCallback(),
bind(&TestCongestionMarkProducer::onRegisterFailed, this, _1, _2));
m_face.processEvents();
}
private:
void
onInterest(const InterestFilter& filter, const Interest& i)
{
static const std::string content = "0123456789";
shared_ptr<Data> data = make_shared<Data>();
data->setName(i.getName());
data->setFreshnessPeriod(time::seconds(10));
data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size());
data->setCongestionMark(i.getCongestionMark());
m_keyChain.sign(*data);
m_face.put(*data);
}
void
onRegisterFailed(const Name& prefix, const std::string& reason)
{
std::cerr << "Failed to register prefix " << prefix << " (reason: " + reason + ")" << std::endl;
m_face.shutdown();
}
private:
Face m_face;
KeyChain m_keyChain;
};
int
main(int argc, char** argv)
{
if (argc != 2) {
return 2;
}
try {
TestCongestionMarkProducer producer;
producer.run(argv[1]);
}
catch (const std::exception& e) {
std::cerr << "ERROR: " << e.what() << std::endl;
return 1;
}
return 0;
}