NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ndn-consumer-cbr.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 University of California, Los Angeles
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
19  */
20 
21 #include "ndn-consumer-cbr.h"
22 #include "ns3/ptr.h"
23 #include "ns3/log.h"
24 #include "ns3/simulator.h"
25 #include "ns3/packet.h"
26 #include "ns3/callback.h"
27 #include "ns3/string.h"
28 #include "ns3/boolean.h"
29 #include "ns3/uinteger.h"
30 #include "ns3/integer.h"
31 #include "ns3/double.h"
32 
33 #include "ns3/ndn-app-face.h"
34 #include "ns3/ndn-interest.h"
35 #include "ns3/ndn-data.h"
36 
37 NS_LOG_COMPONENT_DEFINE ("ndn.ConsumerCbr");
38 
39 namespace ns3 {
40 namespace ndn {
41 
42 NS_OBJECT_ENSURE_REGISTERED (ConsumerCbr);
43 
44 TypeId
45 ConsumerCbr::GetTypeId (void)
46 {
47  static TypeId tid = TypeId ("ns3::ndn::ConsumerCbr")
48  .SetGroupName ("Ndn")
49  .SetParent<Consumer> ()
50  .AddConstructor<ConsumerCbr> ()
51 
52  .AddAttribute ("Frequency", "Frequency of interest packets",
53  StringValue ("1.0"),
54  MakeDoubleAccessor (&ConsumerCbr::m_frequency),
55  MakeDoubleChecker<double> ())
56 
57  .AddAttribute ("Randomize", "Type of send time randomization: none (default), uniform, exponential",
58  StringValue ("none"),
60  MakeStringChecker ())
61 
62  .AddAttribute ("MaxSeq",
63  "Maximum sequence number to request",
64  IntegerValue (std::numeric_limits<uint32_t>::max ()),
65  MakeIntegerAccessor (&ConsumerCbr::m_seqMax),
66  MakeIntegerChecker<uint32_t> ())
67 
68  ;
69 
70  return tid;
71 }
72 
74  : m_frequency (1.0)
75  , m_firstTime (true)
76  , m_random (0)
77 {
78  NS_LOG_FUNCTION_NOARGS ();
79  m_seqMax = std::numeric_limits<uint32_t>::max ();
80 }
81 
82 ConsumerCbr::~ConsumerCbr ()
83 {
84  if (m_random)
85  delete m_random;
86 }
87 
88 void
90 {
91  // double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
92  // std::cout << "next: " << Simulator::Now().ToDouble(Time::S) + mean << "s\n";
93 
94  if (m_firstTime)
95  {
96  m_sendEvent = Simulator::Schedule (Seconds (0.0),
97  &Consumer::SendPacket, this);
98  m_firstTime = false;
99  }
100  else if (!m_sendEvent.IsRunning ())
101  m_sendEvent = Simulator::Schedule (
102  (m_random == 0) ?
103  Seconds(1.0 / m_frequency)
104  :
105  Seconds(m_random->GetValue ()),
106  &Consumer::SendPacket, this);
107 }
108 
109 void
110 ConsumerCbr::SetRandomize (const std::string &value)
111 {
112  if (m_random)
113  delete m_random;
114 
115  if (value == "uniform")
116  {
117  m_random = new UniformVariable (0.0, 2 * 1.0 / m_frequency);
118  }
119  else if (value == "exponential")
120  {
121  m_random = new ExponentialVariable (1.0 / m_frequency, 50 * 1.0 / m_frequency);
122  }
123  else
124  m_random = 0;
125 
126  m_randomType = value;
127 }
128 
129 std::string
131 {
132  return m_randomType;
133 }
134 
135 
137 // Process incoming packets //
139 
140 // void
141 // Consumer::OnData (const Ptr<const Data> &contentObject,
142 // const Ptr<const Packet> &payload)
143 // {
144 // Consumer::OnData (contentObject, payload); // tracing inside
145 // }
146 
147 // void
148 // Consumer::OnNack (const Ptr<const Interest> &interest)
149 // {
150 // Consumer::OnNack (interest); // tracing inside
151 // }
152 
153 } // namespace ndn
154 } // namespace ns3
ConsumerCbr()
Default constructor Sets up randomizer function and packet sequence number.
Consumer()
Default constructor Sets up randomizer function and packet sequence number.
Definition: ndn-consumer.cc:86
EventId m_sendEvent
EventId of pending "send packet" event.
Definition: ndn-consumer.h:131
void SetRandomize(const std::string &value)
Set type of frequency randomization.
uint32_t m_seqMax
maximum number of sequence number
Definition: ndn-consumer.h:130
std::string GetRandomize() const
Get type of frequency randomization.
void SendPacket()
Actually send packet.
virtual void ScheduleNextPacket()
Constructs the Interest packet and sends it using a callback to the underlying NDN protocol...