Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * 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 Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * 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 Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * 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 Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 19 | |
| 20 | #ifndef NDN_CONTENT_STORE_WITH_PROBABILITY_H_ |
| 21 | #define NDN_CONTENT_STORE_WITH_PROBABILITY_H_ |
| 22 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 23 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 25 | #include "content-store-impl.hpp" |
| 26 | |
| 27 | #include "../../utils/trie/multi-policy.hpp" |
| 28 | #include "custom-policies/probability-policy.hpp" |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 29 | #include "ns3/double.h" |
| 30 | #include "ns3/type-id.h" |
| 31 | |
| 32 | namespace ns3 { |
| 33 | namespace ndn { |
| 34 | namespace cs { |
| 35 | |
| 36 | /** |
| 37 | * @ingroup ndn-cs |
| 38 | * @brief Special content store realization that honors Freshness parameter in Data packets |
| 39 | */ |
| 40 | template<class Policy> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 41 | class ContentStoreWithProbability |
| 42 | : public ContentStoreImpl<ndnSIM::multi_policy_traits<boost::mpl:: |
| 43 | vector2<ndnSIM::probability_policy_traits, |
| 44 | Policy>>> { |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 45 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 46 | typedef ContentStoreImpl<ndnSIM::multi_policy_traits<boost::mpl:: |
| 47 | vector2<ndnSIM::probability_policy_traits, |
| 48 | Policy>>> super; |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 49 | |
| 50 | typedef typename super::policy_container::template index<0>::type probability_policy_container; |
| 51 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 52 | ContentStoreWithProbability(){}; |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 53 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 54 | static TypeId |
| 55 | GetTypeId(); |
| 56 | |
| 57 | private: |
| 58 | void |
| 59 | SetCacheProbability(double probability) |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 60 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 61 | this->getPolicy().template get<probability_policy_container>().set_probability(probability); |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | double |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 65 | GetCacheProbability() const |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 66 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 67 | return this->getPolicy().template get<probability_policy_container>().get_probability(); |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 68 | } |
| 69 | }; |
| 70 | |
| 71 | ////////////////////////////////////////// |
| 72 | ////////// Implementation //////////////// |
| 73 | ////////////////////////////////////////// |
| 74 | |
| 75 | template<class Policy> |
| 76 | TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 77 | ContentStoreWithProbability<Policy>::GetTypeId() |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 78 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 79 | static TypeId tid = |
| 80 | TypeId(("ns3::ndn::cs::Probability::" + Policy::GetName()).c_str()) |
| 81 | .SetGroupName("Ndn") |
| 82 | .SetParent<super>() |
| 83 | .template AddConstructor<ContentStoreWithProbability<Policy>>() |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 85 | .AddAttribute("CacheProbability", |
| 86 | "Set probability of caching in ContentStore. " |
| 87 | "If 1, every content is cached. If 0, no content is cached.", |
| 88 | DoubleValue(1.0), //(+) |
| 89 | MakeDoubleAccessor(&ContentStoreWithProbability<Policy>::GetCacheProbability, |
| 90 | &ContentStoreWithProbability<Policy>::SetCacheProbability), |
| 91 | MakeDoubleChecker<double>()); |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 92 | |
| 93 | return tid; |
| 94 | } |
| 95 | |
Alexander Afanasyev | cd31abd | 2013-09-05 20:45:02 -0700 | [diff] [blame] | 96 | } // namespace cs |
| 97 | } // namespace ndn |
| 98 | } // namespace ns3 |
| 99 | |
| 100 | #endif // NDN_CONTENT_STORE_WITH_PROBABILITY_H_ |