blob: ee192dbf0d750bd2f29b1f469511940672e83b1f [file] [log] [blame]
Shockb0f83152012-12-25 14:16:47 +08001/* -*- 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
Shockb0f83152012-12-25 14:16:47 +080021#ifndef NDN_CONSUMER_ZIPF_MANDELBROT_H_
22#define NDN_CONSUMER_ZIPF_MANDELBROT_H_
23
Alexander Afanasyev0c395372014-12-20 15:54:02 -080024#include "ndn-consumer.hpp"
Shockb0f83152012-12-25 14:16:47 +080025#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 Afanasyev0c395372014-12-20 15:54:02 -080033#include "ndn-consumer-cbr.hpp"
Shockb0f83152012-12-25 14:16:47 +080034#include "ns3/random-variable.h"
35
36namespace ns3 {
37namespace ndn {
38
39/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070040 * @ingroup ndn-apps
Shockb0f83152012-12-25 14:16:47 +080041 * @brief NDN app requesting contents following Zipf-Mandelbrot Distbituion
42 *
43 * The class implements an app which requests contents following Zipf-Mandelbrot Distribution
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080044 * Here is the explaination of Zipf-Mandelbrot Distribution:
45 *http://en.wikipedia.org/wiki/Zipf%E2%80%93Mandelbrot_law
Shockb0f83152012-12-25 14:16:47 +080046 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047class ConsumerZipfMandelbrot : public ConsumerCbr {
Shockb0f83152012-12-25 14:16:47 +080048public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049 static TypeId
50 GetTypeId();
Shockb0f83152012-12-25 14:16:47 +080051
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 Afanasyevbe55cf62014-12-20 17:51:09 -080057 ConsumerZipfMandelbrot();
58 virtual ~ConsumerZipfMandelbrot();
Shockb0f83152012-12-25 14:16:47 +080059
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080060 virtual void
61 SendPacket();
62 uint32_t
63 GetNextSeq();
Shockb0f83152012-12-25 14:16:47 +080064
65protected:
Alexander Afanasyev13800102012-12-25 00:30:31 -080066 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 ScheduleNextPacket();
Shockb0f83152012-12-25 14:16:47 +080068
69private:
Alexander Afanasyev13800102012-12-25 00:30:31 -080070 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 SetNumberOfContents(uint32_t numOfContents);
Shockb0f83152012-12-25 14:16:47 +080072
Alexander Afanasyev13800102012-12-25 00:30:31 -080073 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 GetNumberOfContents() const;
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080075
76 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 SetQ(double q);
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080078
79 double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 GetQ() const;
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080081
82 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 SetS(double s);
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080084
85 double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 GetS() const;
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080087
Alexander Afanasyev13800102012-12-25 00:30:31 -080088private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 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
Shockb0f83152012-12-25 14:16:47 +080093
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094 UniformVariable m_SeqRng; // RNG
Shockb0f83152012-12-25 14:16:47 +080095};
96
97} /* namespace ndn */
98} /* namespace ns3 */
99#endif /* NDN_CONSUMER_ZIPF_MANDELBROT_H_ */