NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
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 NS_LOG_COMPONENT_DEFINE("ndn.ConsumerCbr");
33 
34 namespace ns3 {
35 namespace ndn {
36 
38 
39 TypeId
41 {
42  static TypeId tid =
43  TypeId("ns3::ndn::ConsumerCbr")
44  .SetGroupName("Ndn")
45  .SetParent<Consumer>()
46  .AddConstructor<ConsumerCbr>()
47 
48  .AddAttribute("Frequency", "Frequency of interest packets", StringValue("1.0"),
49  MakeDoubleAccessor(&ConsumerCbr::m_frequency), MakeDoubleChecker<double>())
50 
51  .AddAttribute("Randomize",
52  "Type of send time randomization: none (default), uniform, exponential",
53  StringValue("none"),
55  MakeStringChecker())
56 
57  .AddAttribute("MaxSeq", "Maximum sequence number to request",
58  IntegerValue(std::numeric_limits<uint32_t>::max()),
59  MakeIntegerAccessor(&ConsumerCbr::m_seqMax), MakeIntegerChecker<uint32_t>())
60 
61  ;
62 
63  return tid;
64 }
65 
67  : m_frequency(1.0)
68  , m_firstTime(true)
69 {
70  NS_LOG_FUNCTION_NOARGS();
71  m_seqMax = std::numeric_limits<uint32_t>::max();
72 }
73 
75 {
76 }
77 
78 void
80 {
81  // double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
82  // std::cout << "next: " << Simulator::Now().ToDouble(Time::S) + mean << "s\n";
83 
84  if (m_firstTime) {
85  m_sendEvent = Simulator::Schedule(Seconds(0.0), &Consumer::SendPacket, this);
86  m_firstTime = false;
87  }
88  else if (!m_sendEvent.IsRunning())
89  m_sendEvent = Simulator::Schedule((m_random == 0) ? Seconds(1.0 / m_frequency)
90  : Seconds(m_random->GetValue()),
91  &Consumer::SendPacket, this);
92 }
93 
94 void
95 ConsumerCbr::SetRandomize(const std::string& value)
96 {
97  if (value == "uniform") {
98  m_random = CreateObject<UniformRandomVariable>();
99  m_random->SetAttribute("Min", DoubleValue(0.0));
100  m_random->SetAttribute("Max", DoubleValue(2 * 1.0 / m_frequency));
101  }
102  else if (value == "exponential") {
103  m_random = CreateObject<ExponentialRandomVariable>();
104  m_random->SetAttribute("Mean", DoubleValue(1.0 / m_frequency));
105  m_random->SetAttribute("Bound", DoubleValue(50 * 1.0 / m_frequency));
106  }
107  else
108  m_random = 0;
109 
111 }
112 
113 std::string
115 {
116  return m_randomType;
117 }
118 
119 } // namespace ndn
120 } // namespace ns3
ndn ConsumerCbr
Copyright (c) 2011-2015 Regents of the University of California.
uint32_t m_seqMax
maximum number of sequence number
Copyright (c) 2011-2015 Regents of the University of California.
Ptr< RandomVariableStream > 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...
Copyright (c) 2011-2015 Regents of the University of California.
ConsumerCbr()
Default constructor Sets up randomizer function and packet sequence number.
EventId m_sendEvent
EventId of pending "send packet" event.