NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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 
27 #include "model/ndn-ns3.hpp"
30 
31 #include <memory>
32 
33 NS_LOG_COMPONENT_DEFINE("ndn.Producer");
34 
35 namespace ns3 {
36 namespace ndn {
37 
39 
40 TypeId
42 {
43  static TypeId tid =
44  TypeId("ns3::ndn::Producer")
45  .SetGroupName("Ndn")
46  .SetParent<App>()
47  .AddConstructor<Producer>()
48  .AddAttribute("Prefix", "Prefix, for which producer has the data", StringValue("/"),
49  MakeNameAccessor(&Producer::m_prefix), MakeNameChecker())
50  .AddAttribute(
51  "Postfix",
52  "Postfix that is added to the output data (e.g., for adding producer-uniqueness)",
53  StringValue("/"), MakeNameAccessor(&Producer::m_postfix), MakeNameChecker())
54  .AddAttribute("PayloadSize", "Virtual payload size for Content packets", UintegerValue(1024),
55  MakeUintegerAccessor(&Producer::m_virtualPayloadSize),
56  MakeUintegerChecker<uint32_t>())
57  .AddAttribute("Freshness", "Freshness of data packets, if 0, then unlimited freshness",
58  TimeValue(Seconds(0)), MakeTimeAccessor(&Producer::m_freshness),
59  MakeTimeChecker())
60  .AddAttribute(
61  "Signature",
62  "Fake signature, 0 valid signature (default), other values application-specific",
63  UintegerValue(0), MakeUintegerAccessor(&Producer::m_signature),
64  MakeUintegerChecker<uint32_t>())
65  .AddAttribute("KeyLocator",
66  "Name to be used for key locator. If root, then key locator is not used",
67  NameValue(), MakeNameAccessor(&Producer::m_keyLocator), MakeNameChecker());
68  return tid;
69 }
70 
72 {
73  NS_LOG_FUNCTION_NOARGS();
74 }
75 
76 // inherited from Application base class.
77 void
79 {
80  NS_LOG_FUNCTION_NOARGS();
82 
83  FibHelper::AddRoute(GetNode(), m_prefix, m_face, 0);
84 }
85 
86 void
88 {
89  NS_LOG_FUNCTION_NOARGS();
90 
92 }
93 
94 void
95 Producer::OnInterest(shared_ptr<const Interest> interest)
96 {
97  App::OnInterest(interest); // tracing inside
98 
99  NS_LOG_FUNCTION(this << interest);
100 
101  if (!m_active)
102  return;
103 
104  Name dataName(interest->getName());
105  // dataName.append(m_postfix);
106  // dataName.appendVersion();
107 
108  auto data = make_shared<Data>();
109  data->setName(dataName);
110  data->setFreshnessPeriod(::ndn::time::milliseconds(m_freshness.GetMilliSeconds()));
111 
112  data->setContent(make_shared< ::ndn::Buffer>(m_virtualPayloadSize));
113 
114  Signature signature;
115  SignatureInfo signatureInfo(static_cast< ::ndn::tlv::SignatureTypeValue>(255));
116 
117  if (m_keyLocator.size() > 0) {
118  signatureInfo.setKeyLocator(m_keyLocator);
119  }
120 
121  signature.setInfo(signatureInfo);
122  signature.setValue(::ndn::nonNegativeIntegerBlock(::ndn::tlv::SignatureValue, m_signature));
123 
124  data->setSignature(signature);
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:154
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.
Definition: ndn-app.cpp:130
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.
Block nonNegativeIntegerBlock(uint32_t type, uint64_t value)
virtual void OnInterest(shared_ptr< const Interest > interest)
Method that will be called every time new Interest arrives.
Definition: ndn-app.cpp:106
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:121
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:100
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