NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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 #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 {
72  NS_LOG_FUNCTION_NOARGS();
73  m_seqMax = std::numeric_limits<uint32_t>::max();
74 }
75 
77 {
78 }
79 
80 void
82 {
83  // double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
84  // std::cout << "next: " << Simulator::Now().ToDouble(Time::S) + mean << "s\n";
85 
86  if (m_firstTime) {
87  m_sendEvent = Simulator::Schedule(Seconds(0.0), &Consumer::SendPacket, this);
88  m_firstTime = false;
89  }
90  else if (!m_sendEvent.IsRunning())
91  m_sendEvent = Simulator::Schedule((m_random == 0) ? Seconds(1.0 / m_frequency)
92  : Seconds(m_random->GetValue()),
93  &Consumer::SendPacket, this);
94 }
95 
96 void
97 ConsumerCbr::SetRandomize(const std::string& value)
98 {
99  if (value == "uniform") {
100  m_random = CreateObject<UniformRandomVariable>();
101  m_random->SetAttribute("Min", DoubleValue(0.0));
102  m_random->SetAttribute("Max", DoubleValue(2 * 1.0 / m_frequency));
103  }
104  else if (value == "exponential") {
105  m_random = CreateObject<ExponentialRandomVariable>();
106  m_random->SetAttribute("Mean", DoubleValue(1.0 / m_frequency));
107  m_random->SetAttribute("Bound", DoubleValue(50 * 1.0 / m_frequency));
108  }
109  else
110  m_random = 0;
111 
112  m_randomType = value;
113 }
114 
115 std::string
117 {
118  return m_randomType;
119 }
120 
121 } // namespace ndn
122 } // 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.