28 NS_LOG_COMPONENT_DEFINE(
"ndn.ConsumerZipfMandelbrot");
39 TypeId(
"ns3::ndn::ConsumerZipfMandelbrot")
42 .AddConstructor<ConsumerZipfMandelbrot>()
44 .AddAttribute(
"NumberOfContents",
"Number of the Contents in total", StringValue(
"100"),
45 MakeUintegerAccessor(&ConsumerZipfMandelbrot::SetNumberOfContents,
46 &ConsumerZipfMandelbrot::GetNumberOfContents),
47 MakeUintegerChecker<uint32_t>())
49 .AddAttribute(
"q",
"parameter of improve rank", StringValue(
"0.7"),
50 MakeDoubleAccessor(&ConsumerZipfMandelbrot::SetQ,
51 &ConsumerZipfMandelbrot::GetQ),
52 MakeDoubleChecker<double>())
54 .AddAttribute(
"s",
"parameter of power", StringValue(
"0.7"),
55 MakeDoubleAccessor(&ConsumerZipfMandelbrot::SetS,
56 &ConsumerZipfMandelbrot::GetS),
57 MakeDoubleChecker<double>());
66 , m_seqRng(CreateObject<UniformRandomVariable>())
76 ConsumerZipfMandelbrot::SetNumberOfContents(uint32_t numOfContents)
80 NS_LOG_DEBUG(m_q <<
" and " << m_s <<
" and " << m_N);
82 m_Pcum = std::vector<double>(m_N + 1);
85 for (uint32_t i = 1; i <= m_N; i++) {
86 m_Pcum[i] = m_Pcum[i - 1] + 1.0 / std::pow(i + m_q, m_s);
89 for (uint32_t i = 1; i <= m_N; i++) {
90 m_Pcum[i] = m_Pcum[i] / m_Pcum[m_N];
91 NS_LOG_LOGIC(
"Cumulative probability [" << i <<
"]=" << m_Pcum[i]);
96 ConsumerZipfMandelbrot::GetNumberOfContents()
const 102 ConsumerZipfMandelbrot::SetQ(
double q)
105 SetNumberOfContents(m_N);
109 ConsumerZipfMandelbrot::GetQ()
const 115 ConsumerZipfMandelbrot::SetS(
double s)
118 SetNumberOfContents(m_N);
122 ConsumerZipfMandelbrot::GetS()
const 133 NS_LOG_FUNCTION_NOARGS();
135 uint32_t seq = std::numeric_limits<uint32_t>::max();
139 while (m_retxSeqs.size()) {
140 seq = *m_retxSeqs.begin();
141 m_retxSeqs.erase(m_retxSeqs.begin());
152 NS_LOG_DEBUG(
"=interest seq " << seq <<
" from m_retxSeqs");
156 if (seq == std::numeric_limits<uint32_t>::max())
158 if (
m_seqMax != std::numeric_limits<uint32_t>::max()) {
171 shared_ptr<Name> nameWithSequence = make_shared<Name>(
m_interestName);
172 nameWithSequence->appendSequenceNumber(seq);
175 shared_ptr<Interest> interest = make_shared<Interest>();
176 interest->setNonce(
m_rand->GetValue(0, std::numeric_limits<uint32_t>::max()));
177 interest->setName(*nameWithSequence);
180 NS_LOG_INFO(
"> Interest for " << seq <<
", Total: " <<
m_seq <<
", face: " <<
m_face->getId());
181 NS_LOG_DEBUG(
"Trying to add " << seq <<
" with " << Simulator::Now() <<
". already " 182 << m_seqTimeouts.size() <<
" items");
184 m_seqTimeouts.insert(SeqTimeout(seq, Simulator::Now()));
185 m_seqFullDelay.insert(SeqTimeout(seq, Simulator::Now()));
187 m_seqLastDelay.erase(seq);
188 m_seqLastDelay.insert(SeqTimeout(seq, Simulator::Now()));
190 m_seqRetxCounts[seq]++;
192 m_rtt->SentSeq(SequenceNumber32(seq), 1);
203 uint32_t content_index = 1;
206 double p_random = m_seqRng->GetValue();
207 while (p_random == 0) {
208 p_random = m_seqRng->GetValue();
211 NS_LOG_LOGIC(
"p_random=" << p_random);
212 for (uint32_t i = 1; i <= m_N; i++) {
215 if (p_random <= p_sum) {
221 NS_LOG_DEBUG(
"RandomNumber=" << content_index);
222 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()
void onReceiveInterest(const Interest &interest)
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.
shared_ptr< Face > m_face
AppLinkService * m_appLink
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()