Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Alexander Afanasyev | 480e456 | 2012-06-29 17:46:47 -0700 | [diff] [blame] | 21 | #include "ccnx-content-store-policies.h" |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 22 | #include "ns3/log.h" |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 23 | #include "ns3/uinteger.h" |
| 24 | |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 25 | NS_LOG_COMPONENT_DEFINE ("CcnxContentStorePolicies"); |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 26 | |
| 27 | namespace ns3 |
| 28 | { |
| 29 | |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 30 | //////////////////////////////////////////////////////////////////////////////////// |
| 31 | //////////////////////////////////////////////////////////////////////////////////// |
| 32 | // LRU policy |
| 33 | //////////////////////////////////////////////////////////////////////////////////// |
| 34 | //////////////////////////////////////////////////////////////////////////////////// |
| 35 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 36 | NS_OBJECT_ENSURE_REGISTERED (CcnxContentStoreLru); |
| 37 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 38 | TypeId |
| 39 | CcnxContentStoreLru::GetTypeId (void) |
| 40 | { |
| 41 | static TypeId tid = TypeId ("ns3::CcnxContentStoreLru") |
| 42 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 43 | .SetParent< CcnxContentStore > () |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 44 | .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 | |
| 56 | void |
| 57 | CcnxContentStoreLru::SetMaxSize (uint32_t maxSize) |
| 58 | { |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 59 | getPolicy ().set_max_size (maxSize); |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | uint32_t |
| 63 | CcnxContentStoreLru::GetMaxSize () const |
| 64 | { |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 65 | return getPolicy ().get_max_size (); |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 68 | CcnxContentStoreLru::CcnxContentStoreLru () |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 69 | { |
| 70 | } |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 71 | |
| 72 | CcnxContentStoreLru::~CcnxContentStoreLru () |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 73 | { |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 74 | } |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 75 | |
| 76 | //////////////////////////////////////////////////////////////////////////////////// |
| 77 | //////////////////////////////////////////////////////////////////////////////////// |
| 78 | // RANDOM policy |
| 79 | //////////////////////////////////////////////////////////////////////////////////// |
| 80 | //////////////////////////////////////////////////////////////////////////////////// |
| 81 | |
| 82 | NS_OBJECT_ENSURE_REGISTERED (CcnxContentStoreRandom); |
| 83 | |
| 84 | TypeId |
| 85 | CcnxContentStoreRandom::GetTypeId (void) |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 86 | { |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 87 | 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 Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 103 | void |
| 104 | CcnxContentStoreRandom::SetMaxSize (uint32_t maxSize) |
| 105 | { |
| 106 | getPolicy ().set_max_size (maxSize); |
| 107 | } |
| 108 | |
| 109 | uint32_t |
| 110 | CcnxContentStoreRandom::GetMaxSize () const |
| 111 | { |
| 112 | return getPolicy ().get_max_size (); |
| 113 | } |
| 114 | |
| 115 | CcnxContentStoreRandom::CcnxContentStoreRandom () |
| 116 | { |
| 117 | } |
| 118 | |
| 119 | CcnxContentStoreRandom::~CcnxContentStoreRandom () |
| 120 | { |
| 121 | } |
| 122 | |
| 123 | |
| 124 | //////////////////////////////////////////////////////////////////////////////////// |
| 125 | //////////////////////////////////////////////////////////////////////////////////// |
| 126 | // FIFO policy |
| 127 | //////////////////////////////////////////////////////////////////////////////////// |
| 128 | //////////////////////////////////////////////////////////////////////////////////// |
| 129 | |
| 130 | NS_OBJECT_ENSURE_REGISTERED (CcnxContentStoreFifo); |
| 131 | |
| 132 | TypeId |
| 133 | CcnxContentStoreFifo::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 | |
| 151 | void |
| 152 | CcnxContentStoreFifo::SetMaxSize (uint32_t maxSize) |
| 153 | { |
| 154 | getPolicy ().set_max_size (maxSize); |
| 155 | } |
| 156 | |
| 157 | uint32_t |
| 158 | CcnxContentStoreFifo::GetMaxSize () const |
| 159 | { |
| 160 | return getPolicy ().get_max_size (); |
| 161 | } |
| 162 | |
| 163 | CcnxContentStoreFifo::CcnxContentStoreFifo () |
| 164 | { |
| 165 | } |
| 166 | |
| 167 | CcnxContentStoreFifo::~CcnxContentStoreFifo () |
| 168 | { |
| 169 | } |
| 170 | |
| 171 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 172 | } // namespace ns3 |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 173 | |