NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
39
NS_OBJECT_ENSURE_REGISTERED
(
ConsumerCbr
);
40
41
TypeId
42
ConsumerCbr::GetTypeId
(
void
)
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"
),
56
MakeStringAccessor(&
ConsumerCbr::SetRandomize
, &
ConsumerCbr::GetRandomize
),
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
68
ConsumerCbr::ConsumerCbr
()
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
77
ConsumerCbr::~ConsumerCbr
()
78
{
79
if
(
m_random
)
80
delete
m_random
;
81
}
82
83
void
84
ConsumerCbr::ScheduleNextPacket
()
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
118
ConsumerCbr::GetRandomize
()
const
119
{
120
return
m_randomType
;
121
}
122
123
}
// namespace ndn
124
}
// namespace ns3
ConsumerCbr
ndn ConsumerCbr
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-consumer-cbr.cpp:34
ns3::ndn::Consumer::m_seqMax
uint32_t m_seqMax
maximum number of sequence number
Definition:
ndn-consumer.hpp:131
ns3::ndn::ConsumerCbr::m_firstTime
bool m_firstTime
Definition:
ndn-consumer-cbr.hpp:70
ns3::ndn::ConsumerCbr::m_random
RandomVariable * m_random
Definition:
ndn-consumer-cbr.hpp:71
ns3::ndn::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(ContentStore)
ns3::ndn::ConsumerCbr::GetTypeId
static TypeId GetTypeId()
Definition:
ndn-consumer-cbr.cpp:42
ns3::ndn::ConsumerCbr::~ConsumerCbr
virtual ~ConsumerCbr()
Definition:
ndn-consumer-cbr.cpp:77
ns3::ndn::ConsumerCbr::m_frequency
double m_frequency
Definition:
ndn-consumer-cbr.hpp:69
ns3::ndn::ConsumerCbr::GetRandomize
std::string GetRandomize() const
Get type of frequency randomization.
Definition:
ndn-consumer-cbr.cpp:118
ns3::ndn::Consumer
NDN application for sending out Interest packets.
Definition:
ndn-consumer.hpp:50
ns3::ndn::Consumer::SendPacket
void SendPacket()
Actually send packet.
Definition:
ndn-consumer.cpp:156
ns3::ndn::ConsumerCbr::SetRandomize
void SetRandomize(const std::string &value)
Set type of frequency randomization.
Definition:
ndn-consumer-cbr.cpp:100
ndn-consumer-cbr.hpp
ns3::ndn::ConsumerCbr::m_randomType
std::string m_randomType
Definition:
ndn-consumer-cbr.hpp:72
ns3::ndn::ConsumerCbr::ScheduleNextPacket
virtual void ScheduleNextPacket()
Constructs the Interest packet and sends it using a callback to the underlying NDN protocol...
Definition:
ndn-consumer-cbr.cpp:84
ns3::ndn::ConsumerCbr::ConsumerCbr
ConsumerCbr()
Default constructor Sets up randomizer function and packet sequence number.
Definition:
ndn-consumer-cbr.cpp:68
ndn-app-face.hpp
ns3::ndn::Consumer::m_sendEvent
EventId m_sendEvent
EventId of pending "send packet" event.
Definition:
ndn-consumer.hpp:132
ndnSIM
apps
ndn-consumer-cbr.cpp
Generated on Wed Feb 18 2015 16:31:16 for ndnSIM by
1.8.7