Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012-2013 University of California, Los Angeles |
| 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #ifndef NDN_CONTENT_STORE_WITH_PROBABILITY_H_ |
| 22 | #define NDN_CONTENT_STORE_WITH_PROBABILITY_H_ |
| 23 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame^] | 24 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 26 | #include "content-store-impl.hpp" |
| 27 | |
| 28 | #include "../../utils/trie/multi-policy.hpp" |
| 29 | #include "custom-policies/probability-policy.hpp" |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 30 | #include "ns3/double.h" |
| 31 | #include "ns3/type-id.h" |
| 32 | |
| 33 | namespace ns3 { |
| 34 | namespace ndn { |
| 35 | namespace cs { |
| 36 | |
| 37 | /** |
| 38 | * @ingroup ndn-cs |
| 39 | * @brief Special content store realization that honors Freshness parameter in Data packets |
| 40 | */ |
| 41 | template<class Policy> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 42 | class ContentStoreWithProbability |
| 43 | : public ContentStoreImpl<ndnSIM::multi_policy_traits<boost::mpl:: |
| 44 | vector2<ndnSIM::probability_policy_traits, |
| 45 | Policy>>> { |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 46 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 47 | typedef ContentStoreImpl<ndnSIM::multi_policy_traits<boost::mpl:: |
| 48 | vector2<ndnSIM::probability_policy_traits, |
| 49 | Policy>>> super; |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 50 | |
| 51 | typedef typename super::policy_container::template index<0>::type probability_policy_container; |
| 52 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 53 | ContentStoreWithProbability(){}; |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 54 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 55 | static TypeId |
| 56 | GetTypeId(); |
| 57 | |
| 58 | private: |
| 59 | void |
| 60 | SetCacheProbability(double probability) |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 61 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | this->getPolicy().template get<probability_policy_container>().set_probability(probability); |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | double |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 66 | GetCacheProbability() const |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 67 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 68 | return this->getPolicy().template get<probability_policy_container>().get_probability(); |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 69 | } |
| 70 | }; |
| 71 | |
| 72 | ////////////////////////////////////////// |
| 73 | ////////// Implementation //////////////// |
| 74 | ////////////////////////////////////////// |
| 75 | |
| 76 | template<class Policy> |
| 77 | TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 78 | ContentStoreWithProbability<Policy>::GetTypeId() |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 79 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 80 | 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 Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 85 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | .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 Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 93 | |
| 94 | return tid; |
| 95 | } |
| 96 | |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 97 | } // namespace cs |
| 98 | } // namespace ndn |
| 99 | } // namespace ns3 |
| 100 | |
| 101 | #endif // NDN_CONTENT_STORE_WITH_PROBABILITY_H_ |