blob: b1188221bf071d7c55b67c65c2829a160f57f7b0 [file] [log] [blame]
Alexander Afanasyeve6852122013-01-21 11:54:47 -08001.. _content store:
2
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -08003NFD's Content Store
4++++++++++++++++++++
Alexander Afanasyeve6852122013-01-21 11:54:47 -08005
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -08006The current implementation of NFD's Content Store uses a `skip list
7<http://en.wikipedia.org/wiki/Skip_list>`_ as its underlying data structure. Skip lists are a
8probabilistic alternative to balanced trees. Skip lists are balanced by virtue of a random
9number generator. Its average insertion and lookup complexity is O(log n). CS entries are
10placed in the Skip List in ascending order (by Name).
Alexander Afanasyeve6852122013-01-21 11:54:47 -080011
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080012The current implementation evicts CS entries based on prioritized FIFO (First In First Out)
13strategy. The entries that get removed first are unsolicited Data packets, which are the Data
14packets that got cached opportunistically without preceding forwarding of the corresponding
15Interest packet. Next, the Data packets with expired freshness are removed. Lastly, the Data
16packets are removed from the Content Store on a pure FIFO basis. This cache replacement policy
17is currently hard-coded; it is intended to be replaceable in the future by the NFD developer
18team.
Alexander Afanasyeve6852122013-01-21 11:54:47 -080019
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080020The only currently available option to control behavior of NFD's Content Store is to set its
21maximum size using :ndnsim:`StackHelper::setCsSize()`:
Alexander Afanasyeve6852122013-01-21 11:54:47 -080022
23 .. code-block:: c++
24
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080025 ndnHelper.setCsSize(<max-size-in-packets>);
26 ...
27 ndnHelper.Install(nodes);
Alexander Afanasyeve6852122013-01-21 11:54:47 -080028
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080029Examples:
Alexander Afanasyeve6852122013-01-21 11:54:47 -080030
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080031- Effectively disable NFD content store an all nodes
Alexander Afanasyeve6852122013-01-21 11:54:47 -080032
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080033 Minimum allowed value for NFD content store size is 1. If 0 is specified, it will be assumed
34 that the old content store implementation should be used.
Alexander Afanasyeve6852122013-01-21 11:54:47 -080035
36 .. code-block:: c++
37
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080038 ndnHelper.setCsSize(1);
39 ...
40 ndnHelper.Install(nodes);
Alexander Afanasyeve6852122013-01-21 11:54:47 -080041
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080042- Set CS size 100 on node1, size 1000 on node1, and size 2000 on all other nodes:
Alexander Afanasyeve6852122013-01-21 11:54:47 -080043
44 .. code-block:: c++
45
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080046 ndnHelper.setCsSize(100);
47 ndnHelper.Install(node1);
48
49 ndnHelper.setCsSize(1000);
50 ndnHelper.Install(node2);
51
52 NodeContainer allOtherNodes;
53 for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i) {
54 if (*i != node1 && *i != node2) {
55 allOtherNodes.Add(*i);
56 }
57 }
58 ndnHelper.Install(allOtherNodes);
59
60CS entry
61~~~~~~~~
62
63The Data packet, along with other necessary fields, are stored in a CS entry. Each entry
64contains:
65
66- the Data packet
67- flag indicating whether the Data packet is unsolicited
68- the timestamp at which the cached Data becomes stale
69
70CS
71~~
72
73A multi-index container is maintained in order to support the prioritized FIFO cache
74replacement policy. In this way, pointers to the Data packets in a particular order are
75kept. Note that this multi-index container is completely separated from the skip list
76container, which indexes Content Store entries by name.
77
78The container (Cs::CleanupIndex) currently supports indexing of unsolicited Data packets,
79indexing by packet staleness and indexing by packet arrival time. Calculation of the indexes is
80performed in the container during the Data packet insertion (Cs::insert) in the Content Store.
81
82Eviction (Cs::evictItem) is performed during the insertion when the CS is full, and when the
83capacity is decreased by management. We decided not to perform periodical cleanups, because its
84CPU overhead causes jitter in packet forwarding.
85
86In the current version of NFD, cache replacement policy can be modified by adding different
87indexes in the Cs::CleanupIndex container (refer to Boost.multiIndex documentation) and
88implementing additional logic in Cs::evictItem function.
89
90For more detailed specification refer to the `NFD Developer's Guide
91<http://named-data.net/wp-content/uploads/2014/07/NFD-developer-guide.pdf>`_, section 3.2.
92
93Old Content Store Implementations
94+++++++++++++++++++++++++++++++++
95
96NFD's content store implementation takes full consideration of Interest selectors, however is
97not yet flexible when it comes to cache replacement policies. Feature to extend CS flexibility
98is currently in active development (refer to `Issue #2219 on NFD Redmine
99<http://redmine.named-data.net/issues/2219>`_) and for the time being, we have ported the old
100ndnSIM 1.0 content store implementations to the new code base. These implementations feature
101different cache replacement policies, but have very limited support for Interest selectors. If
102your scenario relies on proper selector processing, do not use these implementations as the
103simulation results most likely be incorrect.
104
105To select old content store implementations, use :ndnsim:`StackHelper::SetOldContentStore`:
106
107.. code-block:: c++
108
109 ndnHelper.SetOldContentStore("<content store implementation>",
110 ["<optional parameter>", "<optional parameter's value>" [, ...]]);
111 ...
112 ndnHelper.Install (nodes);
113
114Available old content store implementations are listed in the following table:
115
116
117+----------------------------------------------+----------------------------------------------------------+
118| **Simple content stores** |
119+----------------------------------------------+----------------------------------------------------------+
120| ``ns3::ndn::cs::Lru`` | **Least recently used (LRU) (default)** |
121+----------------------------------------------+----------------------------------------------------------+
122| ``ns3::ndn::cs::Fifo`` | First-in-first-Out (FIFO) |
123+----------------------------------------------+----------------------------------------------------------+
124| ``ns3::ndn::cs::Lfu`` | Least frequently used (LFU) |
125+----------------------------------------------+----------------------------------------------------------+
126| ``ns3::ndn::cs::Random`` | Random |
127+----------------------------------------------+----------------------------------------------------------+
128| ``ns3::ndn::cs::Nocache`` | Policy that completely disables caching |
129+----------------------------------------------+----------------------------------------------------------+
130+----------------------------------------------+----------------------------------------------------------+
131| **Content stores with entry lifetime tracking** |
132| |
133| These policies allow evaluation of CS enties lifetime (i.e., how long entries stay in CS) |
134+----------------------------------------------+----------------------------------------------------------+
135| ``ns3::ndn::cs::Stats::Lru`` | Least recently used (LRU) |
136+----------------------------------------------+----------------------------------------------------------+
137| ``ns3::ndn::cs::Stats::Fifo`` | Least frequently used (LFU) |
138+----------------------------------------------+----------------------------------------------------------+
139| ``ns3::ndn::cs::Stats::Lfu`` | Random |
140+----------------------------------------------+----------------------------------------------------------+
141| ``ns3::ndn::cs::Stats::Random`` | Policy that completely disables caching |
142+----------------------------------------------+----------------------------------------------------------+
143+----------------------------------------------+----------------------------------------------------------+
144| **Content stores respecting freshness field of Data packets** |
145| |
146| These policies cache Data packets only for the time indicated by FreshnessPeriod. |
147+----------------------------------------------+----------------------------------------------------------+
148| ``ns3::ndn::cs::Freshness::Lru`` | Least recently used (LRU) |
149+----------------------------------------------+----------------------------------------------------------+
150| ``ns3::ndn::cs::Freshness::Fifo`` | Least frequently used (LFU) |
151+----------------------------------------------+----------------------------------------------------------+
152| ``ns3::ndn::cs::Freshness::Lfu`` | Random |
153+----------------------------------------------+----------------------------------------------------------+
154| ``ns3::ndn::cs::Freshness::Random`` | Policy that completely disables caching |
155+----------------------------------------------+----------------------------------------------------------+
156+----------------------------------------------+----------------------------------------------------------+
157| **Content store realization that probabilistically accepts data packet into CS (placement policy)** |
158+----------------------------------------------+----------------------------------------------------------+
159| ``ns3::ndn::cs::Probability::Lru`` | Least recently used (LRU) |
160+----------------------------------------------+----------------------------------------------------------+
161| ``ns3::ndn::cs::Probability::Fifo`` | Least frequently used (LFU) |
162+----------------------------------------------+----------------------------------------------------------+
163| ``ns3::ndn::cs::Probability::Lfu`` | Random |
164+----------------------------------------------+----------------------------------------------------------+
165| ``ns3::ndn::cs::Probability::Random`` | Policy that completely disables caching |
166+----------------------------------------------+----------------------------------------------------------+
167
168Examples:
169
170
171- Select simple LRU policy on node1, simple FIFO policy on node2, and simple random policy on
172 other nodes with maximum CS sizes of 10000 packets:
173
174 .. code-block:: c++
175
176 ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", "10000");
177 ndnHelper.Install(node1);
178
179 ndnHelper.SetOldContentStore("ns3::ndn::cs::Fifo", "MaxSize", "10000");
180 ndnHelper.Install(node2);
181
182 ndnHelper.SetOldContentStore("ns3::ndn::cs::Random", "MaxSize", "10000");
183 ...
184 ndnHelper.Install(otherNodes);
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800185
186.. note::
187
188 If ``MaxSize`` parameter is omitted, then will be used a default value (100).
189
190.. note::
191
192 If ``MaxSize`` is set to 0, then no limit on ContentStore will be enforced
193
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800194- Disable CS on node2
Alexander Afanasyevb42619d2014-02-17 12:11:25 -0800195
196 .. code-block:: c++
197
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800198 ndnHelper.SetOldContentStore("ns3::ndn::cs::Nocache");
199 ndnHelper.Install(node3);
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800200
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800201- Track lifetime of CS entries (must use ``ns3::ndn::cs::*::LifetimeStats`` policy):
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800202
203 .. code-block:: c++
204
205 void
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800206 CacheEntryRemoved(std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800207 {
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800208 std::cout << entry->GetName() << " " << lifetime.ToDouble(Time::S) << "s" << std::endl;
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800209 }
210
211 ...
212
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800213 ndnHelper.SetOldContentStore("ns3::ndn::cs::Stats::Lru", "MaxSize", "10000");
214 ...
215 ndnHelper.Install(nodes);
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800216
217 // connect to lifetime trace
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800218 Config::Connect("/NodeList/*/$ns3::ndn::cs::Stats::Lru/WillRemoveEntry", MakeCallback(CacheEntryRemoved));
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800219
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800220- Get aggregate statistics of CS hit/miss ratio (works with any policy)
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800221
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800222 The simplest way tro track CS hit/miss statistics is to use :ndnsim:`CsTracer`, in more
223 details described in :ref:`Metrics Section <cs trace helper>`.
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800224
225 .. code-block:: c++
226
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800227 CsTracer::InstallAll("cs-trace.txt", Seconds(1));