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 | |
| 21 | |
| 22 | #ifndef NDN_CONSUMER_ZIPF_MANDELBROT_H_ |
| 23 | #define NDN_CONSUMER_ZIPF_MANDELBROT_H_ |
| 24 | |
| 25 | #include "ndn-consumer.h" |
| 26 | #include "ns3/ptr.h" |
| 27 | #include "ns3/log.h" |
| 28 | #include "ns3/simulator.h" |
| 29 | #include "ns3/packet.h" |
| 30 | #include "ns3/callback.h" |
| 31 | #include "ns3/string.h" |
| 32 | #include "ns3/uinteger.h" |
| 33 | #include "ns3/double.h" |
| 34 | #include "ndn-consumer-cbr.h" |
| 35 | #include "ns3/random-variable.h" |
| 36 | |
| 37 | namespace ns3 { |
| 38 | namespace ndn { |
| 39 | |
| 40 | /** |
| 41 | * @ingroup ndn |
| 42 | * @brief NDN app requesting contents following Zipf-Mandelbrot Distbituion |
| 43 | * |
| 44 | * The class implements an app which requests contents following Zipf-Mandelbrot Distribution |
| 45 | * Here is the explaination of Zipf-Mandelbrot Distribution: http://en.wikipedia.org/wiki/Zipf%E2%80%93Mandelbrot_law |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 46 | */ |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 47 | class ConsumerZipfMandelbrot: public ConsumerCbr |
| 48 | { |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 49 | public: |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 50 | static TypeId 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 | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 57 | ConsumerZipfMandelbrot (); |
| 58 | virtual ~ConsumerZipfMandelbrot (); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 60 | virtual void SendPacket(); |
| 61 | uint32_t GetNextSeq(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 62 | |
| 63 | protected: |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 64 | virtual void |
| 65 | ScheduleNextPacket (); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 66 | |
| 67 | private: |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 68 | void |
| 69 | SetNumberOfContents (uint32_t numOfContents); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 71 | uint32_t |
| 72 | GetNumberOfContents () const; |
Saran Tarnoi | 5cd9a15 | 2013-02-15 15:59:15 -0800 | [diff] [blame] | 73 | |
| 74 | void |
| 75 | SetQ (double q); |
| 76 | |
| 77 | double |
| 78 | GetQ () const; |
| 79 | |
| 80 | void |
| 81 | SetS (double s); |
| 82 | |
| 83 | double |
| 84 | GetS () const; |
| 85 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 86 | private: |
| 87 | uint32_t m_N; //number of the contents |
| 88 | double m_q; //q in (k+q)^s |
| 89 | double m_s; //s in (k+q)^s |
| 90 | std::vector<double> m_Pcum; //cumulative probability |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 91 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 92 | UniformVariable m_SeqRng; //RNG |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } /* namespace ndn */ |
| 96 | } /* namespace ns3 */ |
| 97 | #endif /* NDN_CONSUMER_ZIPF_MANDELBROT_H_ */ |