blob: 42ad716c20556b5367681e6a1d73b8f7af1c5e92 [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
26#include "../../utils/trie/multi-policy.h"
27#include "custom-policies/probability-policy.h"
28#include "ns3/double.h"
29#include "ns3/type-id.h"
30
31namespace ns3 {
32namespace ndn {
33namespace cs {
34
35/**
36 * @ingroup ndn-cs
37 * @brief Special content store realization that honors Freshness parameter in Data packets
38 */
39template<class Policy>
40class ContentStoreWithProbability :
41 public ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< ndnSIM::probability_policy_traits, Policy > > >
42{
43public:
44 typedef ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< ndnSIM::probability_policy_traits, Policy > > > super;
45
46 typedef typename super::policy_container::template index<0>::type probability_policy_container;
47
48 ContentStoreWithProbability () {};
49
50 static TypeId
51 GetTypeId ();
52private:
53
54 void SetCacheProbability (double probability)
55 {
56 this->getPolicy ()
57 .template get<probability_policy_container> ()
58 .set_probability (probability);
59 }
60
61 double
62 GetCacheProbability () const
63 {
64 return
65 this->getPolicy ()
66 .template get<probability_policy_container> ()
67 .get_probability ();
68 }
69};
70
71//////////////////////////////////////////
72////////// Implementation ////////////////
73//////////////////////////////////////////
74
75template<class Policy>
76TypeId
77ContentStoreWithProbability< Policy >::GetTypeId ()
78{
79 static TypeId tid = TypeId (("ns3::ndn::cs::Probability::"+Policy::GetName ()).c_str ())
80 .SetGroupName ("Ndn")
81 .SetParent<super> ()
82 .template AddConstructor< ContentStoreWithProbability< Policy > > ()
83
84 .AddAttribute ("CacheProbability",
85 "Set probability of caching in ContentStore. "
86 "If 1, every content is cached. If 0, no content is cached.",
87 DoubleValue (1.0),//(+)
88 MakeDoubleAccessor (&ContentStoreWithProbability< Policy >::GetCacheProbability,
89 &ContentStoreWithProbability< Policy >::SetCacheProbability),
90 MakeDoubleChecker<double> ())
91 ;
92
93 return tid;
94}
95
96
97} // namespace cs
98} // namespace ndn
99} // namespace ns3
100
101#endif // NDN_CONTENT_STORE_WITH_PROBABILITY_H_