NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
Overall ndnSIM documentation

Content Store

ndnSIM comes with several different in-memory content store implementations, featuring different cache replacement policies.

To select a particular content store and configure its capacity, use SetContentStore() helper method

Simple content stores

Least Recently Used (LRU) (default)

Implementation name: ndn::cs::Lru.

Usage example:

ndnHelper.SetContentStore ("ns3::ndn::cs::Lru",
                           "MaxSize", "10000");
...
ndnHelper.Install (nodes);

First-In-First-Out (FIFO)

Implementation name: ndn::cs::Fifo

Usage example:

ndnHelper.SetContentStore ("ns3::ndn::cs::Fifo",
                           "MaxSize", "10000");
...
ndnHelper.Install (nodes);

Random

Implementation name: ndn::cs::Random

Usage example:

ndnHelper.SetContentStore ("ns3::ndn::cs::Random",
                           "MaxSize", "10000");
...
ndnHelper.Install (nodes);

Note

If MaxSize parameter is omitted, then will be used a default value (100).

Note

If MaxSize is set to 0, then no limit on ContentStore will be enforced

Nocache

Trivial implementation of the ContentStore that does not really do any caching.

Usage example:

ndnHelper.SetContentStore ("ns3::ndn::cs::Nocache");
...
ndnHelper.Install (nodes);

Content stores with entry lifetime tracking

In order to evaluate lifetime of the content store entries, the special versions of the content store need to be used:

Least Recently Used (LRU)

Implementation name: ndn::cs::Stats::Lru.

Usage example:

void
CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
{
    std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl;
}

...

ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Lru",
                           "MaxSize", "10000");
...
ndnHelper.Install (nodes);

// connect to lifetime trace
Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Lru/WillRemoveEntry", MakeCallback (CacheEntryRemoved));

First-In-First-Out (FIFO)

Implementation name: ndn::cs::Stats::Fifo.

Usage example:

void
CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
{
    std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl;
}

...

ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Fifo",
                           "MaxSize", "10000");
...
ndnHelper.Install (nodes);

// connect to lifetime trace
Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Fifo/WillRemoveEntry", MakeCallback (CacheEntryRemoved));

Random

Implementation name: ndn::cs::Stats::Random

Usage example:

void
CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
{
    std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl;
}

...

ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Random",
                           "MaxSize", "10000");
...
ndnHelper.Install (nodes);

// connect to lifetime trace
Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Random/WillRemoveEntry", MakeCallback (CacheEntryRemoved));

Content stores respecting freshness field of ContentObjects

If simulations need Content Store which respects freshness of ContentObjects, the following versions of content store should be used:

Least Recently Used (LRU)

Implementation name: ndn::cs::Freshness::Lru.

Usage example:

...

ndnHelper.SetContentStore ("ns3::ndn::cs::Freshness::Lru",
                           "MaxSize", "10000");
...

First-In-First-Out (FIFO)

Implementation name: ndn::cs::Freshness::Fifo

Usage example:

...

ndnHelper.SetContentStore ("ns3::ndn::cs::Freshness::Fifo",
                           "MaxSize", "10000");
...

Random

Implementation name: ndn::cs::Freshness::Random

Usage example:

...

ndnHelper.SetContentStore ("ns3::ndn::cs::Freshness::Random",
                           "MaxSize", "10000");
...

Example

The following example demonstrates a basic usage of a customized content store (ndn-simple-with-content-freshness.cc). In this scenario two simple consumers (both installed on a consumer node) continually request the same data packet. When 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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// ndn-simple.cc
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/ndnSIM-module.h"

using namespace ns3;

int 
main (int argc, char *argv[])
{
  // setting default parameters for PointToPoint links and channels
  Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
  Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
  Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse (argc, argv);

  // Creating nodes
  NodeContainer nodes;
  nodes.Create (3);

  // Connecting nodes using two links
  PointToPointHelper p2p;
  p2p.Install (nodes.Get (0), nodes.Get (1));
  p2p.Install (nodes.Get (1), nodes.Get (2));

  // Install CCNx stack on all nodes
  ndn::StackHelper ccnxHelper;
  ccnxHelper.SetDefaultRoutes (true);
  ccnxHelper.SetContentStore ("ns3::ndn::cs::Freshness::Lru",
                              "MaxSize", "2"); // allow just 2 entries to be cached
  ccnxHelper.InstallAll ();

  // Installing applications

  // Consumer
  ndn::AppHelper consumerHelper ("DumbRequester");

  // /*
  //   1) at time 1 second requests Data from a producer that does not specify freshness
  //   2) at time 10 seconds requests the same Data packet as client 1

  //   3) at time 2 seconds requests Data from a producer that specifies freshness set to 2 seconds
  //   4) at time 12 seconds requests the same Data packet as client 3

  //   Expectation:
  //   Interests from 1, 3 and 4 will reach producers
  //   Interset from 2 will be served from cache
  //  */

  ApplicationContainer apps;
  
  consumerHelper.SetPrefix ("/no-freshness");
  apps = consumerHelper.Install (nodes.Get (0));
  apps.Start (Seconds (0.1));
  apps.Stop  (Seconds (10.0));

  consumerHelper.SetPrefix ("/with-freshness");
  apps = consumerHelper.Install (nodes.Get (0));
  apps.Start (Seconds (20.1));
  apps.Stop  (Seconds (30.0));
  
  // Producer
  ndn::AppHelper producerHelper ("ns3::ndn::Producer");
  producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));

  producerHelper.SetAttribute ("Freshness", TimeValue (Seconds (0))); // unlimited freshness
  producerHelper.SetPrefix ("/no-freshness");
  producerHelper.Install (nodes.Get (2)); // last node

  producerHelper.SetAttribute ("Freshness", TimeValue (Seconds (2.0))); // freshness 2 seconds (!!! freshness granularity is 1 seconds !!!)
  producerHelper.SetPrefix ("/with-freshness");
  producerHelper.Install (nodes.Get (2)); // last node
                               
  Simulator::Stop (Seconds (30.0));

  Simulator::Run ();
  Simulator::Destroy ();

  return 0;
}

To run this scenario, use the following command:

NS_LOG=DumbRequester:ndn.cs.Freshness.Lru ./waf --run=ndn-simple-with-content-freshness