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 | |
spirosmastorakis | 2c9c005 | 2016-10-31 13:51:14 -0700 | [diff] [blame] | 6 | The Contest Store (CS) is implemented as a set of :ndnsim:`CS entries <nfd::cs::EntryImpl>`), |
| 7 | ordered by the full data name including the implicit digest. To manage entries, CS adopts a cache policy interface (:ndnsim:`nfd::cs::Policy`), invoked any time a CS entry is added, removed, updated, or used. |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 8 | |
spirosmastorakis | 2c9c005 | 2016-10-31 13:51:14 -0700 | [diff] [blame] | 9 | By default, ndnSIM uses NFD's Content Store with an option to use an old-style ndnSIM-specific content store implementations (see :ref:`old_cs`). The supported cache replacement policies are the following: |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 10 | |
spirosmastorakis | 2c9c005 | 2016-10-31 13:51:14 -0700 | [diff] [blame] | 11 | +----------------------------------------------+----------------------------------------------------------+ |
| 12 | | **NFD's Content Store Policies** | |
| 13 | +----------------------------------------------+----------------------------------------------------------+ |
| 14 | | ``nfd::cs::lru`` | Last Recently Used (LRU) | |
| 15 | +----------------------------------------------+----------------------------------------------------------+ |
| 16 | | ``nfd::cs::priority_fifo`` | Priority-Based First-In-First-Out (FIFO) | |
| 17 | +----------------------------------------------+----------------------------------------------------------+ |
| 18 | |
| 19 | For more detailed specification refer to the `NFD Developer's Guide |
| 20 | <https://named-data.net/wp-content/uploads/2016/03/ndn-0021-6-nfd-developer-guide.pdf>`_, section 3.3. |
| 21 | |
| 22 | |
| 23 | To control the maximum size and the policy of NFD's Content Store use :ndnsim:`StackHelper::setCsSize()` and |
| 24 | :ndnsim:`StackHelper::setPolicy()` methods: |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 25 | |
| 26 | .. code-block:: c++ |
| 27 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 28 | ndnHelper.setCsSize(<max-size-in-packets>); |
spirosmastorakis | 2c9c005 | 2016-10-31 13:51:14 -0700 | [diff] [blame] | 29 | ndnHelper.setPolicy(<replacement-policy>); |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 30 | ... |
| 31 | ndnHelper.Install(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 | Examples: |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 34 | |
spirosmastorakis | 2c9c005 | 2016-10-31 13:51:14 -0700 | [diff] [blame] | 35 | - To set CS size 100 on node1, size 1000 on node2, and size 2000 on all other nodes. |
| 36 | LRU replacement policy for node 1, priority FIFO for the rest: |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 37 | |
| 38 | .. code-block:: c++ |
| 39 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 40 | ndnHelper.setCsSize(100); |
spirosmastorakis | 2c9c005 | 2016-10-31 13:51:14 -0700 | [diff] [blame] | 41 | ndnHelper.setPolicy("nfd::cs::lru"); |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 42 | ndnHelper.Install(node1); |
| 43 | |
| 44 | ndnHelper.setCsSize(1000); |
spirosmastorakis | 2c9c005 | 2016-10-31 13:51:14 -0700 | [diff] [blame] | 45 | ndnHelper.setPolicy("nfd::cs::priority_fifo"); |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 46 | ndnHelper.Install(node2); |
| 47 | |
| 48 | NodeContainer allOtherNodes; |
| 49 | for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i) { |
| 50 | if (*i != node1 && *i != node2) { |
| 51 | allOtherNodes.Add(*i); |
| 52 | } |
| 53 | } |
| 54 | ndnHelper.Install(allOtherNodes); |
| 55 | |
spirosmastorakis | 2c9c005 | 2016-10-31 13:51:14 -0700 | [diff] [blame] | 56 | - To effectively disable NFD content store an all nodes |
| 57 | |
| 58 | Minimum allowed value for NFD content store maximum size is 1. If 0 is specified, it will be assumed |
| 59 | that the old content store implementation should be used. |
| 60 | |
| 61 | .. code-block:: c++ |
| 62 | |
| 63 | ndnHelper.setCsSize(1); |
| 64 | ... |
| 65 | ndnHelper.Install(nodes); |
| 66 | |
| 67 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 68 | CS entry |
| 69 | ~~~~~~~~ |
| 70 | |
| 71 | The Data packet, along with other necessary fields, are stored in a CS entry. Each entry |
| 72 | contains: |
| 73 | |
| 74 | - the Data packet |
| 75 | - flag indicating whether the Data packet is unsolicited |
| 76 | - the timestamp at which the cached Data becomes stale |
| 77 | |
spirosmastorakis | 2c9c005 | 2016-10-31 13:51:14 -0700 | [diff] [blame] | 78 | .. _old_cs: |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 79 | |
| 80 | Old Content Store Implementations |
| 81 | +++++++++++++++++++++++++++++++++ |
| 82 | |
spirosmastorakis | 2c9c005 | 2016-10-31 13:51:14 -0700 | [diff] [blame] | 83 | We have also ported the old ndnSIM 1.0 content store implementations to the new code base. |
| 84 | These implementations feature different cache replacement policies, but have very limited |
| 85 | support for Interest selectors. If your scenario relies on proper selector processing, |
| 86 | do not use these implementations as the simulation results most likely be incorrect. |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 87 | |
| 88 | To select old content store implementations, use :ndnsim:`StackHelper::SetOldContentStore`: |
| 89 | |
| 90 | .. code-block:: c++ |
| 91 | |
| 92 | ndnHelper.SetOldContentStore("<content store implementation>", |
| 93 | ["<optional parameter>", "<optional parameter's value>" [, ...]]); |
| 94 | ... |
| 95 | ndnHelper.Install (nodes); |
| 96 | |
| 97 | Available old content store implementations are listed in the following table: |
| 98 | |
| 99 | |
| 100 | +----------------------------------------------+----------------------------------------------------------+ |
| 101 | | **Simple content stores** | |
| 102 | +----------------------------------------------+----------------------------------------------------------+ |
| 103 | | ``ns3::ndn::cs::Lru`` | **Least recently used (LRU) (default)** | |
| 104 | +----------------------------------------------+----------------------------------------------------------+ |
| 105 | | ``ns3::ndn::cs::Fifo`` | First-in-first-Out (FIFO) | |
| 106 | +----------------------------------------------+----------------------------------------------------------+ |
| 107 | | ``ns3::ndn::cs::Lfu`` | Least frequently used (LFU) | |
| 108 | +----------------------------------------------+----------------------------------------------------------+ |
| 109 | | ``ns3::ndn::cs::Random`` | Random | |
| 110 | +----------------------------------------------+----------------------------------------------------------+ |
| 111 | | ``ns3::ndn::cs::Nocache`` | Policy that completely disables caching | |
| 112 | +----------------------------------------------+----------------------------------------------------------+ |
| 113 | +----------------------------------------------+----------------------------------------------------------+ |
| 114 | | **Content stores with entry lifetime tracking** | |
| 115 | | | |
| 116 | | These policies allow evaluation of CS enties lifetime (i.e., how long entries stay in CS) | |
| 117 | +----------------------------------------------+----------------------------------------------------------+ |
| 118 | | ``ns3::ndn::cs::Stats::Lru`` | Least recently used (LRU) | |
| 119 | +----------------------------------------------+----------------------------------------------------------+ |
| 120 | | ``ns3::ndn::cs::Stats::Fifo`` | Least frequently used (LFU) | |
| 121 | +----------------------------------------------+----------------------------------------------------------+ |
| 122 | | ``ns3::ndn::cs::Stats::Lfu`` | Random | |
| 123 | +----------------------------------------------+----------------------------------------------------------+ |
| 124 | | ``ns3::ndn::cs::Stats::Random`` | Policy that completely disables caching | |
| 125 | +----------------------------------------------+----------------------------------------------------------+ |
| 126 | +----------------------------------------------+----------------------------------------------------------+ |
| 127 | | **Content stores respecting freshness field of Data packets** | |
| 128 | | | |
| 129 | | These policies cache Data packets only for the time indicated by FreshnessPeriod. | |
| 130 | +----------------------------------------------+----------------------------------------------------------+ |
| 131 | | ``ns3::ndn::cs::Freshness::Lru`` | Least recently used (LRU) | |
| 132 | +----------------------------------------------+----------------------------------------------------------+ |
| 133 | | ``ns3::ndn::cs::Freshness::Fifo`` | Least frequently used (LFU) | |
| 134 | +----------------------------------------------+----------------------------------------------------------+ |
| 135 | | ``ns3::ndn::cs::Freshness::Lfu`` | Random | |
| 136 | +----------------------------------------------+----------------------------------------------------------+ |
| 137 | | ``ns3::ndn::cs::Freshness::Random`` | Policy that completely disables caching | |
| 138 | +----------------------------------------------+----------------------------------------------------------+ |
| 139 | +----------------------------------------------+----------------------------------------------------------+ |
| 140 | | **Content store realization that probabilistically accepts data packet into CS (placement policy)** | |
| 141 | +----------------------------------------------+----------------------------------------------------------+ |
| 142 | | ``ns3::ndn::cs::Probability::Lru`` | Least recently used (LRU) | |
| 143 | +----------------------------------------------+----------------------------------------------------------+ |
| 144 | | ``ns3::ndn::cs::Probability::Fifo`` | Least frequently used (LFU) | |
| 145 | +----------------------------------------------+----------------------------------------------------------+ |
| 146 | | ``ns3::ndn::cs::Probability::Lfu`` | Random | |
| 147 | +----------------------------------------------+----------------------------------------------------------+ |
| 148 | | ``ns3::ndn::cs::Probability::Random`` | Policy that completely disables caching | |
| 149 | +----------------------------------------------+----------------------------------------------------------+ |
| 150 | |
| 151 | Examples: |
| 152 | |
| 153 | |
| 154 | - Select simple LRU policy on node1, simple FIFO policy on node2, and simple random policy on |
| 155 | other nodes with maximum CS sizes of 10000 packets: |
| 156 | |
| 157 | .. code-block:: c++ |
| 158 | |
| 159 | ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", "10000"); |
| 160 | ndnHelper.Install(node1); |
| 161 | |
| 162 | ndnHelper.SetOldContentStore("ns3::ndn::cs::Fifo", "MaxSize", "10000"); |
| 163 | ndnHelper.Install(node2); |
| 164 | |
| 165 | ndnHelper.SetOldContentStore("ns3::ndn::cs::Random", "MaxSize", "10000"); |
| 166 | ... |
| 167 | ndnHelper.Install(otherNodes); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 168 | |
| 169 | .. note:: |
| 170 | |
| 171 | If ``MaxSize`` parameter is omitted, then will be used a default value (100). |
| 172 | |
| 173 | .. note:: |
| 174 | |
| 175 | If ``MaxSize`` is set to 0, then no limit on ContentStore will be enforced |
| 176 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 177 | - Disable CS on node2 |
Alexander Afanasyev | b42619d | 2014-02-17 12:11:25 -0800 | [diff] [blame] | 178 | |
| 179 | .. code-block:: c++ |
| 180 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 181 | ndnHelper.SetOldContentStore("ns3::ndn::cs::Nocache"); |
| 182 | ndnHelper.Install(node3); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 183 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 184 | - Track lifetime of CS entries (must use ``ns3::ndn::cs::*::LifetimeStats`` policy): |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 185 | |
| 186 | .. code-block:: c++ |
| 187 | |
| 188 | void |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 189 | CacheEntryRemoved(std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime) |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 190 | { |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 191 | std::cout << entry->GetName() << " " << lifetime.ToDouble(Time::S) << "s" << std::endl; |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | ... |
| 195 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 196 | ndnHelper.SetOldContentStore("ns3::ndn::cs::Stats::Lru", "MaxSize", "10000"); |
| 197 | ... |
| 198 | ndnHelper.Install(nodes); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 199 | |
| 200 | // connect to lifetime trace |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 201 | Config::Connect("/NodeList/*/$ns3::ndn::cs::Stats::Lru/WillRemoveEntry", MakeCallback(CacheEntryRemoved)); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 202 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 203 | - Get aggregate statistics of CS hit/miss ratio (works with any policy) |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 204 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 205 | The simplest way tro track CS hit/miss statistics is to use :ndnsim:`CsTracer`, in more |
| 206 | details described in :ref:`Metrics Section <cs trace helper>`. |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 207 | |
| 208 | .. code-block:: c++ |
| 209 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 210 | CsTracer::InstallAll("cs-trace.txt", Seconds(1)); |