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