blob: 89be9d1cc3d61cf38b2e1bc89e2f75eafad74d91 [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
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070024#include "ns3/ndnSIM/model/ndn-common.hpp"
25
Alexander Afanasyev0c395372014-12-20 15:54:02 -080026#include "ndn-consumer.hpp"
Mickey Sweatt89046c12014-11-16 20:32:27 -080027#include "ndn-consumer-cbr.hpp"
28
Shockb0f83152012-12-25 14:16:47 +080029#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"
Shockb0f83152012-12-25 14:16:47 +080037#include "ns3/random-variable.h"
38
39namespace ns3 {
40namespace ndn {
41
42/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070043 * @ingroup ndn-apps
Shockb0f83152012-12-25 14:16:47 +080044 * @brief NDN app requesting contents following Zipf-Mandelbrot Distbituion
45 *
46 * The class implements an app which requests contents following Zipf-Mandelbrot Distribution
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 * Here is the explaination of Zipf-Mandelbrot Distribution:
48 *http://en.wikipedia.org/wiki/Zipf%E2%80%93Mandelbrot_law
Shockb0f83152012-12-25 14:16:47 +080049 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050class ConsumerZipfMandelbrot : public ConsumerCbr {
Shockb0f83152012-12-25 14:16:47 +080051public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 static TypeId
53 GetTypeId();
Shockb0f83152012-12-25 14:16:47 +080054
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 Afanasyevbe55cf62014-12-20 17:51:09 -080060 ConsumerZipfMandelbrot();
61 virtual ~ConsumerZipfMandelbrot();
Shockb0f83152012-12-25 14:16:47 +080062
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 virtual void
64 SendPacket();
65 uint32_t
66 GetNextSeq();
Shockb0f83152012-12-25 14:16:47 +080067
68protected:
Alexander Afanasyev13800102012-12-25 00:30:31 -080069 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 ScheduleNextPacket();
Shockb0f83152012-12-25 14:16:47 +080071
72private:
Alexander Afanasyev13800102012-12-25 00:30:31 -080073 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 SetNumberOfContents(uint32_t numOfContents);
Shockb0f83152012-12-25 14:16:47 +080075
Alexander Afanasyev13800102012-12-25 00:30:31 -080076 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 GetNumberOfContents() const;
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080078
79 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 SetQ(double q);
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080081
82 double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 GetQ() const;
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080084
85 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 SetS(double s);
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080087
88 double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 GetS() const;
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080090
Alexander Afanasyev13800102012-12-25 00:30:31 -080091private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 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
Shockb0f83152012-12-25 14:16:47 +080096
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080097 UniformVariable m_SeqRng; // RNG
Shockb0f83152012-12-25 14:16:47 +080098};
99
100} /* namespace ndn */
101} /* namespace ns3 */
102#endif /* NDN_CONSUMER_ZIPF_MANDELBROT_H_ */