22 #include "ndn-producer.h"
24 #include "ns3/ndn-interest.h"
25 #include "ns3/ndn-data.h"
26 #include "ns3/string.h"
27 #include "ns3/uinteger.h"
28 #include "ns3/packet.h"
29 #include "ns3/simulator.h"
31 #include "ns3/ndn-app-face.h"
32 #include "ns3/ndn-fib.h"
34 #include "ns3/ndnSIM/utils/ndn-fw-hop-count-tag.h"
36 #include <boost/ref.hpp>
37 #include <boost/lambda/lambda.hpp>
38 #include <boost/lambda/bind.hpp>
39 namespace ll = boost::lambda;
41 NS_LOG_COMPONENT_DEFINE (
"ndn.Producer");
46 NS_OBJECT_ENSURE_REGISTERED (Producer);
49 Producer::GetTypeId (
void)
51 static TypeId tid = TypeId (
"ns3::ndn::Producer")
54 .AddConstructor<Producer> ()
55 .AddAttribute (
"Prefix",
"Prefix, for which producer has the data",
57 MakeNameAccessor (&Producer::m_prefix),
59 .AddAttribute (
"Postfix",
"Postfix that is added to the output data (e.g., for adding producer-uniqueness)",
61 MakeNameAccessor (&Producer::m_postfix),
63 .AddAttribute (
"PayloadSize",
"Virtual payload size for Content packets",
65 MakeUintegerAccessor (&Producer::m_virtualPayloadSize),
66 MakeUintegerChecker<uint32_t> ())
67 .AddAttribute (
"Freshness",
"Freshness of data packets, if 0, then unlimited freshness",
68 TimeValue (Seconds (0)),
69 MakeTimeAccessor (&Producer::m_freshness),
71 .AddAttribute (
"Signature",
"Fake signature, 0 valid signature (default), other values application-specific",
73 MakeUintegerAccessor (&Producer::m_signature),
74 MakeUintegerChecker<uint32_t> ())
75 .AddAttribute (
"KeyLocator",
"Name to be used for key locator. If root, then key locator is not used",
77 MakeNameAccessor (&Producer::m_keyLocator),
92 NS_LOG_FUNCTION_NOARGS ();
93 NS_ASSERT (GetNode ()->GetObject<Fib> () != 0);
97 NS_LOG_DEBUG (
"NodeID: " << GetNode ()->
GetId ());
99 Ptr<Fib> fib = GetNode ()->GetObject<
Fib> ();
101 Ptr<fib::Entry> fibEntry = fib->
Add (m_prefix,
m_face, 0);
103 fibEntry->UpdateStatus (
m_face, fib::FaceMetric::NDN_FIB_GREEN);
114 NS_LOG_FUNCTION_NOARGS ();
115 NS_ASSERT (GetNode ()->GetObject<Fib> () != 0);
126 NS_LOG_FUNCTION (
this << interest);
130 Ptr<Data> data = Create<Data> (Create<Packet> (m_virtualPayloadSize));
131 Ptr<Name> dataName = Create<Name> (interest->GetName ());
132 dataName->append (m_postfix);
133 data->SetName (dataName);
134 data->SetFreshness (m_freshness);
135 data->SetTimestamp (Simulator::Now());
137 data->SetSignature (m_signature);
138 if (m_keyLocator.
size () > 0)
140 data->SetKeyLocator (Create<Name> (m_keyLocator));
143 NS_LOG_INFO (
"node("<< GetNode()->
GetId() <<
") respodning with Data: " << data->GetName ());
147 if (interest->GetPayload ()->PeekPacketTag (hopCountTag))
149 data->GetPayload ()->AddPacketTag (hopCountTag);
152 m_face->ReceiveData (data);
bool m_active
Flag to indicate that application is active (set by StartApplication and StopApplication) ...
virtual Ptr< fib::Entry > Add(const Name &prefix, Ptr< Face > face, int32_t metric)=0
Add or update FIB entry.
virtual void StartApplication()
Called at time specified by Start.
virtual void StartApplication()
Called at time specified by Start.
uint32_t GetId() const
Get application ID (ID of applications face)
size_t size() const
Get number of the name components.
void OnInterest(Ptr< const Interest > interest)
Method that will be called every time new Interest arrives.
Class implementing FIB functionality.
virtual void StopApplication()
Called at time specified by Stop.
virtual void OnInterest(Ptr< const Interest > interest)
Method that will be called every time new Interest arrives.
Packet tag that is used to track hop count for Interest-Data pairs.
App()
Default constructor.
Ptr< Face > m_face
automatically created application face through which application communicates
virtual void StopApplication()
Called at time specified by Stop.
TracedCallback< Ptr< const Data >, Ptr< App >, Ptr< Face > > m_transmittedDatas
App-level trace of transmitted Data.