blob: a47446170c3cdca28298c8ce174fb9005d860ec3 [file] [log] [blame]
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 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 *
Alexander Afanasyev9a989702012-06-29 17:44:00 -070018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070019 */
20
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070021#include "ndn-content-store-policies.h"
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070022#include "ns3/log.h"
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070023#include "ns3/uinteger.h"
24
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070025NS_LOG_COMPONENT_DEFINE ("NdnContentStorePolicies");
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070026
27namespace ns3
28{
29
Alexander Afanasyev9a989702012-06-29 17:44:00 -070030////////////////////////////////////////////////////////////////////////////////////
31////////////////////////////////////////////////////////////////////////////////////
32// LRU policy
33////////////////////////////////////////////////////////////////////////////////////
34////////////////////////////////////////////////////////////////////////////////////
35
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070036NS_OBJECT_ENSURE_REGISTERED (NdnContentStoreLru);
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070037
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070038TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070039NdnContentStoreLru::GetTypeId (void)
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070040{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070041 static TypeId tid = TypeId ("ns3::NdnContentStoreLru")
42 .SetGroupName ("Ndn")
43 .SetParent< NdnContentStore > ()
44 .AddConstructor<NdnContentStoreLru> ()
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070045 .AddAttribute ("Size",
46 "Maximum number of packets that content storage can hold",
47 UintegerValue (100),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070048 MakeUintegerAccessor (&NdnContentStoreLru::SetMaxSize,
49 &NdnContentStoreLru::GetMaxSize),
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070050 MakeUintegerChecker<uint32_t> ())
51 ;
52
53 return tid;
54}
55
56void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070057NdnContentStoreLru::SetMaxSize (uint32_t maxSize)
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070058{
Alexander Afanasyev9a989702012-06-29 17:44:00 -070059 getPolicy ().set_max_size (maxSize);
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070060}
61
62uint32_t
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070063NdnContentStoreLru::GetMaxSize () const
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070064{
Alexander Afanasyev9a989702012-06-29 17:44:00 -070065 return getPolicy ().get_max_size ();
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070066}
67
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070068NdnContentStoreLru::NdnContentStoreLru ()
Alexander Afanasyev9a989702012-06-29 17:44:00 -070069{
70}
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070071
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070072NdnContentStoreLru::~NdnContentStoreLru ()
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070073{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070074}
Alexander Afanasyev9a989702012-06-29 17:44:00 -070075
76////////////////////////////////////////////////////////////////////////////////////
77////////////////////////////////////////////////////////////////////////////////////
78// RANDOM policy
79////////////////////////////////////////////////////////////////////////////////////
80////////////////////////////////////////////////////////////////////////////////////
81
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070082NS_OBJECT_ENSURE_REGISTERED (NdnContentStoreRandom);
Alexander Afanasyev9a989702012-06-29 17:44:00 -070083
84TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070085NdnContentStoreRandom::GetTypeId (void)
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070086{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070087 static TypeId tid = TypeId ("ns3::NdnContentStoreRandom")
88 .SetGroupName ("Ndn")
89 .SetParent< NdnContentStore > ()
90 .AddConstructor<NdnContentStoreRandom> ()
Alexander Afanasyev9a989702012-06-29 17:44:00 -070091
92 .AddAttribute ("Size",
93 "Maximum number of packets that content storage can hold",
94 UintegerValue (100),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070095 MakeUintegerAccessor (&NdnContentStoreRandom::SetMaxSize,
96 &NdnContentStoreRandom::GetMaxSize),
Alexander Afanasyev9a989702012-06-29 17:44:00 -070097 MakeUintegerChecker<uint32_t> ())
98 ;
99
100 return tid;
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700101}
102
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700103void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700104NdnContentStoreRandom::SetMaxSize (uint32_t maxSize)
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700105{
106 getPolicy ().set_max_size (maxSize);
107}
108
109uint32_t
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700110NdnContentStoreRandom::GetMaxSize () const
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700111{
112 return getPolicy ().get_max_size ();
113}
114
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700115NdnContentStoreRandom::NdnContentStoreRandom ()
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700116{
117}
118
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700119NdnContentStoreRandom::~NdnContentStoreRandom ()
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700120{
121}
122
123
124////////////////////////////////////////////////////////////////////////////////////
125////////////////////////////////////////////////////////////////////////////////////
126// FIFO policy
127////////////////////////////////////////////////////////////////////////////////////
128////////////////////////////////////////////////////////////////////////////////////
129
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700130NS_OBJECT_ENSURE_REGISTERED (NdnContentStoreFifo);
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700131
132TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700133NdnContentStoreFifo::GetTypeId (void)
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700134{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700135 static TypeId tid = TypeId ("ns3::NdnContentStoreFifo")
136 .SetGroupName ("Ndn")
137 .SetParent< NdnContentStore > ()
138 .AddConstructor<NdnContentStoreFifo> ()
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700139
140 .AddAttribute ("Size",
141 "Maximum number of packets that content storage can hold",
142 UintegerValue (100),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700143 MakeUintegerAccessor (&NdnContentStoreFifo::SetMaxSize,
144 &NdnContentStoreFifo::GetMaxSize),
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700145 MakeUintegerChecker<uint32_t> ())
146 ;
147
148 return tid;
149}
150
151void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700152NdnContentStoreFifo::SetMaxSize (uint32_t maxSize)
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700153{
154 getPolicy ().set_max_size (maxSize);
155}
156
157uint32_t
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700158NdnContentStoreFifo::GetMaxSize () const
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700159{
160 return getPolicy ().get_max_size ();
161}
162
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700163NdnContentStoreFifo::NdnContentStoreFifo ()
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700164{
165}
166
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700167NdnContentStoreFifo::~NdnContentStoreFifo ()
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700168{
169}
170
171
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700172} // namespace ns3
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700173