blob: dd03563892b14a78eb356eadf290373e1b28e351 [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"
Shockb0f83152012-12-25 14:16:47 +080027#include "ns3/ptr.h"
28#include "ns3/log.h"
29#include "ns3/simulator.h"
30#include "ns3/packet.h"
31#include "ns3/callback.h"
32#include "ns3/string.h"
33#include "ns3/uinteger.h"
34#include "ns3/double.h"
Alexander Afanasyev0c395372014-12-20 15:54:02 -080035#include "ndn-consumer-cbr.hpp"
Shockb0f83152012-12-25 14:16:47 +080036#include "ns3/random-variable.h"
37
38namespace ns3 {
39namespace ndn {
40
41/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070042 * @ingroup ndn-apps
Shockb0f83152012-12-25 14:16:47 +080043 * @brief NDN app requesting contents following Zipf-Mandelbrot Distbituion
44 *
45 * The class implements an app which requests contents following Zipf-Mandelbrot Distribution
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080046 * Here is the explaination of Zipf-Mandelbrot Distribution:
47 *http://en.wikipedia.org/wiki/Zipf%E2%80%93Mandelbrot_law
Shockb0f83152012-12-25 14:16:47 +080048 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049class ConsumerZipfMandelbrot : public ConsumerCbr {
Shockb0f83152012-12-25 14:16:47 +080050public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051 static TypeId
52 GetTypeId();
Shockb0f83152012-12-25 14:16:47 +080053
54 /**
55 * \brief Default constructor
56 * Sets up randomized Number Generator (RNG)
57 * Note: m_seq of its parent class ConsumerCbr here is used to record the interest number
58 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 ConsumerZipfMandelbrot();
60 virtual ~ConsumerZipfMandelbrot();
Shockb0f83152012-12-25 14:16:47 +080061
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 virtual void
63 SendPacket();
64 uint32_t
65 GetNextSeq();
Shockb0f83152012-12-25 14:16:47 +080066
67protected:
Alexander Afanasyev13800102012-12-25 00:30:31 -080068 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 ScheduleNextPacket();
Shockb0f83152012-12-25 14:16:47 +080070
71private:
Alexander Afanasyev13800102012-12-25 00:30:31 -080072 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 SetNumberOfContents(uint32_t numOfContents);
Shockb0f83152012-12-25 14:16:47 +080074
Alexander Afanasyev13800102012-12-25 00:30:31 -080075 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 GetNumberOfContents() const;
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080077
78 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079 SetQ(double q);
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080080
81 double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 GetQ() const;
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080083
84 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 SetS(double s);
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080086
87 double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080088 GetS() const;
Saran Tarnoi5cd9a152013-02-15 15:59:15 -080089
Alexander Afanasyev13800102012-12-25 00:30:31 -080090private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 uint32_t m_N; // number of the contents
92 double m_q; // q in (k+q)^s
93 double m_s; // s in (k+q)^s
94 std::vector<double> m_Pcum; // cumulative probability
Shockb0f83152012-12-25 14:16:47 +080095
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 UniformVariable m_SeqRng; // RNG
Shockb0f83152012-12-25 14:16:47 +080097};
98
99} /* namespace ndn */
100} /* namespace ns3 */
101#endif /* NDN_CONSUMER_ZIPF_MANDELBROT_H_ */