NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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  Signature signature;
114  SignatureInfo signatureInfo(static_cast< ::ndn::tlv::SignatureTypeValue>(255));
115 
116  if (m_keyLocator.size() > 0) {
117  signatureInfo.setKeyLocator(m_keyLocator);
118  }
119 
120  signature.setInfo(signatureInfo);
121  signature.setValue(::ndn::makeNonNegativeIntegerBlock(::ndn::tlv::SignatureValue, m_signature));
122 
123  data->setSignature(signature);
124 
125  NS_LOG_INFO("node(" << GetNode()->GetId() << ") responding with Data: " << data->getName());
126 
127  // to create real wire encoding
128  data->wireEncode();
129 
130  m_transmittedDatas(data, this, m_face);
131  m_appLink->onReceiveData(*data);
132 }
133 
134 } // namespace ndn
135 } // 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.
NS_OBJECT_ENSURE_REGISTERED(ContentStore)
boost::posix_time::time_duration milliseconds(long duration)
Definition: asio.hpp:117
virtual void StartApplication()
Called at time specified by Start.
Definition: ndn-app.cpp:138
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.
Block makeNonNegativeIntegerBlock(uint32_t type, uint64_t value)
Create a TLV block containing a non-negative integer.
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)
Ptr< const AttributeAccessor > MakeNameAccessor(T1 a1)
Definition: ndn-common.hpp:49
bool m_active
Flag to indicate that application is active (set by StartApplication and StopApplication) ...
Definition: ndn-app.hpp:103
uint32_t GetId() const
Get application ID (ID of applications face)
Definition: ndn-app.cpp:108