To simulate and evaluate NDN- based networks in ns-3, NDN model can be used.
Step-by-Step Guide to Implement Named Data Networking in ns-3
- Install ns-3:
- Ensure ns-3 is installed. Follow the installation instructions for ns-3 if you haven’t done so already.
- Install NDN Module for ns-3:
- The NDN module is not included by default in ns-3. You need to download and install it separately. The NDN project provides a special repository with the NDN module for ns-3.
- Clone the repository
git clone https://github.com/named-data-ndnSIM/ns-3-dev-ndnSIM.git ns-3
cd ns-3
./waf configure
./waf
Create a Simulation Script:
- Create a new script file, e.g., ndn-simulation.cc.
Include Necessary Headers:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/ndnSIM-module.h”
Define the Main Function:
using namespace ns3;
int main(int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse(argc, argv);
// Read optional command-line parameters (e.g., enable visualizer with ./waf –run=<> –visualize
Config::SetDefault(“ns3::ndn::L3Protocol::ContentStore::MaxSize”, StringValue(“100”)); // Cache size
Set Up the Network Topology:
- Create nodes and configure the NDN stack
NodeContainer nodes;
nodes.Create(3); // Create 3 nodes
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“1Gbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices;
devices = p2p.Install(nodes.Get(0), nodes.Get(1));
devices.Add(p2p.Install(nodes.Get(1), nodes.Get(2)));
// Install NDN stack on all nodes
ndn::StackHelper ndnHelper;
ndnHelper.InstallAll();
Set Up NDN Routing:
- Define the NDN forwarding strategy and set up the routing
// Choosing forwarding strategy
ndn::StrategyChoiceHelper::InstallAll(“/”, “/localhost/nfd/strategy/best-route”);
// Install NDN applications
ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
ndnGlobalRoutingHelper.InstallAll();
// Add /prefix origins to ndn::GlobalRouter
ndnGlobalRoutingHelper.AddOrigins(“/prefix”, nodes.Get(0)); // Node 0 will be the producer
// Calculate and install FIBs
ndn::GlobalRoutingHelper::CalculateRoutes();
Install NDN Applications:
- Create a producer application on one node and a consumer application on another node:
// Consumer
ndn::AppHelper consumerHelper(“ns3::ndn::ConsumerCbr”);
consumerHelper.SetPrefix(“/prefix”);
consumerHelper.SetAttribute(“Frequency”, StringValue(“10”)); // 10 interests per second
consumerHelper.Install(nodes.Get(2)); // Node 2 will be the consumer
// Producer
ndn::AppHelper producerHelper(“ns3::ndn::Producer”);
producerHelper.SetPrefix(“/prefix”);
producerHelper.SetAttribute(“PayloadSize”, StringValue(“1024”)); // 1024 bytes
producerHelper.Install(nodes.Get(0)); // Node 0 will be the producer
Configure Mobility (Optional):
- If you want to simulate mobility, you can configure the mobility model for the nodes:
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
positionAlloc->Add(Vector(0.0, 0.0, 0.0)); // Node 0
positionAlloc->Add(Vector(50.0, 0.0, 0.0)); // Node 1
positionAlloc->Add(Vector(100.0, 0.0, 0.0)); // Node 2
mobility.SetPositionAllocator(positionAlloc);
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
Run the Simulation:
- Define the simulation stop time and start the simulator
Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
return 0;
Example Complete Script (ndn-simulation.cc):
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/mobility-module.h”
#include “ns3/ndnSIM-module.h”
using namespace ns3;
int main(int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse(argc, argv);
// Read optional command-line parameters (e.g., enable visualizer with ./waf –run=<> –visualize)
Config::SetDefault(“ns3::ndn::L3Protocol::ContentStore::MaxSize”, StringValue(“100”)); // Cache size
NodeContainer nodes;
nodes.Create(3); // Create 3 nodes
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“1Gbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices;
devices = p2p.Install(nodes.Get(0), nodes.Get(1));
devices.Add(p2p.Install(nodes.Get(1), nodes.Get(2)));
// Install NDN stack on all nodes
ndn::StackHelper ndnHelper;
ndnHelper.InstallAll();
// Choosing forwarding strategy
ndn::StrategyChoiceHelper::InstallAll(“/”, “/localhost/nfd/strategy/best-route”);
// Install NDN applications
ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
ndnGlobalRoutingHelper.InstallAll();
// Add /prefix origins to ndn::GlobalRouter
ndnGlobalRoutingHelper.AddOrigins(“/prefix”, nodes.Get(0)); // Node 0 will be the producer
// Calculate and install FIBs
ndn::GlobalRoutingHelper::CalculateRoutes();
// Consumer
ndn::AppHelper consumerHelper(“ns3::ndn::ConsumerCbr”);
consumerHelper.SetPrefix(“/prefix”);
consumerHelper.SetAttribute(“Frequency”, StringValue(“10”)); // 10 interests per second
consumerHelper.Install(nodes.Get(2)); // Node 2 will be the consumer
// Producer
ndn::AppHelper producerHelper(“ns3::ndn::Producer”);
producerHelper.SetPrefix(“/prefix”);
producerHelper.SetAttribute(“PayloadSize”, StringValue(“1024”)); // 1024 bytes
producerHelper.Install(nodes.Get(0)); // Node 0 will be the producer
// Mobility (Optional)
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
positionAlloc->Add(Vector(0.0, 0.0, 0.0)); // Node 0
positionAlloc->Add(Vector(50.0, 0.0, 0.0)); // Node 1
positionAlloc->Add(Vector(100.0, 0.0, 0.0)); // Node 2
mobility.SetPositionAllocator(positionAlloc);
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
Explanation:
- Network Configuration:
- Nodes are created, and point-to-point links are set up between them.
- The NDN stack is installed on all nodes.
- Routing:
- The best-route forwarding strategy is chosen for all nodes.
- The global routing helper is used to calculate and install routes.
- Applications:
- A consumer application is installed on one node to request data.
- A producer application is installed on another node to provide the requested data.
- Mobility (Optional):
- Nodes are placed at specific positions using the ConstantPositionMobilityModel.
Implementing the named data networking in ns-3 is described clearly and simulated by NDN based networks rely on us for best guidance.
To simulate and evaluate NDN- based networks in ns-3, NDN model can be used.
Step-by-Step Guide to Implement Named Data Networking in ns-3
- Install ns-3:
- Ensure ns-3 is installed. Follow the installation instructions for ns-3 if you haven’t done so already.
- Install NDN Module for ns-3:
- The NDN module is not included by default in ns-3. You need to download and install it separately. The NDN project provides a special repository with the NDN module for ns-3.
- Clone the repository
git clone https://github.com/named-data-ndnSIM/ns-3-dev-ndnSIM.git ns-3
cd ns-3
./waf configure
./waf
Create a Simulation Script:
- Create a new script file, e.g., ndn-simulation.cc.
Include Necessary Headers:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/ndnSIM-module.h”
Define the Main Function:
using namespace ns3;
int main(int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse(argc, argv);
// Read optional command-line parameters (e.g., enable visualizer with ./waf –run=<> –visualize
Config::SetDefault(“ns3::ndn::L3Protocol::ContentStore::MaxSize”, StringValue(“100”)); // Cache size
Set Up the Network Topology:
- Create nodes and configure the NDN stack
NodeContainer nodes;
nodes.Create(3); // Create 3 nodes
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“1Gbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices;
devices = p2p.Install(nodes.Get(0), nodes.Get(1));
devices.Add(p2p.Install(nodes.Get(1), nodes.Get(2)));
// Install NDN stack on all nodes
ndn::StackHelper ndnHelper;
ndnHelper.InstallAll();
Set Up NDN Routing:
- Define the NDN forwarding strategy and set up the routing
// Choosing forwarding strategy
ndn::StrategyChoiceHelper::InstallAll(“/”, “/localhost/nfd/strategy/best-route”);
// Install NDN applications
ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
ndnGlobalRoutingHelper.InstallAll();
// Add /prefix origins to ndn::GlobalRouter
ndnGlobalRoutingHelper.AddOrigins(“/prefix”, nodes.Get(0)); // Node 0 will be the producer
// Calculate and install FIBs
ndn::GlobalRoutingHelper::CalculateRoutes();
Install NDN Applications:
- Create a producer application on one node and a consumer application on another node:
// Consumer
ndn::AppHelper consumerHelper(“ns3::ndn::ConsumerCbr”);
consumerHelper.SetPrefix(“/prefix”);
consumerHelper.SetAttribute(“Frequency”, StringValue(“10”)); // 10 interests per second
consumerHelper.Install(nodes.Get(2)); // Node 2 will be the consumer
// Producer
ndn::AppHelper producerHelper(“ns3::ndn::Producer”);
producerHelper.SetPrefix(“/prefix”);
producerHelper.SetAttribute(“PayloadSize”, StringValue(“1024”)); // 1024 bytes
producerHelper.Install(nodes.Get(0)); // Node 0 will be the producer
Configure Mobility (Optional):
- If you want to simulate mobility, you can configure the mobility model for the nodes:
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
positionAlloc->Add(Vector(0.0, 0.0, 0.0)); // Node 0
positionAlloc->Add(Vector(50.0, 0.0, 0.0)); // Node 1
positionAlloc->Add(Vector(100.0, 0.0, 0.0)); // Node 2
mobility.SetPositionAllocator(positionAlloc);
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
Run the Simulation:
- Define the simulation stop time and start the simulator
Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
return 0;
Example Complete Script (ndn-simulation.cc):
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/mobility-module.h”
#include “ns3/ndnSIM-module.h”
using namespace ns3;
int main(int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse(argc, argv);
// Read optional command-line parameters (e.g., enable visualizer with ./waf –run=<> –visualize)
Config::SetDefault(“ns3::ndn::L3Protocol::ContentStore::MaxSize”, StringValue(“100”)); // Cache size
NodeContainer nodes;
nodes.Create(3); // Create 3 nodes
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“1Gbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices;
devices = p2p.Install(nodes.Get(0), nodes.Get(1));
devices.Add(p2p.Install(nodes.Get(1), nodes.Get(2)));
// Install NDN stack on all nodes
ndn::StackHelper ndnHelper;
ndnHelper.InstallAll();
// Choosing forwarding strategy
ndn::StrategyChoiceHelper::InstallAll(“/”, “/localhost/nfd/strategy/best-route”);
// Install NDN applications
ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
ndnGlobalRoutingHelper.InstallAll();
// Add /prefix origins to ndn::GlobalRouter
ndnGlobalRoutingHelper.AddOrigins(“/prefix”, nodes.Get(0)); // Node 0 will be the producer
// Calculate and install FIBs
ndn::GlobalRoutingHelper::CalculateRoutes();
// Consumer
ndn::AppHelper consumerHelper(“ns3::ndn::ConsumerCbr”);
consumerHelper.SetPrefix(“/prefix”);
consumerHelper.SetAttribute(“Frequency”, StringValue(“10”)); // 10 interests per second
consumerHelper.Install(nodes.Get(2)); // Node 2 will be the consumer
// Producer
ndn::AppHelper producerHelper(“ns3::ndn::Producer”);
producerHelper.SetPrefix(“/prefix”);
producerHelper.SetAttribute(“PayloadSize”, StringValue(“1024”)); // 1024 bytes
producerHelper.Install(nodes.Get(0)); // Node 0 will be the producer
// Mobility (Optional)
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
positionAlloc->Add(Vector(0.0, 0.0, 0.0)); // Node 0
positionAlloc->Add(Vector(50.0, 0.0, 0.0)); // Node 1
positionAlloc->Add(Vector(100.0, 0.0, 0.0)); // Node 2
mobility.SetPositionAllocator(positionAlloc);
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
Explanation:
- Network Configuration:
- Nodes are created, and point-to-point links are set up between them.
- The NDN stack is installed on all nodes.
- Routing:
- The best-route forwarding strategy is chosen for all nodes.
- The global routing helper is used to calculate and install routes.
- Applications:
- A consumer application is installed on one node to request data.
- A producer application is installed on another node to provide the requested data.
- Mobility (Optional):
- Nodes are placed at specific positions using the ConstantPositionMobilityModel.
Implementing the named data networking in ns-3 is described clearly and simulated by NDN based networks rely on us for best guidance.