NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-app-face.hpp"
28 #include "model/ndn-ns3.hpp"
31 
32 #include <memory>
33 
34 NS_LOG_COMPONENT_DEFINE("ndn.Producer");
35 
36 namespace ns3 {
37 namespace ndn {
38 
40 
41 TypeId
43 {
44  static TypeId tid =
45  TypeId("ns3::ndn::Producer")
46  .SetGroupName("Ndn")
47  .SetParent<App>()
48  .AddConstructor<Producer>()
49  .AddAttribute("Prefix", "Prefix, for which producer has the data", StringValue("/"),
50  MakeNameAccessor(&Producer::m_prefix), MakeNameChecker())
51  .AddAttribute(
52  "Postfix",
53  "Postfix that is added to the output data (e.g., for adding producer-uniqueness)",
54  StringValue("/"), MakeNameAccessor(&Producer::m_postfix), MakeNameChecker())
55  .AddAttribute("PayloadSize", "Virtual payload size for Content packets", UintegerValue(1024),
56  MakeUintegerAccessor(&Producer::m_virtualPayloadSize),
57  MakeUintegerChecker<uint32_t>())
58  .AddAttribute("Freshness", "Freshness of data packets, if 0, then unlimited freshness",
59  TimeValue(Seconds(0)), MakeTimeAccessor(&Producer::m_freshness),
60  MakeTimeChecker())
61  .AddAttribute(
62  "Signature",
63  "Fake signature, 0 valid signature (default), other values application-specific",
64  UintegerValue(0), MakeUintegerAccessor(&Producer::m_signature),
65  MakeUintegerChecker<uint32_t>())
66  .AddAttribute("KeyLocator",
67  "Name to be used for key locator. If root, then key locator is not used",
68  NameValue(), MakeNameAccessor(&Producer::m_keyLocator), MakeNameChecker());
69  return tid;
70 }
71 
73 {
74  NS_LOG_FUNCTION_NOARGS();
75 }
76 
77 // inherited from Application base class.
78 void
80 {
81  NS_LOG_FUNCTION_NOARGS();
83 
84  FibHelper::AddRoute(GetNode(), m_prefix, m_face, 0);
85 }
86 
87 void
89 {
90  NS_LOG_FUNCTION_NOARGS();
91 
93 }
94 
95 void
96 Producer::OnInterest(shared_ptr<const Interest> interest)
97 {
98  App::OnInterest(interest); // tracing inside
99 
100  NS_LOG_FUNCTION(this << interest);
101 
102  if (!m_active)
103  return;
104 
105  Name dataName(interest->getName());
106  // dataName.append(m_postfix);
107  // dataName.appendVersion();
108 
109  auto data = make_shared<Data>();
110  data->setName(dataName);
111  data->setFreshnessPeriod(::ndn::time::milliseconds(m_freshness.GetMilliSeconds()));
112 
113  data->setContent(make_shared< ::ndn::Buffer>(m_virtualPayloadSize));
114 
115  Signature signature;
116  SignatureInfo signatureInfo(static_cast< ::ndn::tlv::SignatureTypeValue>(255));
117 
118  if (m_keyLocator.size() > 0) {
119  signatureInfo.setKeyLocator(m_keyLocator);
120  }
121 
122  signature.setInfo(signatureInfo);
123  signature.setValue(Block(&m_signature, sizeof(m_signature)));
124 
125  data->setSignature(signature);
126 
127  NS_LOG_INFO("node(" << GetNode()->GetId() << ") respodning with Data: " << data->getName());
128 
129  // to create real wire encoding
130  data->wireEncode();
131 
132  m_transmittedDatas(data, this, m_face);
133  m_face->onReceiveData(*data);
134 }
135 
136 } // namespace ndn
137 } // namespace ns3
virtual void StopApplication()
Called at time specified by Stop.
Definition: ndn-app.cpp:121
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:103
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:88
shared_ptr< Face > m_face
and StopApplication)
Definition: ndn-app.hpp:101
TracedCallback< shared_ptr< const Data >, Ptr< App >, shared_ptr< Face > > m_transmittedDatas
App-level trace of transmitted Data.
Definition: ndn-app.hpp:114
virtual void OnInterest(shared_ptr< const Interest > interest)
Method that will be called every time new Interest arrives.
Base class that all NDN applications should be derived from.
Definition: ndn-app.hpp:47
Ptr< const AttributeChecker > MakeNameChecker(void)
Ptr< const AttributeAccessor > MakeNameAccessor(T1 a1)
Definition: ndn-common.hpp:47
bool m_active
Flag to indicate that application is active (set by StartApplication.
Definition: ndn-app.hpp:98
uint32_t GetId() const
Get application ID (ID of applications face)
Definition: ndn-app.cpp:79
static void AddRoute(const std::string &nodeName, const Name &prefix, uint32_t faceId, int32_t metric)
Add forwarding entry to FIB.