blob: 5ba9b58d75e9f685e75cb22acea8c6dc2bde4a61 [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * 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.
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * 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.
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * 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 **/
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070019
20#ifndef NDN_CONTENT_STORE_WITH_PROBABILITY_H_
21#define NDN_CONTENT_STORE_WITH_PROBABILITY_H_
22
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070023#include "ns3/ndnSIM/model/ndn-common.hpp"
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070024
Alexander Afanasyev0c395372014-12-20 15:54:02 -080025#include "content-store-impl.hpp"
26
27#include "../../utils/trie/multi-policy.hpp"
28#include "custom-policies/probability-policy.hpp"
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070029#include "ns3/double.h"
30#include "ns3/type-id.h"
31
32namespace ns3 {
33namespace ndn {
34namespace cs {
35
36/**
37 * @ingroup ndn-cs
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080038 * @brief Special content store realization that probabilistically accepts data packet
39 * into CS (placement policy)
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070040 */
41template<class Policy>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080042class ContentStoreWithProbability
43 : public ContentStoreImpl<ndnSIM::multi_policy_traits<boost::mpl::
44 vector2<ndnSIM::probability_policy_traits,
45 Policy>>> {
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070046public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 typedef ContentStoreImpl<ndnSIM::multi_policy_traits<boost::mpl::
48 vector2<ndnSIM::probability_policy_traits,
49 Policy>>> super;
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070050
51 typedef typename super::policy_container::template index<0>::type probability_policy_container;
52
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 ContentStoreWithProbability(){};
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070054
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055 static TypeId
56 GetTypeId();
57
58private:
59 void
60 SetCacheProbability(double probability)
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070061 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 this->getPolicy().template get<probability_policy_container>().set_probability(probability);
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070063 }
64
65 double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 GetCacheProbability() const
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070067 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 return this->getPolicy().template get<probability_policy_container>().get_probability();
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070069 }
70};
71
72//////////////////////////////////////////
73////////// Implementation ////////////////
74//////////////////////////////////////////
75
76template<class Policy>
77TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078ContentStoreWithProbability<Policy>::GetTypeId()
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070079{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 static TypeId tid =
81 TypeId(("ns3::ndn::cs::Probability::" + Policy::GetName()).c_str())
82 .SetGroupName("Ndn")
83 .SetParent<super>()
84 .template AddConstructor<ContentStoreWithProbability<Policy>>()
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070085
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 .AddAttribute("CacheProbability",
87 "Set probability of caching in ContentStore. "
88 "If 1, every content is cached. If 0, no content is cached.",
89 DoubleValue(1.0), //(+)
90 MakeDoubleAccessor(&ContentStoreWithProbability<Policy>::GetCacheProbability,
91 &ContentStoreWithProbability<Policy>::SetCacheProbability),
92 MakeDoubleChecker<double>());
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070093
94 return tid;
95}
96
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070097} // namespace cs
98} // namespace ndn
99} // namespace ns3
100
101#endif // NDN_CONTENT_STORE_WITH_PROBABILITY_H_