To simulate Named Data Networking (NDN) projects using NS2, which needs expanding or integrating NS2 with NDN-specific functionalities, as NS2 does not natively support Named Data Networking. But, an NDN patch for NS2 has been improved by the NDN community to allow the replication of NDN-based communication and networking scenarios in NS2.
Below is a step-by-step guide on how to configure and replicate Named Data Networking projects in NS2 using this patch.
Steps to Simulate Named Data Networking Projects in NS2
- Install NS2 and the NDN Patch
Initially, we require to install NS2 and the NDN patch to replicate NDN functionalities.
Steps to Install NS2:
- We can download NS2 from the NS2 website.
- Follow the installation instructions for your operating system.
Steps to Install the NDN Patch:
- We can download the NDN patch for NS2 from the official NDN GitHub repository.
- Apply the patch to the NS2 installation:
- Extract the NDN patch files into the NS2 root directory.
- Rebuild NS2 by running make clean and make commands in the NS2 directory.
When the patch is applied effectively then NS2 will have NDN-specific components like the Interest, Data, and Forwarding classes to mimic NDN behavior.
- NDN Components in NS2
The NDN patch for NS2 launches numerous key modules needed for mimicking NDN communication:
- NDN Nodes: These nodes store and send data according to names instead of IP addresses.
- Interest Packets: Utilized by consumers to request data by name.
- Data Packets: Include the real data, which is returned by producers in response to Interest packets.
- Content Store (CS): A cache that stores Data packets temporarily for future retrieval.
- Forwarding Information Base (FIB): Conserves routing data to forward Interest packets toward the suitable producers.
- Pending Interest Table (PIT): Keeps track of all Interests waiting for a respective Data packet.
- Create an NDN Simulation in NS2
We will now make a TCL script to replicate NDN behaviour within NS2.
Example: Simple NDN Simulation
Below is an instance of a simple NDN simulation script in NS2, which illustrates communication between consumer and producer nodes:
# Create NS2 simulator instance
set ns [new Simulator]
# Create NDN-enabled nodes
set consumer [new Node/NDN]
set producer [new Node/NDN]
# Define the link between consumer and producer
$ns duplex-link $consumer $producer 1Mb 10ms DropTail
# Set up NDN application on consumer and producer
set interest [new Agent/NDN/Interest]
set data [new Agent/NDN/Data]
# Attach Interest agent to consumer and Data agent to producer
$ns attach-agent $consumer $interest
$ns attach-agent $producer $data
# Connect the Interest agent to the Data agent
$ns connect $interest $data
# Schedule the consumer to send an Interest packet
$ns at 1.0 “$interest send /ndn/content/1”
# Run the simulation
$ns at 10.0 “finish”
$ns run
What This Script Does:
- Makes two NDN-enabled nodes: one preforming as a consumer and the other as a producer.
- Configures a duplex link among the consumer and producer.
- The consumer transmits an Interest packet requesting content named /ndn/content/1.
- The producer responds with the respective Data packet.
- The simulation runs for 10 seconds.
- Simulating Advanced NDN Features
4.1. Content Store (Caching)
NDN supports in-network caching in which routers or intermediate nodes are store Data packets temporarily to work future requests faster. We can allow and set up the Content Store (CS) in the simulation script.
Example:
# Enable caching on the consumer
$consumer set cs_ [new Cache]
$consumer set cacheSize_ 50 # Cache size of 50 Data packets
This will enable caching on the consumer, which can cache Data packets for future retrieval without needing to send a new Interest to the producer.
4.2. Forwarding Information Base (FIB)
We can set up the Forwarding Information Base (FIB) to manage how Interest packets are forwarded across the network.
Example of configuring a custom FIB:
# Add FIB entries on the consumer to direct Interest packets to the producer
$consumer add-fib-entry /ndn/content/1 $producer
4.3. Pending Interest Table (PIT)
NDN nodes contain a Pending Interest Table (PIT) to monitor outgoing Interests waiting for a Data packet. We can manage how the PIT performs in NS2.
Example:
# Set the PIT lifetime (how long Interests are kept before expiring)
$consumer set pitLifetime_ 5 # Keep Interests in the PIT for 5 seconds
- Running the Simulation and Collecting Results
When the TCL script is configure with NDN functionality then we can run the simulation by invoking the NS2 simulator:
ns my_ndn_simulation.tcl
NS2 will generate a trace file, which records all communication events, like when Interest packets are transmitted, once Data packets are received, and other network statistics.
To investigate the simulation, use NS2’s built-in tracing capabilities:
# Enable tracing
set tracefile [open out.tr w]
$ns trace-all $tracefile
This will make a file called out.tr with detailed simulation logs.
- Visualizing NDN Network Simulation
We can envision the NDN communication using NAM (Network Animator) within NS2. To allow NAM visualization:
# Open NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
# Run NAM after the simulation
proc finish {} {
global ns namfile
$ns flush-trace
close $namfile
exec nam out.nam &
exit 0
}
Run NAM with:
nam out.nam
It will open a graphical representation of the NDN network and indicate how Interest and Data packets flow among the nodes.
- Advanced NDN Scenarios
We can prolong the simple NDN simulation to manage more complex scenarios, like:
7.1. Multi-Producer Network
In this scenario, we can replicate numerous producers presenting distinct kinds of content. The consumer transmits Interest packets, and the network routes them according to the requested content names.
Example of adding multiple producers:
set producer1 [new Node/NDN]
set producer2 [new Node/NDN]
# Set up multiple FIB entries for the consumer to access different producers
$consumer add-fib-entry /ndn/content/1 $producer1
$consumer add-fib-entry /ndn/content/2 $producer2
7.2. Mobility in NDN
If we require to replicate mobile consumers or producers then we can use NS2’s mobility models to move nodes in the course of the simulation.
Example:
# Set a random mobility pattern for the consumer
$ns at 2.0 “$consumer setdest 100 200 10.0”
It will move the consumer node to locate (100, 200) at a speed of 10 m/s.
- Analyze Performance Metrics
Key parameters to analyse in an NDN network simulation contain:
- Cache hit ratio: The percentage of requests worked from the cache instead of the original producer.
- Content retrieval delay: The time taken for a consumer to recover a Data packet after transmitting an Interest packet.
- Interest satisfaction ratio: The percentage of Interest packets, which are effectively satisfied by Data packets.
We can extract these parameters from the trace files are generated by NS2 during the simulation.We established a set of simulation steps to simulate and analyse the Named Data Networking Projects via NS2 platform. If needed we can explore this subject further and provide complete information. At phdprime.com, we will support you in achieving optimal simulation results in Named Data Networking. Additionally, we offer customized project ideas and topics in Named Data Networking that align with your interests when you collaborate with us. Furthermore, we assure you of exceptional writing services.