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 | |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame] | 9 | 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 | |
Alexander Afanasyev | 2481092 | 2019-02-10 22:06:43 -0500 | [diff] [blame] | 23 | To control the maximum size and the policy of NFD's Content Store use ``StackHelper::setCsSize()`` and |
| 24 | ``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 | |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame] | 58 | Minimum allowed value for NFD content store maximum size is 1. |
spirosmastorakis | 2c9c005 | 2016-10-31 13:51:14 -0700 | [diff] [blame] | 59 | |
| 60 | .. code-block:: c++ |
| 61 | |
| 62 | ndnHelper.setCsSize(1); |
| 63 | ... |
| 64 | ndnHelper.Install(nodes); |
| 65 | |
| 66 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 67 | CS entry |
| 68 | ~~~~~~~~ |
| 69 | |
| 70 | The Data packet, along with other necessary fields, are stored in a CS entry. Each entry |
| 71 | contains: |
| 72 | |
| 73 | - the Data packet |
| 74 | - flag indicating whether the Data packet is unsolicited |
| 75 | - the timestamp at which the cached Data becomes stale |
| 76 | |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame] | 77 | Misc |
| 78 | ~~~~ |
| 79 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 80 | - Get aggregate statistics of CS hit/miss ratio (works with any policy) |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 81 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 82 | The simplest way tro track CS hit/miss statistics is to use :ndnsim:`CsTracer`, in more |
| 83 | details described in :ref:`Metrics Section <cs trace helper>`. |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 84 | |
| 85 | .. code-block:: c++ |
| 86 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 87 | CsTracer::InstallAll("cs-trace.txt", Seconds(1)); |