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