22 #include "ns3/string.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/packet.h"
25 #include "ns3/simulator.h"
34 NS_LOG_COMPONENT_DEFINE(
"ndn.Producer");
45 TypeId(
"ns3::ndn::Producer")
48 .AddConstructor<Producer>()
49 .AddAttribute(
"Prefix",
"Prefix, for which producer has the data", StringValue(
"/"),
53 "Postfix that is added to the output data (e.g., for adding producer-uniqueness)",
55 .AddAttribute(
"PayloadSize",
"Virtual payload size for Content packets", UintegerValue(1024),
56 MakeUintegerAccessor(&Producer::m_virtualPayloadSize),
57 MakeUintegerChecker<uint32_t>())
58 .AddAttribute(
"Freshness",
"Freshness of data packets, if 0, then unlimited freshness",
59 TimeValue(Seconds(0)), MakeTimeAccessor(&Producer::m_freshness),
63 "Fake signature, 0 valid signature (default), other values application-specific",
64 UintegerValue(0), MakeUintegerAccessor(&Producer::m_signature),
65 MakeUintegerChecker<uint32_t>())
66 .AddAttribute(
"KeyLocator",
67 "Name to be used for key locator. If root, then key locator is not used",
74 NS_LOG_FUNCTION_NOARGS();
81 NS_LOG_FUNCTION_NOARGS();
90 NS_LOG_FUNCTION_NOARGS();
100 NS_LOG_FUNCTION(
this << interest);
105 Name dataName(interest->getName());
109 auto data = make_shared<Data>();
110 data->setName(dataName);
111 data->setFreshnessPeriod(::ndn::time::milliseconds(m_freshness.GetMilliSeconds()));
113 data->setContent(make_shared< ::ndn::Buffer>(m_virtualPayloadSize));
116 SignatureInfo signatureInfo(static_cast< ::ndn::tlv::SignatureTypeValue>(255));
118 if (m_keyLocator.size() > 0) {
119 signatureInfo.setKeyLocator(m_keyLocator);
122 signature.setInfo(signatureInfo);
123 signature.setValue(Block(&m_signature,
sizeof(m_signature)));
125 data->setSignature(signature);
127 NS_LOG_INFO(
"node(" << GetNode()->
GetId() <<
") respodning with Data: " << data->getName());
133 m_face->onReceiveData(*data);
virtual void StopApplication()
Called at time specified by Stop.
static TypeId GetTypeId(void)
virtual void StopApplication()
Called at time specified by Stop.
NS_OBJECT_ENSURE_REGISTERED(ContentStore)
virtual void StartApplication()
Called at time specified by Start.
ndn Producer
Copyright (c) 2011-2015 Regents of the University of California.
virtual void StartApplication()
Called at time specified by Start.
virtual void OnInterest(shared_ptr< const Interest > interest)
Method that will be called every time new Interest arrives.
shared_ptr< Face > m_face
and StopApplication)
TracedCallback< shared_ptr< const Data >, Ptr< App >, shared_ptr< Face > > m_transmittedDatas
App-level trace of transmitted Data.
virtual void OnInterest(shared_ptr< const Interest > interest)
Method that will be called every time new Interest arrives.
Base class that all NDN applications should be derived from.
Ptr< const AttributeChecker > MakeNameChecker(void)
Ptr< const AttributeAccessor > MakeNameAccessor(T1 a1)
bool m_active
Flag to indicate that application is active (set by StartApplication.
uint32_t GetId() const
Get application ID (ID of applications face)
static void AddRoute(const std::string &nodeName, const Name &prefix, uint32_t faceId, int32_t metric)
Add forwarding entry to FIB.