blob: e9a23e1f6ff101aa641b3dcf6b804c7c3368893c [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 Afanasyev480e4562012-06-29 17:46:47 -070021#include "ccnx-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 Afanasyev9a989702012-06-29 17:44:00 -070025NS_LOG_COMPONENT_DEFINE ("CcnxContentStorePolicies");
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 Afanasyevd9fecdd2012-06-08 16:22:24 -070036NS_OBJECT_ENSURE_REGISTERED (CcnxContentStoreLru);
37
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070038TypeId
39CcnxContentStoreLru::GetTypeId (void)
40{
41 static TypeId tid = TypeId ("ns3::CcnxContentStoreLru")
42 .SetGroupName ("Ccnx")
Alexander Afanasyev9a989702012-06-29 17:44:00 -070043 .SetParent< CcnxContentStore > ()
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070044 .AddConstructor<CcnxContentStoreLru> ()
45 .AddAttribute ("Size",
46 "Maximum number of packets that content storage can hold",
47 UintegerValue (100),
48 MakeUintegerAccessor (&CcnxContentStoreLru::SetMaxSize,
49 &CcnxContentStoreLru::GetMaxSize),
50 MakeUintegerChecker<uint32_t> ())
51 ;
52
53 return tid;
54}
55
56void
57CcnxContentStoreLru::SetMaxSize (uint32_t maxSize)
58{
Alexander Afanasyev9a989702012-06-29 17:44:00 -070059 getPolicy ().set_max_size (maxSize);
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070060}
61
62uint32_t
63CcnxContentStoreLru::GetMaxSize () const
64{
Alexander Afanasyev9a989702012-06-29 17:44:00 -070065 return getPolicy ().get_max_size ();
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070066}
67
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070068CcnxContentStoreLru::CcnxContentStoreLru ()
Alexander Afanasyev9a989702012-06-29 17:44:00 -070069{
70}
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070071
72CcnxContentStoreLru::~CcnxContentStoreLru ()
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
82NS_OBJECT_ENSURE_REGISTERED (CcnxContentStoreRandom);
83
84TypeId
85CcnxContentStoreRandom::GetTypeId (void)
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070086{
Alexander Afanasyev9a989702012-06-29 17:44:00 -070087 static TypeId tid = TypeId ("ns3::CcnxContentStoreRandom")
88 .SetGroupName ("Ccnx")
89 .SetParent< CcnxContentStore > ()
90 .AddConstructor<CcnxContentStoreRandom> ()
91
92 .AddAttribute ("Size",
93 "Maximum number of packets that content storage can hold",
94 UintegerValue (100),
95 MakeUintegerAccessor (&CcnxContentStoreRandom::SetMaxSize,
96 &CcnxContentStoreRandom::GetMaxSize),
97 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
104CcnxContentStoreRandom::SetMaxSize (uint32_t maxSize)
105{
106 getPolicy ().set_max_size (maxSize);
107}
108
109uint32_t
110CcnxContentStoreRandom::GetMaxSize () const
111{
112 return getPolicy ().get_max_size ();
113}
114
115CcnxContentStoreRandom::CcnxContentStoreRandom ()
116{
117}
118
119CcnxContentStoreRandom::~CcnxContentStoreRandom ()
120{
121}
122
123
124////////////////////////////////////////////////////////////////////////////////////
125////////////////////////////////////////////////////////////////////////////////////
126// FIFO policy
127////////////////////////////////////////////////////////////////////////////////////
128////////////////////////////////////////////////////////////////////////////////////
129
130NS_OBJECT_ENSURE_REGISTERED (CcnxContentStoreFifo);
131
132TypeId
133CcnxContentStoreFifo::GetTypeId (void)
134{
135 static TypeId tid = TypeId ("ns3::CcnxContentStoreFifo")
136 .SetGroupName ("Ccnx")
137 .SetParent< CcnxContentStore > ()
138 .AddConstructor<CcnxContentStoreFifo> ()
139
140 .AddAttribute ("Size",
141 "Maximum number of packets that content storage can hold",
142 UintegerValue (100),
143 MakeUintegerAccessor (&CcnxContentStoreFifo::SetMaxSize,
144 &CcnxContentStoreFifo::GetMaxSize),
145 MakeUintegerChecker<uint32_t> ())
146 ;
147
148 return tid;
149}
150
151void
152CcnxContentStoreFifo::SetMaxSize (uint32_t maxSize)
153{
154 getPolicy ().set_max_size (maxSize);
155}
156
157uint32_t
158CcnxContentStoreFifo::GetMaxSize () const
159{
160 return getPolicy ().get_max_size ();
161}
162
163CcnxContentStoreFifo::CcnxContentStoreFifo ()
164{
165}
166
167CcnxContentStoreFifo::~CcnxContentStoreFifo ()
168{
169}
170
171
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700172} // namespace ns3
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700173