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-consumer-cbr.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #include "ndn-consumer-cbr.hpp"
21 #include "ns3/ptr.h"
22 #include "ns3/log.h"
23 #include "ns3/simulator.h"
24 #include "ns3/packet.h"
25 #include "ns3/callback.h"
26 #include "ns3/string.h"
27 #include "ns3/boolean.h"
28 #include "ns3/uinteger.h"
29 #include "ns3/integer.h"
30 #include "ns3/double.h"
31 
32 #include "model/ndn-app-face.hpp"
33 
34 NS_LOG_COMPONENT_DEFINE("ndn.ConsumerCbr");
35 
36 namespace ns3 {
37 namespace ndn {
38 
40 
41 TypeId
43 {
44  static TypeId tid =
45  TypeId("ns3::ndn::ConsumerCbr")
46  .SetGroupName("Ndn")
47  .SetParent<Consumer>()
48  .AddConstructor<ConsumerCbr>()
49 
50  .AddAttribute("Frequency", "Frequency of interest packets", StringValue("1.0"),
51  MakeDoubleAccessor(&ConsumerCbr::m_frequency), MakeDoubleChecker<double>())
52 
53  .AddAttribute("Randomize",
54  "Type of send time randomization: none (default), uniform, exponential",
55  StringValue("none"),
57  MakeStringChecker())
58 
59  .AddAttribute("MaxSeq", "Maximum sequence number to request",
60  IntegerValue(std::numeric_limits<uint32_t>::max()),
61  MakeIntegerAccessor(&ConsumerCbr::m_seqMax), MakeIntegerChecker<uint32_t>())
62 
63  ;
64 
65  return tid;
66 }
67 
69  : m_frequency(1.0)
70  , m_firstTime(true)
71  , m_random(0)
72 {
73  NS_LOG_FUNCTION_NOARGS();
74  m_seqMax = std::numeric_limits<uint32_t>::max();
75 }
76 
78 {
79  if (m_random)
80  delete m_random;
81 }
82 
83 void
85 {
86  // double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
87  // std::cout << "next: " << Simulator::Now().ToDouble(Time::S) + mean << "s\n";
88 
89  if (m_firstTime) {
90  m_sendEvent = Simulator::Schedule(Seconds(0.0), &Consumer::SendPacket, this);
91  m_firstTime = false;
92  }
93  else if (!m_sendEvent.IsRunning())
94  m_sendEvent = Simulator::Schedule((m_random == 0) ? Seconds(1.0 / m_frequency)
95  : Seconds(m_random->GetValue()),
96  &Consumer::SendPacket, this);
97 }
98 
99 void
100 ConsumerCbr::SetRandomize(const std::string& value)
101 {
102  if (m_random)
103  delete m_random;
104 
105  if (value == "uniform") {
106  m_random = new UniformVariable(0.0, 2 * 1.0 / m_frequency);
107  }
108  else if (value == "exponential") {
109  m_random = new ExponentialVariable(1.0 / m_frequency, 50 * 1.0 / m_frequency);
110  }
111  else
112  m_random = 0;
113 
114  m_randomType = value;
115 }
116 
117 std::string
119 {
120  return m_randomType;
121 }
122 
123 } // namespace ndn
124 } // namespace ns3
ndn ConsumerCbr
Copyright (c) 2011-2015 Regents of the University of California.
uint32_t m_seqMax
maximum number of sequence number
RandomVariable * m_random
NS_OBJECT_ENSURE_REGISTERED(ContentStore)
static TypeId GetTypeId()
std::string GetRandomize() const
Get type of frequency randomization.
NDN application for sending out Interest packets.
void SendPacket()
Actually send packet.
void SetRandomize(const std::string &value)
Set type of frequency randomization.
virtual void ScheduleNextPacket()
Constructs the Interest packet and sends it using a callback to the underlying NDN protocol...
ConsumerCbr()
Default constructor Sets up randomizer function and packet sequence number.
EventId m_sendEvent
EventId of pending "send packet" event.