21 #include "ndn-consumer-zipf-mandelbrot.h"
23 #include "ns3/ndn-app-face.h"
24 #include "ns3/ndn-interest.h"
25 #include "ns3/ndn-data.h"
27 #include "ns3/ndnSIM/utils/ndn-fw-hop-count-tag.h"
32 NS_LOG_COMPONENT_DEFINE (
"ndn.ConsumerZipfMandelbrot");
37 NS_OBJECT_ENSURE_REGISTERED (ConsumerZipfMandelbrot);
40 ConsumerZipfMandelbrot::GetTypeId (
void)
42 static TypeId tid = TypeId (
"ns3::ndn::ConsumerZipfMandelbrot")
45 .AddConstructor<ConsumerZipfMandelbrot> ()
47 .AddAttribute (
"NumberOfContents",
"Number of the Contents in total",
49 MakeUintegerAccessor (&ConsumerZipfMandelbrot::SetNumberOfContents, &ConsumerZipfMandelbrot::GetNumberOfContents),
50 MakeUintegerChecker<uint32_t> ())
52 .AddAttribute (
"q",
"parameter of improve rank",
54 MakeDoubleAccessor (&ConsumerZipfMandelbrot::SetQ, &ConsumerZipfMandelbrot::GetQ),
55 MakeDoubleChecker<double> ())
57 .AddAttribute (
"s",
"parameter of power",
59 MakeDoubleAccessor (&ConsumerZipfMandelbrot::SetS, &ConsumerZipfMandelbrot::GetS),
60 MakeDoubleChecker<double> ())
76 ConsumerZipfMandelbrot::~ConsumerZipfMandelbrot()
81 ConsumerZipfMandelbrot::SetNumberOfContents (uint32_t numOfContents)
85 NS_LOG_DEBUG (m_q <<
" and " << m_s <<
" and " << m_N);
87 m_Pcum = std::vector<double> (m_N + 1);
90 for (uint32_t i=1; i<=m_N; i++)
92 m_Pcum[i] = m_Pcum[i-1] + 1.0 / std::pow(i+m_q, m_s);
95 for (uint32_t i=1; i<=m_N; i++)
97 m_Pcum[i] = m_Pcum[i] / m_Pcum[m_N];
98 NS_LOG_LOGIC (
"Cumulative probability [" << i <<
"]=" << m_Pcum[i]);
103 ConsumerZipfMandelbrot::GetNumberOfContents ()
const
109 ConsumerZipfMandelbrot::SetQ (
double q)
112 SetNumberOfContents (m_N);
116 ConsumerZipfMandelbrot::GetQ ()
const
122 ConsumerZipfMandelbrot::SetS (
double s)
125 SetNumberOfContents (m_N);
129 ConsumerZipfMandelbrot::GetS ()
const
135 ConsumerZipfMandelbrot::SendPacket() {
138 NS_LOG_FUNCTION_NOARGS ();
140 uint32_t seq=std::numeric_limits<uint32_t>::max ();
144 while (m_retxSeqs.size ())
146 seq = *m_retxSeqs.begin ();
147 m_retxSeqs.erase (m_retxSeqs.begin ());
157 NS_LOG_DEBUG(
"=interest seq "<<seq<<
" from m_retxSeqs");
161 if (seq == std::numeric_limits<uint32_t>::max ())
163 if (
m_seqMax != std::numeric_limits<uint32_t>::max ())
171 seq = ConsumerZipfMandelbrot::GetNextSeq();
179 nameWithSequence->appendSeqNum (seq);
182 Ptr<Interest> interest = Create<Interest> ();
183 interest->SetNonce (
m_rand.GetValue ());
184 interest->SetName (nameWithSequence);
187 NS_LOG_INFO (
"> Interest for " << seq<<
", Total: "<<
m_seq<<
", face: "<<
m_face->GetId());
188 NS_LOG_DEBUG (
"Trying to add " << seq <<
" with " << Simulator::Now () <<
". already " << m_seqTimeouts.size () <<
" items");
190 m_seqTimeouts.insert (SeqTimeout (seq, Simulator::Now ()));
191 m_seqFullDelay.insert (SeqTimeout (seq, Simulator::Now ()));
193 m_seqLastDelay.erase (seq);
194 m_seqLastDelay.insert (SeqTimeout (seq, Simulator::Now ()));
196 m_seqRetxCounts[seq] ++;
198 m_rtt->SentSeq (SequenceNumber32 (seq), 1);
200 FwHopCountTag hopCountTag;
201 interest->GetPayload ()->AddPacketTag (hopCountTag);
204 m_face->ReceiveInterest (interest);
211 ConsumerZipfMandelbrot::GetNextSeq()
213 uint32_t content_index = 1;
216 double p_random = m_SeqRng.GetValue();
217 while (p_random == 0)
219 p_random = m_SeqRng.GetValue();
222 NS_LOG_LOGIC(
"p_random="<<p_random);
223 for (uint32_t i=1; i<=m_N; i++)
226 if (p_random <= p_sum)
233 NS_LOG_DEBUG(
"RandomNumber="<<content_index);
234 return content_index;
243 &ConsumerZipfMandelbrot::SendPacket,
this);
249 Seconds(1.0 / m_frequency)
251 Seconds(m_random->GetValue ()),
252 &ConsumerZipfMandelbrot::SendPacket,
this);
bool m_active
Flag to indicate that application is active (set by StartApplication and StopApplication) ...
ConsumerZipfMandelbrot()
Default constructor Sets up randomized Number Generator (RNG) Note: m_seq of its parent class Consume...
ConsumerCbr()
Default constructor Sets up randomizer function and packet sequence number.
Name m_interestName
NDN Name of the Interest (use Name)
TracedCallback< Ptr< const Interest >, Ptr< App >, Ptr< Face > > m_transmittedInterests
App-level trace of transmitted Interests.
UniformVariable m_rand
nonce generator
EventId m_sendEvent
EventId of pending "send packet" event.
Ptr< RttEstimator > m_rtt
RTT estimator.
uint32_t m_seqMax
maximum number of sequence number
virtual void ScheduleNextPacket()
Constructs the Interest packet and sends it using a callback to the underlying NDN protocol...
uint32_t m_seq
currently requested sequence number
Ptr< Face > m_face
automatically created application face through which application communicates