blob: 55266e8152a00b85fcf86797846abdb4d57cc62f [file] [log] [blame]
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -07001/* -*- 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
24#include "content-store-impl.h"
25
Alexander Afanasyev0c395372014-12-20 15:54:02 -080026#include "content-store-impl.hpp"
27
28#include "../../utils/trie/multi-policy.hpp"
29#include "custom-policies/probability-policy.hpp"
Alexander Afanasyevcd31abd2013-09-05 20:45:02 -070030#include "ns3/double.h"
31#include "ns3/type-id.h"
32
33namespace ns3 {
34namespace ndn {
35namespace cs {
36
37/**
38 * @ingroup ndn-cs
39 * @brief Special content store realization that honors Freshness parameter in Data packets
40 */
41template<class Policy>
42class ContentStoreWithProbability :
43 public ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< ndnSIM::probability_policy_traits, Policy > > >
44{
45public:
46 typedef ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< ndnSIM::probability_policy_traits, Policy > > > super;
47
48 typedef typename super::policy_container::template index<0>::type probability_policy_container;
49
50 ContentStoreWithProbability () {};
51
52 static TypeId
53 GetTypeId ();
54private:
55
56 void SetCacheProbability (double probability)
57 {
58 this->getPolicy ()
59 .template get<probability_policy_container> ()
60 .set_probability (probability);
61 }
62
63 double
64 GetCacheProbability () const
65 {
66 return
67 this->getPolicy ()
68 .template get<probability_policy_container> ()
69 .get_probability ();
70 }
71};
72
73//////////////////////////////////////////
74////////// Implementation ////////////////
75//////////////////////////////////////////
76
77template<class Policy>
78TypeId
79ContentStoreWithProbability< Policy >::GetTypeId ()
80{
81 static TypeId tid = TypeId (("ns3::ndn::cs::Probability::"+Policy::GetName ()).c_str ())
82 .SetGroupName ("Ndn")
83 .SetParent<super> ()
84 .template AddConstructor< ContentStoreWithProbability< Policy > > ()
85
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> ())
93 ;
94
95 return tid;
96}
97
98
99} // namespace cs
100} // namespace ndn
101} // namespace ns3
102
103#endif // NDN_CONTENT_STORE_WITH_PROBABILITY_H_