29 NS_LOG_COMPONENT_DEFINE(
"ndn.ConsumerZipfMandelbrot");
40 TypeId(
"ns3::ndn::ConsumerZipfMandelbrot")
43 .AddConstructor<ConsumerZipfMandelbrot>()
45 .AddAttribute(
"NumberOfContents",
"Number of the Contents in total", StringValue(
"100"),
46 MakeUintegerAccessor(&ConsumerZipfMandelbrot::SetNumberOfContents,
47 &ConsumerZipfMandelbrot::GetNumberOfContents),
48 MakeUintegerChecker<uint32_t>())
50 .AddAttribute(
"q",
"parameter of improve rank", StringValue(
"0.7"),
51 MakeDoubleAccessor(&ConsumerZipfMandelbrot::SetQ,
52 &ConsumerZipfMandelbrot::GetQ),
53 MakeDoubleChecker<double>())
55 .AddAttribute(
"s",
"parameter of power", StringValue(
"0.7"),
56 MakeDoubleAccessor(&ConsumerZipfMandelbrot::SetS,
57 &ConsumerZipfMandelbrot::GetS),
58 MakeDoubleChecker<double>());
67 , m_seqRng(CreateObject<UniformRandomVariable>())
77 ConsumerZipfMandelbrot::SetNumberOfContents(uint32_t numOfContents)
81 NS_LOG_DEBUG(m_q <<
" and " << m_s <<
" and " << m_N);
83 m_Pcum = std::vector<double>(m_N + 1);
86 for (uint32_t i = 1; i <= m_N; i++) {
87 m_Pcum[i] = m_Pcum[i - 1] + 1.0 / std::pow(i + m_q, m_s);
90 for (uint32_t i = 1; i <= m_N; i++) {
91 m_Pcum[i] = m_Pcum[i] / m_Pcum[m_N];
92 NS_LOG_LOGIC(
"Cumulative probability [" << i <<
"]=" << m_Pcum[i]);
97 ConsumerZipfMandelbrot::GetNumberOfContents()
const 103 ConsumerZipfMandelbrot::SetQ(
double q)
106 SetNumberOfContents(m_N);
110 ConsumerZipfMandelbrot::GetQ()
const 116 ConsumerZipfMandelbrot::SetS(
double s)
119 SetNumberOfContents(m_N);
123 ConsumerZipfMandelbrot::GetS()
const 134 NS_LOG_FUNCTION_NOARGS();
136 uint32_t seq = std::numeric_limits<uint32_t>::max();
140 while (m_retxSeqs.size()) {
141 seq = *m_retxSeqs.begin();
142 m_retxSeqs.erase(m_retxSeqs.begin());
153 NS_LOG_DEBUG(
"=interest seq " << seq <<
" from m_retxSeqs");
157 if (seq == std::numeric_limits<uint32_t>::max())
159 if (
m_seqMax != std::numeric_limits<uint32_t>::max()) {
172 shared_ptr<Name> nameWithSequence = make_shared<Name>(
m_interestName);
173 nameWithSequence->appendSequenceNumber(seq);
176 shared_ptr<Interest> interest = make_shared<Interest>();
177 interest->setNonce(
m_rand->GetValue(0, std::numeric_limits<uint32_t>::max()));
178 interest->setName(*nameWithSequence);
181 NS_LOG_INFO(
"> Interest for " << seq <<
", Total: " <<
m_seq <<
", face: " <<
m_face->getId());
182 NS_LOG_DEBUG(
"Trying to add " << seq <<
" with " << Simulator::Now() <<
". already " 183 << m_seqTimeouts.size() <<
" items");
185 m_seqTimeouts.insert(SeqTimeout(seq, Simulator::Now()));
186 m_seqFullDelay.insert(SeqTimeout(seq, Simulator::Now()));
188 m_seqLastDelay.erase(seq);
189 m_seqLastDelay.insert(SeqTimeout(seq, Simulator::Now()));
191 m_seqRetxCounts[seq]++;
193 m_rtt->SentSeq(SequenceNumber32(seq), 1);
196 m_face->onReceiveInterest(*interest);
204 uint32_t content_index = 1;
207 double p_random = m_seqRng->GetValue();
208 while (p_random == 0) {
209 p_random = m_seqRng->GetValue();
212 NS_LOG_LOGIC(
"p_random=" << p_random);
213 for (uint32_t i = 1; i <= m_N; i++) {
216 if (p_random <= p_sum) {
222 NS_LOG_DEBUG(
"RandomNumber=" << content_index);
223 return content_index;
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)
uint32_t m_seq
currently requested sequence number
virtual void SendPacket()
shared_ptr< AppFace > m_face
automatically created application face through which application communicates
Ptr< RttEstimator > m_rtt
RTT estimator.
Name m_interestName
NDN Name of the Interest (use Name)
Ndn application for sending out Interest packets at a "constant" rate (Poisson process) ...
virtual void ScheduleNextPacket()
Constructs the Interest packet and sends it using a callback to the underlying NDN protocol...
ndn ConsumerZipfMandelbrot
Copyright (c) 2011-2015 Tsinghua University, P.R.China.
Copyright (c) 2011-2015 Regents of the University of California.
TracedCallback< shared_ptr< const Interest >, Ptr< App >, shared_ptr< Face > > m_transmittedInterests
App-level trace of transmitted Interests.
Ptr< UniformRandomVariable > m_rand
nonce generator
virtual ~ConsumerZipfMandelbrot()
ConsumerZipfMandelbrot()
Default constructor Sets up randomized Number Generator (RNG) Note: m_seq of its parent class Consume...
EventId m_sendEvent
EventId of pending "send packet" event.
bool m_active
Flag to indicate that application is active (set by StartApplication and StopApplication) ...
static TypeId GetTypeId()