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
37
NS_OBJECT_ENSURE_REGISTERED
(
ConsumerCbr
);
38
39
TypeId
40
ConsumerCbr::GetTypeId
(
void
)
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"
),
54
MakeStringAccessor(&
ConsumerCbr::SetRandomize
, &
ConsumerCbr::GetRandomize
),
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
66
ConsumerCbr::ConsumerCbr
()
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
74
ConsumerCbr::~ConsumerCbr
()
75
{
76
}
77
78
void
79
ConsumerCbr::ScheduleNextPacket
()
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
110
m_randomType
= value;
111
}
112
113
std::string
114
ConsumerCbr::GetRandomize
()
const
115
{
116
return
m_randomType
;
117
}
118
119
}
// namespace ndn
120
}
// namespace ns3
ConsumerCbr
ndn ConsumerCbr
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-consumer-cbr.cpp:32
ns3::ndn::Consumer::m_seqMax
uint32_t m_seqMax
maximum number of sequence number
Definition:
ndn-consumer.hpp:138
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ns3::ndn::ConsumerCbr::m_random
Ptr< RandomVariableStream > m_random
Definition:
ndn-consumer-cbr.hpp:71
ns3::ndn::ConsumerCbr::m_firstTime
bool m_firstTime
Definition:
ndn-consumer-cbr.hpp:70
ns3::ndn::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(ContentStore)
ns3::ndn::ConsumerCbr::GetTypeId
static TypeId GetTypeId()
Definition:
ndn-consumer-cbr.cpp:40
ns3::ndn::ConsumerCbr::~ConsumerCbr
virtual ~ConsumerCbr()
Definition:
ndn-consumer-cbr.cpp:74
ns3::ndn::ConsumerCbr::m_frequency
double m_frequency
Definition:
ndn-consumer-cbr.hpp:69
ns3::ndn::Consumer
NDN application for sending out Interest packets.
Definition:
ndn-consumer.hpp:49
ns3::ndn::Consumer::SendPacket
void SendPacket()
Actually send packet.
Definition:
ndn-consumer.cpp:159
ns3::ndn::ConsumerCbr::SetRandomize
void SetRandomize(const std::string &value)
Set type of frequency randomization.
Definition:
ndn-consumer-cbr.cpp:95
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:79
ns3
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
content-store-impl.cpp:38
ns3::ndn::ConsumerCbr::ConsumerCbr
ConsumerCbr()
Default constructor Sets up randomizer function and packet sequence number.
Definition:
ndn-consumer-cbr.cpp:66
ns3::ndn::Consumer::m_sendEvent
EventId m_sendEvent
EventId of pending "send packet" event.
Definition:
ndn-consumer.hpp:139
ns3::ndn::ConsumerCbr::GetRandomize
std::string GetRandomize() const
Get type of frequency randomization.
Definition:
ndn-consumer-cbr.cpp:114
ndnSIM
apps
ndn-consumer-cbr.cpp
Generated on Wed Jan 11 2017 18:17:13 for ndnSIM by
1.8.13