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  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
ns3::ndn::Producer
A simple Interest-sink applia simple Interest-sink application.
Definition: ndn-producer.hpp:43
ns3::ndn::MakeNameAccessor
Ptr< const AttributeAccessor > MakeNameAccessor(T1 a1)
Definition: ndn-common.hpp:49
ns3
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-app-link-service.cpp:32
ns3::ndn::MakeNameChecker
Ptr< const AttributeChecker > MakeNameChecker(void)
ns3::ndn::App::m_active
bool m_active
Flag to indicate that application is active (set by StartApplication and StopApplication)
Definition: ndn-app.hpp:103
ns3::ndn::App::m_appLink
AppLinkService * m_appLink
Definition: ndn-app.hpp:105
ns3::ndn::Producer::OnInterest
virtual void OnInterest(shared_ptr< const Interest > interest)
Method that will be called every time new Interest arrives.
Definition: ndn-producer.cpp:94
ns3::ndn::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(GlobalRouter)
ns3::ndn::App::StartApplication
virtual void StartApplication()
Called at time specified by Start.
Definition: ndn-app.cpp:138
ndn::tlv::SignatureValue
@ SignatureValue
Definition: tlv.hpp:81
ns3::ndn::Name
Name
Definition: ndn-common.cpp:25
ns3::ndn::Producer::Producer
Producer()
Definition: ndn-producer.cpp:70
ns3::ndn::AppLinkService::onReceiveData
void onReceiveData(const Data &data)
Definition: ndn-app-link-service.cpp:85
ndn::encoding::makeNonNegativeIntegerBlock
Block makeNonNegativeIntegerBlock(uint32_t type, uint64_t value)
Create a TLV block containing a non-negative integer.
Definition: block-helpers.cpp:52
ndn::tlv::SignatureTypeValue
SignatureTypeValue
SignatureType values.
Definition: tlv.hpp:129
ns3::ndn::FibHelper::AddRoute
static void AddRoute(Ptr< Node > node, const Name &prefix, shared_ptr< Face > face, int32_t metric)
Add forwarding entry to FIB.
Definition: ndn-fib-helper.cpp:85
ns3::ndn::Producer::GetTypeId
static TypeId GetTypeId(void)
Definition: ndn-producer.cpp:40
ns3::ndn::App::OnInterest
virtual void OnInterest(shared_ptr< const Interest > interest)
Method that will be called every time new Interest arrives.
Definition: ndn-app.cpp:114
ns3::ndn::Producer::StopApplication
virtual void StopApplication()
Called at time specified by Stop.
Definition: ndn-producer.cpp:86
ndn-fib-helper.hpp
ndn-producer.hpp
ns3::ndn::App
Base class that all NDN applications should be derived from.
Definition: ndn-app.hpp:48
ns3::ndn::App::GetId
uint32_t GetId() const
Get application ID (ID of applications face)
Definition: ndn-app.cpp:108
ns3::ndn::Producer::StartApplication
virtual void StartApplication()
Called at time specified by Start.
Definition: ndn-producer.cpp:77
ns3::ndn::App::m_face
shared_ptr< Face > m_face
Definition: ndn-app.hpp:104
ns3::ndn::App::m_transmittedDatas
TracedCallback< shared_ptr< const Data >, Ptr< App >, shared_ptr< Face > > m_transmittedDatas
App-level trace of transmitted Data.
Definition: ndn-app.hpp:122
ns3::ndn::NameValue
Definition: ndn-common.hpp:49
ns3::ndn::App::StopApplication
virtual void StopApplication()
Called at time specified by Stop.
Definition: ndn-app.cpp:162
ndn-l3-protocol.hpp
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::tlv::SignatureInfo
@ SignatureInfo
Definition: tlv.hpp:80