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 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 24 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
| 25 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 26 | #include "ndn-consumer.hpp" |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 27 | #include "ns3/ptr.h" |
| 28 | #include "ns3/log.h" |
| 29 | #include "ns3/simulator.h" |
| 30 | #include "ns3/packet.h" |
| 31 | #include "ns3/callback.h" |
| 32 | #include "ns3/string.h" |
| 33 | #include "ns3/uinteger.h" |
| 34 | #include "ns3/double.h" |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 35 | #include "ndn-consumer-cbr.hpp" |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 36 | #include "ns3/random-variable.h" |
| 37 | |
| 38 | namespace ns3 { |
| 39 | namespace ndn { |
| 40 | |
| 41 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 42 | * @ingroup ndn-apps |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 43 | * @brief NDN app requesting contents following Zipf-Mandelbrot Distbituion |
| 44 | * |
| 45 | * The class implements an app which requests contents following Zipf-Mandelbrot Distribution |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 46 | * Here is the explaination of Zipf-Mandelbrot Distribution: |
| 47 | *http://en.wikipedia.org/wiki/Zipf%E2%80%93Mandelbrot_law |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 48 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 49 | class ConsumerZipfMandelbrot : public ConsumerCbr { |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 50 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | static TypeId |
| 52 | GetTypeId(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * \brief Default constructor |
| 56 | * Sets up randomized Number Generator (RNG) |
| 57 | * Note: m_seq of its parent class ConsumerCbr here is used to record the interest number |
| 58 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 59 | ConsumerZipfMandelbrot(); |
| 60 | virtual ~ConsumerZipfMandelbrot(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 61 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | virtual void |
| 63 | SendPacket(); |
| 64 | uint32_t |
| 65 | GetNextSeq(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 66 | |
| 67 | protected: |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 68 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 69 | ScheduleNextPacket(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 70 | |
| 71 | private: |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 72 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 73 | SetNumberOfContents(uint32_t numOfContents); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 74 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 75 | uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 76 | GetNumberOfContents() const; |
Saran Tarnoi | 5cd9a15 | 2013-02-15 15:59:15 -0800 | [diff] [blame] | 77 | |
| 78 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 79 | SetQ(double q); |
Saran Tarnoi | 5cd9a15 | 2013-02-15 15:59:15 -0800 | [diff] [blame] | 80 | |
| 81 | double |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 82 | GetQ() const; |
Saran Tarnoi | 5cd9a15 | 2013-02-15 15:59:15 -0800 | [diff] [blame] | 83 | |
| 84 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 85 | SetS(double s); |
Saran Tarnoi | 5cd9a15 | 2013-02-15 15:59:15 -0800 | [diff] [blame] | 86 | |
| 87 | double |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 88 | GetS() const; |
Saran Tarnoi | 5cd9a15 | 2013-02-15 15:59:15 -0800 | [diff] [blame] | 89 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 90 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 91 | uint32_t m_N; // number of the contents |
| 92 | double m_q; // q in (k+q)^s |
| 93 | double m_s; // s in (k+q)^s |
| 94 | std::vector<double> m_Pcum; // cumulative probability |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 95 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 96 | UniformVariable m_SeqRng; // RNG |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | } /* namespace ndn */ |
| 100 | } /* namespace ns3 */ |
| 101 | #endif /* NDN_CONSUMER_ZIPF_MANDELBROT_H_ */ |