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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | #include "ndn-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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 25 | NS_LOG_COMPONENT_DEFINE ("NdnContentStorePolicies"); |
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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 36 | NS_OBJECT_ENSURE_REGISTERED (NdnContentStoreLru); |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 38 | TypeId |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 39 | NdnContentStoreLru::GetTypeId (void) |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 40 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 41 | static TypeId tid = TypeId ("ns3::NdnContentStoreLru") |
| 42 | .SetGroupName ("Ndn") |
| 43 | .SetParent< NdnContentStore > () |
| 44 | .AddConstructor<NdnContentStoreLru> () |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 45 | .AddAttribute ("Size", |
| 46 | "Maximum number of packets that content storage can hold", |
| 47 | UintegerValue (100), |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 48 | MakeUintegerAccessor (&NdnContentStoreLru::SetMaxSize, |
| 49 | &NdnContentStoreLru::GetMaxSize), |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 50 | MakeUintegerChecker<uint32_t> ()) |
| 51 | ; |
| 52 | |
| 53 | return tid; |
| 54 | } |
| 55 | |
| 56 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 57 | NdnContentStoreLru::SetMaxSize (uint32_t maxSize) |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 63 | NdnContentStoreLru::GetMaxSize () const |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 68 | NdnContentStoreLru::NdnContentStoreLru () |
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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 72 | NdnContentStoreLru::~NdnContentStoreLru () |
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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 82 | NS_OBJECT_ENSURE_REGISTERED (NdnContentStoreRandom); |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 83 | |
| 84 | TypeId |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 85 | NdnContentStoreRandom::GetTypeId (void) |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 86 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 87 | static TypeId tid = TypeId ("ns3::NdnContentStoreRandom") |
| 88 | .SetGroupName ("Ndn") |
| 89 | .SetParent< NdnContentStore > () |
| 90 | .AddConstructor<NdnContentStoreRandom> () |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 91 | |
| 92 | .AddAttribute ("Size", |
| 93 | "Maximum number of packets that content storage can hold", |
| 94 | UintegerValue (100), |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 95 | MakeUintegerAccessor (&NdnContentStoreRandom::SetMaxSize, |
| 96 | &NdnContentStoreRandom::GetMaxSize), |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 104 | NdnContentStoreRandom::SetMaxSize (uint32_t maxSize) |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 105 | { |
| 106 | getPolicy ().set_max_size (maxSize); |
| 107 | } |
| 108 | |
| 109 | uint32_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 110 | NdnContentStoreRandom::GetMaxSize () const |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 111 | { |
| 112 | return getPolicy ().get_max_size (); |
| 113 | } |
| 114 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 115 | NdnContentStoreRandom::NdnContentStoreRandom () |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 116 | { |
| 117 | } |
| 118 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 119 | NdnContentStoreRandom::~NdnContentStoreRandom () |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 120 | { |
| 121 | } |
| 122 | |
| 123 | |
| 124 | //////////////////////////////////////////////////////////////////////////////////// |
| 125 | //////////////////////////////////////////////////////////////////////////////////// |
| 126 | // FIFO policy |
| 127 | //////////////////////////////////////////////////////////////////////////////////// |
| 128 | //////////////////////////////////////////////////////////////////////////////////// |
| 129 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 130 | NS_OBJECT_ENSURE_REGISTERED (NdnContentStoreFifo); |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 131 | |
| 132 | TypeId |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 133 | NdnContentStoreFifo::GetTypeId (void) |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 134 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 135 | static TypeId tid = TypeId ("ns3::NdnContentStoreFifo") |
| 136 | .SetGroupName ("Ndn") |
| 137 | .SetParent< NdnContentStore > () |
| 138 | .AddConstructor<NdnContentStoreFifo> () |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 139 | |
| 140 | .AddAttribute ("Size", |
| 141 | "Maximum number of packets that content storage can hold", |
| 142 | UintegerValue (100), |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 143 | MakeUintegerAccessor (&NdnContentStoreFifo::SetMaxSize, |
| 144 | &NdnContentStoreFifo::GetMaxSize), |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 145 | MakeUintegerChecker<uint32_t> ()) |
| 146 | ; |
| 147 | |
| 148 | return tid; |
| 149 | } |
| 150 | |
| 151 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 152 | NdnContentStoreFifo::SetMaxSize (uint32_t maxSize) |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 153 | { |
| 154 | getPolicy ().set_max_size (maxSize); |
| 155 | } |
| 156 | |
| 157 | uint32_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 158 | NdnContentStoreFifo::GetMaxSize () const |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 159 | { |
| 160 | return getPolicy ().get_max_size (); |
| 161 | } |
| 162 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 163 | NdnContentStoreFifo::NdnContentStoreFifo () |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 164 | { |
| 165 | } |
| 166 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 167 | NdnContentStoreFifo::~NdnContentStoreFifo () |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 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 | |