blob: ab5116b4bae8093a5ee04439c5a2cc1b4a81b027 [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
67
68Content stores with entry lifetime tracking
69^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70
71In order to evaluate lifetime of the content store entries, the special versions of the content store need to be used:
72
73Least Recently Used (LRU)
74~~~~~~~~~~~~~~~~~~~~~~~~~
75
76Implementation name: :ndnsim:`ndn::cs::Stats::Lru`.
77
78Usage example:
79
80 .. code-block:: c++
81
82 void
83 CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
84 {
85 std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl;
86 }
87
88 ...
89
90 ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Lru",
91 "MaxSize", "10000");
92 ...
93 ndnHelper.Install (nodes);
94
95 // connect to lifetime trace
96 Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Lru/WillRemoveEntry", MakeCallback (CacheEntryRemoved));
97
98
99First-In-First-Out (FIFO)
100~~~~~~~~~~~~~~~~~~~~~~~~~
101
102Implementation name: :ndnsim:`ndn::cs::Stats::Fifo`.
103
104Usage example:
105
106 .. code-block:: c++
107
108 void
109 CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
110 {
111 std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl;
112 }
113
114 ...
115
116 ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Fifo",
117 "MaxSize", "10000");
118 ...
119 ndnHelper.Install (nodes);
120
121 // connect to lifetime trace
122 Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Fifo/WillRemoveEntry", MakeCallback (CacheEntryRemoved));
123
124Random
125~~~~~~
126
127Implementation name: :ndnsim:`ndn::cs::Stats::Random`
128
129Usage example:
130
131 .. code-block:: c++
132
133 void
134 CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
135 {
136 std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl;
137 }
138
139 ...
140
141 ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Random",
142 "MaxSize", "10000");
143 ...
144 ndnHelper.Install (nodes);
145
146 // connect to lifetime trace
147 Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Random/WillRemoveEntry", MakeCallback (CacheEntryRemoved));
148
149.. _Content Store respecting freshness field of ContentObjects:
150
151Content stores respecting freshness field of ContentObjects
152^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
153
154If simulations need Content Store which respects freshness of ContentObjects, the following versions of content store should be used:
155
156.. note:
157
158 Please note that currently, Freshness granularity is 1 second and maximum value is 65535 second. Value means infinity.
159
160Least Recently Used (LRU)
161~~~~~~~~~~~~~~~~~~~~~~~~~
162
163Implementation name: :ndnsim:`ndn::cs::Freshness::Lru`.
164
165Usage example:
166
167 .. code-block:: c++
168
169 ...
170
171 ndnHelper.SetContentStore ("ns3::ndn::cs::Freshness::Lru",
172 "MaxSize", "10000");
173 ...
174
175First-In-First-Out (FIFO)
176~~~~~~~~~~~~~~~~~~~~~~~~~
177
178Implementation name: :ndnsim:`ndn::cs::Freshness::Fifo`
179
180Usage example:
181
182 .. code-block:: c++
183
184 ...
185
186 ndnHelper.SetContentStore ("ns3::ndn::cs::Freshness::Fifo",
187 "MaxSize", "10000");
188 ...
189
190Random
191~~~~~~
192
193Implementation name: :ndnsim:`ndn::cs::Freshness::Random`
194
195Usage example:
196
197 .. code-block:: c++
198
199 ...
200
201 ndnHelper.SetContentStore ("ns3::ndn::cs::Freshness::Random",
202 "MaxSize", "10000");
203 ...
204
205Example
206~~~~~~~
207
208The following example demonstrates a basic usage of a customized content store (``ndn-simple-with-content-freshness.cc``).
209In this scenario two simple consumers (both installed on a consumer node) continually request the same data packet.
210When 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.
211
212.. aafig::
213 :aspect: 60
214 :scale: 120
215
216 +----------+ +--------+ +----------+
217 | | 1Mbps | | 1Mbps | |
218 | Consumer |<-------------->| Router |<-------------->| Producer |
219 | | 10ms | | 10ms | |
220 +----------+ +--------+ +----------+
221
222
223.. literalinclude:: ../../examples/ndn-simple-with-content-freshness.cc
224 :language: c++
225 :linenos:
226 :lines: 20-27,43-
227
228To run this scenario, use the following command::
229
230 NS_LOG=DumbRequester:ndn.cs.Freshness.Lru ./waf --run=ndn-simple-with-content-freshness