Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 1 | .. _content store: |
| 2 | |
| 3 | Content Store |
| 4 | +++++++++++++ |
| 5 | |
| 6 | ndnSIM comes with several different in-memory :ndnsim:`content store <ndn::ContentStore>` implementations, featuring different cache replacement policies. |
| 7 | |
| 8 | .. note: |
| 9 | |
| 10 | The default content store uses LRU replacement policity and constrained with 100 cached ContentObjects. |
| 11 | |
| 12 | To select a particular content store and configure its capacity, use :ndnsim:`SetContentStore <ndn::StackHelper::SetContentStore>` helper method |
| 13 | |
| 14 | Simple content stores |
| 15 | ^^^^^^^^^^^^^^^^^^^^^ |
| 16 | |
| 17 | Least Recently Used (LRU) (default) |
| 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 19 | |
| 20 | Implementation name: :ndnsim:`ndn::cs::Lru`. |
| 21 | |
| 22 | Usage example: |
| 23 | |
| 24 | .. code-block:: c++ |
| 25 | |
| 26 | ndnHelper.SetContentStore ("ns3::ndn::cs::Lru", |
| 27 | "MaxSize", "10000"); |
| 28 | ... |
| 29 | ndnHelper.Install (nodes); |
| 30 | |
| 31 | First-In-First-Out (FIFO) |
| 32 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 33 | |
| 34 | Implementation name: :ndnsim:`ndn::cs::Fifo` |
| 35 | |
| 36 | Usage example: |
| 37 | |
| 38 | .. code-block:: c++ |
| 39 | |
| 40 | ndnHelper.SetContentStore ("ns3::ndn::cs::Fifo", |
| 41 | "MaxSize", "10000"); |
| 42 | ... |
| 43 | ndnHelper.Install (nodes); |
| 44 | |
| 45 | Random |
| 46 | ~~~~~~ |
| 47 | |
| 48 | Implementation name: :ndnsim:`ndn::cs::Random` |
| 49 | |
| 50 | Usage example: |
| 51 | |
| 52 | .. code-block:: c++ |
| 53 | |
| 54 | ndnHelper.SetContentStore ("ns3::ndn::cs::Random", |
| 55 | "MaxSize", "10000"); |
| 56 | ... |
| 57 | ndnHelper.Install (nodes); |
| 58 | |
| 59 | .. note:: |
| 60 | |
| 61 | If ``MaxSize`` parameter is omitted, then will be used a default value (100). |
| 62 | |
| 63 | .. note:: |
| 64 | |
| 65 | If ``MaxSize`` is set to 0, then no limit on ContentStore will be enforced |
| 66 | |
Alexander Afanasyev | b42619d | 2014-02-17 12:11:25 -0800 | [diff] [blame^] | 67 | Nocache |
| 68 | ~~~~~~~ |
| 69 | |
| 70 | :ndnsim:`Trivial implementation <ndn::cs::Nocache>` of the ContentStore that does not really do any caching. |
| 71 | |
| 72 | Usage example: |
| 73 | |
| 74 | .. code-block:: c++ |
| 75 | |
| 76 | ndnHelper.SetContentStore ("ns3::ndn::cs::Nocache"); |
| 77 | ... |
| 78 | ndnHelper.Install (nodes); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 79 | |
| 80 | Content stores with entry lifetime tracking |
| 81 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 82 | |
| 83 | In order to evaluate lifetime of the content store entries, the special versions of the content store need to be used: |
| 84 | |
| 85 | Least Recently Used (LRU) |
| 86 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 87 | |
| 88 | Implementation name: :ndnsim:`ndn::cs::Stats::Lru`. |
| 89 | |
| 90 | Usage example: |
| 91 | |
| 92 | .. code-block:: c++ |
| 93 | |
| 94 | void |
| 95 | CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime) |
| 96 | { |
| 97 | std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl; |
| 98 | } |
| 99 | |
| 100 | ... |
| 101 | |
| 102 | ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Lru", |
| 103 | "MaxSize", "10000"); |
| 104 | ... |
| 105 | ndnHelper.Install (nodes); |
| 106 | |
| 107 | // connect to lifetime trace |
| 108 | Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Lru/WillRemoveEntry", MakeCallback (CacheEntryRemoved)); |
| 109 | |
| 110 | |
| 111 | First-In-First-Out (FIFO) |
| 112 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 113 | |
| 114 | Implementation name: :ndnsim:`ndn::cs::Stats::Fifo`. |
| 115 | |
| 116 | Usage example: |
| 117 | |
| 118 | .. code-block:: c++ |
| 119 | |
| 120 | void |
| 121 | CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime) |
| 122 | { |
| 123 | std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl; |
| 124 | } |
| 125 | |
| 126 | ... |
| 127 | |
| 128 | ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Fifo", |
| 129 | "MaxSize", "10000"); |
| 130 | ... |
| 131 | ndnHelper.Install (nodes); |
| 132 | |
| 133 | // connect to lifetime trace |
| 134 | Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Fifo/WillRemoveEntry", MakeCallback (CacheEntryRemoved)); |
| 135 | |
| 136 | Random |
| 137 | ~~~~~~ |
| 138 | |
| 139 | Implementation name: :ndnsim:`ndn::cs::Stats::Random` |
| 140 | |
| 141 | Usage example: |
| 142 | |
| 143 | .. code-block:: c++ |
| 144 | |
| 145 | void |
| 146 | CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime) |
| 147 | { |
| 148 | std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl; |
| 149 | } |
| 150 | |
| 151 | ... |
| 152 | |
| 153 | ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Random", |
| 154 | "MaxSize", "10000"); |
| 155 | ... |
| 156 | ndnHelper.Install (nodes); |
| 157 | |
| 158 | // connect to lifetime trace |
| 159 | Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Random/WillRemoveEntry", MakeCallback (CacheEntryRemoved)); |
| 160 | |
| 161 | .. _Content Store respecting freshness field of ContentObjects: |
| 162 | |
| 163 | Content stores respecting freshness field of ContentObjects |
| 164 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 165 | |
| 166 | If simulations need Content Store which respects freshness of ContentObjects, the following versions of content store should be used: |
| 167 | |
| 168 | .. note: |
| 169 | |
| 170 | Please note that currently, Freshness granularity is 1 second and maximum value is 65535 second. Value means infinity. |
| 171 | |
| 172 | Least Recently Used (LRU) |
| 173 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 174 | |
| 175 | Implementation name: :ndnsim:`ndn::cs::Freshness::Lru`. |
| 176 | |
| 177 | Usage example: |
| 178 | |
| 179 | .. code-block:: c++ |
| 180 | |
| 181 | ... |
| 182 | |
| 183 | ndnHelper.SetContentStore ("ns3::ndn::cs::Freshness::Lru", |
| 184 | "MaxSize", "10000"); |
| 185 | ... |
| 186 | |
| 187 | First-In-First-Out (FIFO) |
| 188 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 189 | |
| 190 | Implementation name: :ndnsim:`ndn::cs::Freshness::Fifo` |
| 191 | |
| 192 | Usage example: |
| 193 | |
| 194 | .. code-block:: c++ |
| 195 | |
| 196 | ... |
| 197 | |
| 198 | ndnHelper.SetContentStore ("ns3::ndn::cs::Freshness::Fifo", |
| 199 | "MaxSize", "10000"); |
| 200 | ... |
| 201 | |
| 202 | Random |
| 203 | ~~~~~~ |
| 204 | |
| 205 | Implementation name: :ndnsim:`ndn::cs::Freshness::Random` |
| 206 | |
| 207 | Usage example: |
| 208 | |
| 209 | .. code-block:: c++ |
| 210 | |
| 211 | ... |
| 212 | |
| 213 | ndnHelper.SetContentStore ("ns3::ndn::cs::Freshness::Random", |
| 214 | "MaxSize", "10000"); |
| 215 | ... |
| 216 | |
| 217 | Example |
| 218 | ~~~~~~~ |
| 219 | |
| 220 | The following example demonstrates a basic usage of a customized content store (``ndn-simple-with-content-freshness.cc``). |
| 221 | In this scenario two simple consumers (both installed on a consumer node) continually request the same data packet. |
| 222 | When Data producer specify unlimited freshness, Content keeps getting satisfied from local caches, while if freshness is specified, Interests periodically are getting through to the Data producer. |
| 223 | |
| 224 | .. aafig:: |
| 225 | :aspect: 60 |
| 226 | :scale: 120 |
| 227 | |
| 228 | +----------+ +--------+ +----------+ |
| 229 | | | 1Mbps | | 1Mbps | | |
| 230 | | Consumer |<-------------->| Router |<-------------->| Producer | |
| 231 | | | 10ms | | 10ms | | |
| 232 | +----------+ +--------+ +----------+ |
| 233 | |
| 234 | |
| 235 | .. literalinclude:: ../../examples/ndn-simple-with-content-freshness.cc |
| 236 | :language: c++ |
| 237 | :linenos: |
| 238 | :lines: 20-27,43- |
| 239 | |
| 240 | To run this scenario, use the following command:: |
| 241 | |
| 242 | NS_LOG=DumbRequester:ndn.cs.Freshness.Lru ./waf --run=ndn-simple-with-content-freshness |