blob: 60983372d7e887dbd6f4259e5d93d512fea2cba2 [file] [log] [blame]
Alexander Afanasyeve6852122013-01-21 11:54:47 -08001.. _content store:
2
3Content Store
4+++++++++++++
5
6ndnSIM 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
12To select a particular content store and configure its capacity, use :ndnsim:`SetContentStore <ndn::StackHelper::SetContentStore>` helper method
13
14Simple content stores
15^^^^^^^^^^^^^^^^^^^^^
16
17Least Recently Used (LRU) (default)
18~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19
20Implementation name: :ndnsim:`ndn::cs::Lru`.
21
22Usage example:
23
24 .. code-block:: c++
25
26 ndnHelper.SetContentStore ("ns3::ndn::cs::Lru",
27 "MaxSize", "10000");
28 ...
29 ndnHelper.Install (nodes);
30
31First-In-First-Out (FIFO)
32~~~~~~~~~~~~~~~~~~~~~~~~~
33
34Implementation name: :ndnsim:`ndn::cs::Fifo`
35
36Usage example:
37
38 .. code-block:: c++
39
40 ndnHelper.SetContentStore ("ns3::ndn::cs::Fifo",
41 "MaxSize", "10000");
42 ...
43 ndnHelper.Install (nodes);
44
45Random
46~~~~~~
47
48Implementation name: :ndnsim:`ndn::cs::Random`
49
50Usage 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 Afanasyevb42619d2014-02-17 12:11:25 -080067Nocache
68~~~~~~~
69
70:ndnsim:`Trivial implementation <ndn::cs::Nocache>` of the ContentStore that does not really do any caching.
71
72Usage example:
73
74 .. code-block:: c++
75
76 ndnHelper.SetContentStore ("ns3::ndn::cs::Nocache");
77 ...
78 ndnHelper.Install (nodes);
Alexander Afanasyeve6852122013-01-21 11:54:47 -080079
80Content stores with entry lifetime tracking
81^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82
83In order to evaluate lifetime of the content store entries, the special versions of the content store need to be used:
84
85Least Recently Used (LRU)
86~~~~~~~~~~~~~~~~~~~~~~~~~
87
88Implementation name: :ndnsim:`ndn::cs::Stats::Lru`.
89
90Usage 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
111First-In-First-Out (FIFO)
112~~~~~~~~~~~~~~~~~~~~~~~~~
113
114Implementation name: :ndnsim:`ndn::cs::Stats::Fifo`.
115
116Usage 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
136Random
137~~~~~~
138
139Implementation name: :ndnsim:`ndn::cs::Stats::Random`
140
141Usage 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
163Content stores respecting freshness field of ContentObjects
164^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
165
166If 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
172Least Recently Used (LRU)
173~~~~~~~~~~~~~~~~~~~~~~~~~
174
175Implementation name: :ndnsim:`ndn::cs::Freshness::Lru`.
176
177Usage example:
178
179 .. code-block:: c++
180
181 ...
182
183 ndnHelper.SetContentStore ("ns3::ndn::cs::Freshness::Lru",
184 "MaxSize", "10000");
185 ...
186
187First-In-First-Out (FIFO)
188~~~~~~~~~~~~~~~~~~~~~~~~~
189
190Implementation name: :ndnsim:`ndn::cs::Freshness::Fifo`
191
192Usage example:
193
194 .. code-block:: c++
195
196 ...
197
198 ndnHelper.SetContentStore ("ns3::ndn::cs::Freshness::Fifo",
199 "MaxSize", "10000");
200 ...
201
202Random
203~~~~~~
204
205Implementation name: :ndnsim:`ndn::cs::Freshness::Random`
206
207Usage example:
208
209 .. code-block:: c++
210
211 ...
212
213 ndnHelper.SetContentStore ("ns3::ndn::cs::Freshness::Random",
214 "MaxSize", "10000");
215 ...
216
217Example
218~~~~~~~
219
220The following example demonstrates a basic usage of a customized content store (``ndn-simple-with-content-freshness.cc``).
221In this scenario two simple consumers (both installed on a consumer node) continually request the same data packet.
222When 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
240To run this scenario, use the following command::
241
242 NS_LOG=DumbRequester:ndn.cs.Freshness.Lru ./waf --run=ndn-simple-with-content-freshness