26 NS_LOG_COMPONENT_DEFINE(
"ndn.ConsumerZipfMandelbrot");
37 TypeId(
"ns3::ndn::ConsumerZipfMandelbrot")
40 .AddConstructor<ConsumerZipfMandelbrot>()
42 .AddAttribute(
"NumberOfContents",
"Number of the Contents in total", StringValue(
"100"),
43 MakeUintegerAccessor(&ConsumerZipfMandelbrot::SetNumberOfContents,
44 &ConsumerZipfMandelbrot::GetNumberOfContents),
45 MakeUintegerChecker<uint32_t>())
47 .AddAttribute(
"q",
"parameter of improve rank", StringValue(
"0.7"),
48 MakeDoubleAccessor(&ConsumerZipfMandelbrot::SetQ,
49 &ConsumerZipfMandelbrot::GetQ),
50 MakeDoubleChecker<double>())
52 .AddAttribute(
"s",
"parameter of power", StringValue(
"0.7"),
53 MakeDoubleAccessor(&ConsumerZipfMandelbrot::SetS,
54 &ConsumerZipfMandelbrot::GetS),
55 MakeDoubleChecker<double>());
64 , m_seqRng(CreateObject<UniformRandomVariable>())
74 ConsumerZipfMandelbrot::SetNumberOfContents(uint32_t numOfContents)
78 NS_LOG_DEBUG(m_q <<
" and " << m_s <<
" and " << m_N);
80 m_Pcum = std::vector<double>(m_N + 1);
83 for (uint32_t i = 1; i <= m_N; i++) {
84 m_Pcum[i] = m_Pcum[i - 1] + 1.0 / std::pow(i + m_q, m_s);
87 for (uint32_t i = 1; i <= m_N; i++) {
88 m_Pcum[i] = m_Pcum[i] / m_Pcum[m_N];
89 NS_LOG_LOGIC(
"Cumulative probability [" << i <<
"]=" << m_Pcum[i]);
94 ConsumerZipfMandelbrot::GetNumberOfContents()
const
100 ConsumerZipfMandelbrot::SetQ(
double q)
103 SetNumberOfContents(m_N);
107 ConsumerZipfMandelbrot::GetQ()
const
113 ConsumerZipfMandelbrot::SetS(
double s)
116 SetNumberOfContents(m_N);
120 ConsumerZipfMandelbrot::GetS()
const
131 NS_LOG_FUNCTION_NOARGS();
133 uint32_t seq = std::numeric_limits<uint32_t>::max();
137 while (m_retxSeqs.size()) {
138 seq = *m_retxSeqs.begin();
139 m_retxSeqs.erase(m_retxSeqs.begin());
150 NS_LOG_DEBUG(
"=interest seq " << seq <<
" from m_retxSeqs");
154 if (seq == std::numeric_limits<uint32_t>::max())
156 if (
m_seqMax != std::numeric_limits<uint32_t>::max()) {
169 shared_ptr<Name> nameWithSequence = make_shared<Name>(
m_interestName);
170 nameWithSequence->appendSequenceNumber(seq);
173 shared_ptr<Interest> interest = make_shared<Interest>();
174 interest->setNonce(
m_rand->GetValue(0, std::numeric_limits<uint32_t>::max()));
175 interest->setName(*nameWithSequence);
178 NS_LOG_INFO(
"> Interest for " << seq <<
", Total: " <<
m_seq <<
", face: " <<
m_face->getId());
179 NS_LOG_DEBUG(
"Trying to add " << seq <<
" with " << Simulator::Now() <<
". already "
180 << m_seqTimeouts.size() <<
" items");
182 m_seqTimeouts.insert(SeqTimeout(seq, Simulator::Now()));
183 m_seqFullDelay.insert(SeqTimeout(seq, Simulator::Now()));
185 m_seqLastDelay.erase(seq);
186 m_seqLastDelay.insert(SeqTimeout(seq, Simulator::Now()));
188 m_seqRetxCounts[seq]++;
190 m_rtt->SentSeq(SequenceNumber32(seq), 1);
201 uint32_t content_index = 1;
204 double p_random = m_seqRng->GetValue();
205 while (p_random == 0) {
206 p_random = m_seqRng->GetValue();
209 NS_LOG_LOGIC(
"p_random=" << p_random);
210 for (uint32_t i = 1; i <= m_N; i++) {
213 if (p_random <= p_sum) {
219 NS_LOG_DEBUG(
"RandomNumber=" << content_index);
220 return content_index;