NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
ndn-producer.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #include "ndn-producer.hpp"
21 #include "ns3/log.h"
22 #include "ns3/string.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/packet.h"
25 #include "ns3/simulator.h"
26 
29 
30 #include <memory>
31 
32 NS_LOG_COMPONENT_DEFINE("ndn.Producer");
33 
34 namespace ns3 {
35 namespace ndn {
36 
38 
39 TypeId
41 {
42  static TypeId tid =
43  TypeId("ns3::ndn::Producer")
44  .SetGroupName("Ndn")
45  .SetParent<App>()
46  .AddConstructor<Producer>()
47  .AddAttribute("Prefix", "Prefix, for which producer has the data", StringValue("/"),
48  MakeNameAccessor(&Producer::m_prefix), MakeNameChecker())
49  .AddAttribute(
50  "Postfix",
51  "Postfix that is added to the output data (e.g., for adding producer-uniqueness)",
52  StringValue("/"), MakeNameAccessor(&Producer::m_postfix), MakeNameChecker())
53  .AddAttribute("PayloadSize", "Virtual payload size for Content packets", UintegerValue(1024),
54  MakeUintegerAccessor(&Producer::m_virtualPayloadSize),
55  MakeUintegerChecker<uint32_t>())
56  .AddAttribute("Freshness", "Freshness of data packets, if 0, then unlimited freshness",
57  TimeValue(Seconds(0)), MakeTimeAccessor(&Producer::m_freshness),
58  MakeTimeChecker())
59  .AddAttribute(
60  "Signature",
61  "Fake signature, 0 valid signature (default), other values application-specific",
62  UintegerValue(0), MakeUintegerAccessor(&Producer::m_signature),
63  MakeUintegerChecker<uint32_t>())
64  .AddAttribute("KeyLocator",
65  "Name to be used for key locator. If root, then key locator is not used",
66  NameValue(), MakeNameAccessor(&Producer::m_keyLocator), MakeNameChecker());
67  return tid;
68 }
69 
71 {
72  NS_LOG_FUNCTION_NOARGS();
73 }
74 
75 // inherited from Application base class.
76 void
78 {
79  NS_LOG_FUNCTION_NOARGS();
81 
82  FibHelper::AddRoute(GetNode(), m_prefix, m_face, 0);
83 }
84 
85 void
87 {
88  NS_LOG_FUNCTION_NOARGS();
89 
91 }
92 
93 void
94 Producer::OnInterest(shared_ptr<const Interest> interest)
95 {
96  App::OnInterest(interest); // tracing inside
97 
98  NS_LOG_FUNCTION(this << interest);
99 
100  if (!m_active)
101  return;
102 
103  Name dataName(interest->getName());
104  // dataName.append(m_postfix);
105  // dataName.appendVersion();
106 
107  auto data = make_shared<Data>();
108  data->setName(dataName);
109  data->setFreshnessPeriod(::ndn::time::milliseconds(m_freshness.GetMilliSeconds()));
110 
111  data->setContent(make_shared< ::ndn::Buffer>(m_virtualPayloadSize));
112 
113  SignatureInfo signatureInfo(static_cast< ::ndn::tlv::SignatureTypeValue>(255));
114 
115  if (m_keyLocator.size() > 0) {
116  signatureInfo.setKeyLocator(m_keyLocator);
117  }
118 
119  data->setSignatureInfo(signatureInfo);
120 
121  ::ndn::EncodingEstimator estimator;
122  ::ndn::EncodingBuffer encoder(estimator.appendVarNumber(m_signature), 0);
123  encoder.appendVarNumber(m_signature);
124  data->setSignatureValue(encoder.getBuffer());
125 
126  NS_LOG_INFO("node(" << GetNode()->GetId() << ") responding with Data: " << data->getName());
127 
128  // to create real wire encoding
129  data->wireEncode();
130 
131  m_transmittedDatas(data, this, m_face);
132  m_appLink->onReceiveData(*data);
133 }
134 
135 } // namespace ndn
136 } // namespace ns3
Copyright (c) 2011-2015 Regents of the University of California.
virtual void StopApplication()
Called at time specified by Stop.
Definition: ndn-app.cpp:162
static TypeId GetTypeId(void)
virtual void StopApplication()
Called at time specified by Stop.
virtual void StartApplication()
Called at time specified by Start.
Definition: ndn-app.cpp:138
NS_OBJECT_ENSURE_REGISTERED(GlobalRouter)
static void AddRoute(Ptr< Node > node, const Name &prefix, shared_ptr< Face > face, int32_t metric)
Add forwarding entry to FIB.
void onReceiveData(const Data &data)
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.
Definition: ndn-app.cpp:114
Copyright (c) 2011-2015 Regents of the University of California.
shared_ptr< Face > m_face
Definition: ndn-app.hpp:104
TracedCallback< shared_ptr< const Data >, Ptr< App >, shared_ptr< Face > > m_transmittedDatas
App-level trace of transmitted Data.
Definition: ndn-app.hpp:122
virtual void OnInterest(shared_ptr< const Interest > interest)
Method that will be called every time new Interest arrives.
AppLinkService * m_appLink
Definition: ndn-app.hpp:105
Base class that all NDN applications should be derived from.
Definition: ndn-app.hpp:48
Ptr< const AttributeChecker > MakeNameChecker(void)
uint32_t GetId() const
Get application ID (ID of applications face)
Definition: ndn-app.cpp:108
size_t appendVarNumber(uint64_t number)
Append number encoded as a VAR-NUMBER in NDN-TLV format.
Definition: encoder.cpp:137
Ptr< const AttributeAccessor > MakeNameAccessor(T1 a1)
Definition: ndn-common.hpp:48
bool m_active
Flag to indicate that application is active (set by StartApplication and StopApplication) ...
Definition: ndn-app.hpp:103
EncodingImpl< EncoderTag > EncodingBuffer
EncodingImpl< EstimatorTag > EncodingEstimator
boost::chrono::milliseconds milliseconds
Definition: time.hpp:48