Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 Tsinghua University, P.R.China |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Xiaoke Jiang <shock.jiang@gmail.com> |
| 19 | */ |
| 20 | |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 21 | #ifndef NDN_CONSUMER_ZIPF_MANDELBROT_H_ |
| 22 | #define NDN_CONSUMER_ZIPF_MANDELBROT_H_ |
| 23 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 24 | #include "ndn-consumer.hpp" |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 25 | #include "ns3/ptr.h" |
| 26 | #include "ns3/log.h" |
| 27 | #include "ns3/simulator.h" |
| 28 | #include "ns3/packet.h" |
| 29 | #include "ns3/callback.h" |
| 30 | #include "ns3/string.h" |
| 31 | #include "ns3/uinteger.h" |
| 32 | #include "ns3/double.h" |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 33 | #include "ndn-consumer-cbr.hpp" |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 34 | #include "ns3/random-variable.h" |
| 35 | |
| 36 | namespace ns3 { |
| 37 | namespace ndn { |
| 38 | |
| 39 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 40 | * @ingroup ndn-apps |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 41 | * @brief NDN app requesting contents following Zipf-Mandelbrot Distbituion |
| 42 | * |
| 43 | * The class implements an app which requests contents following Zipf-Mandelbrot Distribution |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 44 | * Here is the explaination of Zipf-Mandelbrot Distribution: |
| 45 | *http://en.wikipedia.org/wiki/Zipf%E2%80%93Mandelbrot_law |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 46 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 47 | class ConsumerZipfMandelbrot : public ConsumerCbr { |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 48 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 49 | static TypeId |
| 50 | GetTypeId(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * \brief Default constructor |
| 54 | * Sets up randomized Number Generator (RNG) |
| 55 | * Note: m_seq of its parent class ConsumerCbr here is used to record the interest number |
| 56 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 57 | ConsumerZipfMandelbrot(); |
| 58 | virtual ~ConsumerZipfMandelbrot(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 60 | virtual void |
| 61 | SendPacket(); |
| 62 | uint32_t |
| 63 | GetNextSeq(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 64 | |
| 65 | protected: |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 66 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 67 | ScheduleNextPacket(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 68 | |
| 69 | private: |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 70 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | SetNumberOfContents(uint32_t numOfContents); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 72 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 73 | uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 74 | GetNumberOfContents() const; |
Saran Tarnoi | 5cd9a15 | 2013-02-15 15:59:15 -0800 | [diff] [blame] | 75 | |
| 76 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 77 | SetQ(double q); |
Saran Tarnoi | 5cd9a15 | 2013-02-15 15:59:15 -0800 | [diff] [blame] | 78 | |
| 79 | double |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 80 | GetQ() const; |
Saran Tarnoi | 5cd9a15 | 2013-02-15 15:59:15 -0800 | [diff] [blame] | 81 | |
| 82 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 83 | SetS(double s); |
Saran Tarnoi | 5cd9a15 | 2013-02-15 15:59:15 -0800 | [diff] [blame] | 84 | |
| 85 | double |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | GetS() const; |
Saran Tarnoi | 5cd9a15 | 2013-02-15 15:59:15 -0800 | [diff] [blame] | 87 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 88 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 89 | uint32_t m_N; // number of the contents |
| 90 | double m_q; // q in (k+q)^s |
| 91 | double m_s; // s in (k+q)^s |
| 92 | std::vector<double> m_Pcum; // cumulative probability |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 93 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 94 | UniformVariable m_SeqRng; // RNG |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | } /* namespace ndn */ |
| 98 | } /* namespace ns3 */ |
| 99 | #endif /* NDN_CONSUMER_ZIPF_MANDELBROT_H_ */ |