Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 1 | .. _content store: |
| 2 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 3 | NFD's Content Store |
| 4 | ++++++++++++++++++++ |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 5 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 6 | The 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 |
| 8 | probabilistic alternative to balanced trees. Skip lists are balanced by virtue of a random |
| 9 | number generator. Its average insertion and lookup complexity is O(log n). CS entries are |
| 10 | placed in the Skip List in ascending order (by Name). |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 11 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 12 | The current implementation evicts CS entries based on prioritized FIFO (First In First Out) |
| 13 | strategy. The entries that get removed first are unsolicited Data packets, which are the Data |
| 14 | packets that got cached opportunistically without preceding forwarding of the corresponding |
| 15 | Interest packet. Next, the Data packets with expired freshness are removed. Lastly, the Data |
| 16 | packets are removed from the Content Store on a pure FIFO basis. This cache replacement policy |
| 17 | is currently hard-coded; it is intended to be replaceable in the future by the NFD developer |
| 18 | team. |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 19 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 20 | The only currently available option to control behavior of NFD's Content Store is to set its |
| 21 | maximum size using :ndnsim:`StackHelper::setCsSize()`: |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 22 | |
| 23 | .. code-block:: c++ |
| 24 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 25 | ndnHelper.setCsSize(<max-size-in-packets>); |
| 26 | ... |
| 27 | ndnHelper.Install(nodes); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 28 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 29 | Examples: |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 30 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 31 | - Effectively disable NFD content store an all nodes |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 32 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 33 | 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 Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 35 | |
| 36 | .. code-block:: c++ |
| 37 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 38 | ndnHelper.setCsSize(1); |
| 39 | ... |
| 40 | ndnHelper.Install(nodes); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 41 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 42 | - Set CS size 100 on node1, size 1000 on node1, and size 2000 on all other nodes: |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 43 | |
| 44 | .. code-block:: c++ |
| 45 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 46 | 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 | |
| 60 | CS entry |
| 61 | ~~~~~~~~ |
| 62 | |
| 63 | The Data packet, along with other necessary fields, are stored in a CS entry. Each entry |
| 64 | contains: |
| 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 | |
| 70 | CS |
| 71 | ~~ |
| 72 | |
| 73 | A multi-index container is maintained in order to support the prioritized FIFO cache |
| 74 | replacement policy. In this way, pointers to the Data packets in a particular order are |
| 75 | kept. Note that this multi-index container is completely separated from the skip list |
| 76 | container, which indexes Content Store entries by name. |
| 77 | |
| 78 | The container (Cs::CleanupIndex) currently supports indexing of unsolicited Data packets, |
| 79 | indexing by packet staleness and indexing by packet arrival time. Calculation of the indexes is |
| 80 | performed in the container during the Data packet insertion (Cs::insert) in the Content Store. |
| 81 | |
| 82 | Eviction (Cs::evictItem) is performed during the insertion when the CS is full, and when the |
| 83 | capacity is decreased by management. We decided not to perform periodical cleanups, because its |
| 84 | CPU overhead causes jitter in packet forwarding. |
| 85 | |
| 86 | In the current version of NFD, cache replacement policy can be modified by adding different |
| 87 | indexes in the Cs::CleanupIndex container (refer to Boost.multiIndex documentation) and |
| 88 | implementing additional logic in Cs::evictItem function. |
| 89 | |
| 90 | For 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 | |
| 93 | Old Content Store Implementations |
| 94 | +++++++++++++++++++++++++++++++++ |
| 95 | |
| 96 | NFD's content store implementation takes full consideration of Interest selectors, however is |
| 97 | not yet flexible when it comes to cache replacement policies. Feature to extend CS flexibility |
| 98 | is 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 |
| 100 | ndnSIM 1.0 content store implementations to the new code base. These implementations feature |
| 101 | different cache replacement policies, but have very limited support for Interest selectors. If |
| 102 | your scenario relies on proper selector processing, do not use these implementations as the |
| 103 | simulation results most likely be incorrect. |
| 104 | |
| 105 | To 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 | |
| 114 | Available 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 | |
| 168 | Examples: |
| 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 Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 185 | |
| 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 Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 194 | - Disable CS on node2 |
Alexander Afanasyev | b42619d | 2014-02-17 12:11:25 -0800 | [diff] [blame] | 195 | |
| 196 | .. code-block:: c++ |
| 197 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 198 | ndnHelper.SetOldContentStore("ns3::ndn::cs::Nocache"); |
| 199 | ndnHelper.Install(node3); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 200 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 201 | - Track lifetime of CS entries (must use ``ns3::ndn::cs::*::LifetimeStats`` policy): |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 202 | |
| 203 | .. code-block:: c++ |
| 204 | |
| 205 | void |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 206 | CacheEntryRemoved(std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime) |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 207 | { |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 208 | std::cout << entry->GetName() << " " << lifetime.ToDouble(Time::S) << "s" << std::endl; |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | ... |
| 212 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 213 | ndnHelper.SetOldContentStore("ns3::ndn::cs::Stats::Lru", "MaxSize", "10000"); |
| 214 | ... |
| 215 | ndnHelper.Install(nodes); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 216 | |
| 217 | // connect to lifetime trace |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 218 | Config::Connect("/NodeList/*/$ns3::ndn::cs::Stats::Lru/WillRemoveEntry", MakeCallback(CacheEntryRemoved)); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 219 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 220 | - Get aggregate statistics of CS hit/miss ratio (works with any policy) |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 221 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 222 | 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 Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 224 | |
| 225 | .. code-block:: c++ |
| 226 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 227 | CsTracer::InstallAll("cs-trace.txt", Seconds(1)); |