How to Start Decentralized Networks Projects Using NS2
To start a Decentralized Network project in Network Simulator 2 (NS2), we can replicate a network environment in which nodes (devices) interact devoid of a central server or authority. It has no single point of control, and each node may make decisions individually regarding the routing and interaction within a decentralized network. Decentralized networks are commonly utilised for peer-to-peer (P2P) networks, blockchain, mesh networks, and distributed computing.
Replicating the decentralized networks in NS2, we learn the core components like distributed routing, peer-to-peer communication, autonomous decision-making, and the lack of a central controller.
Key Concepts in Decentralized Networks
- Peer-to-Peer (P2P) Networks: Each device (peer) can perform like both a server and a client which are distributing resources like data, bandwidth, and so on, with other devices in a P2P network.
- Mesh Networks: A mesh network enables every single node to transmit data for other nodes, to make a decentralized routing system.
- Distributed Routing Protocols: These routing protocols like AODV, OLSR, or DSR are utilised to transmit devoid of a central authority.
NS2 environment permits for replicating decentralized network scenarios by means of designing the distributed routing protocols and autonomous communication among the nodes. Below is a sequential method to getting started with decentralized network simulation in NS2.
Steps to Start Decentralized Networks Projects in NS2
Step 1: Install NS2
We can download and set up NS2 using official NS2 website and adhere to the installation guidance based on the OS.
Confirm the installation by executing:
ns
NS2 is properly installed as the NS2 prompt launches.
Step 2: Understand the Components of a Decentralized Network
In a decentralized network, nodes need the below given roles like:
- Peers: Every single node can directly interact with other nodes devoid of central authority.
- Routing Protocols: Distributed routing protocols such as AODV (Ad hoc On-demand Distance Vector) or DSR (Dynamic Source Routing) are frequently utilised within decentralized networks.
- Traffic Generation: The nodes can make traffic, which replicates the data exchange among the peers.
Following is key modules to replicate a decentralized network using NS2:
- Nodes: It provides devices within the network.
- Routing Protocol: A distributed routing protocol to handle the network routes using AODV, OLSR protocols.
- Traffic Generators: These nodes will be replicated the data traffic among the peers.
- Communication Links: Interaction channels among the nodes which normally used wireless connections.
Step 3: Define the Network Topology
We can create a network topology might be structured like a mesh network or peer-to-peer (P2P) network in which every single node contains direct or indirect interaction with other nodes for a decentralized network. Here’s a required modules:
- Source Node: A node, which makes traffic.
- Destination Node: A node that obtains traffic.
- Intermediate Nodes: Nodes that transmit the information among the source and destination nodes.
Below is an instance of a basic topology:
- A collection of nodes including random positions.
- Every single node interacts with their neighbors (or via other nodes) that build a mesh network.
Step 4: Choose a Distributed Routing Protocol
With the help of distributed routing protocol, we can execute the decentralized communication. Below are common protocols using NS2:
- AODV (Ad hoc On-demand Distance Vector): It is a reactive routing protocol.
- DSR (Dynamic Source Routing): It is known as another on-demand routing protocol which is same to AODV protocol.
- OLSR (Optimized Link State Routing): It is proactive routing protocol that appropriate for highly dynamic networks.
These protocols don’t depend on a central authority and according to the local data we can make routing decisions. For this case, replicate the decentralized routing by AODV.
Step 5: Create the NS2 Simulation Script
Here’s an instance of a decentralized network to utilise AODV routing protocol. In this script, nodes autonomously interact deprived of a central server, and in the network, each node can be launched the routes to other nodes.
Example: Decentralized Network Simulation Using AODV
# Create the simulator object
set ns [new Simulator]
# Create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
# Set node positions (e.g., random placement in a 500×500 area)
$ns node-config -x 500 -y 500 -c 50
$ns at 0.0 “$n0 set X_ 100; $n0 set Y_ 100”
$ns at 0.0 “$n1 set X_ 200; $n1 set Y_ 200”
$ns at 0.0 “$n2 set X_ 300; $n2 set Y_ 300”
$ns at 0.0 “$n3 set X_ 400; $n3 set Y_ 400”
$ns at 0.0 “$n4 set X_ 500; $n4 set Y_ 500”
# Use AODV for routing
$ns rtproto AODV
# Create traffic generation
set udp0 [new Agent/UDP]
set udp1 [new Agent/UDP]
set cbr0 [new Application/Traffic/CBR]
set cbr1 [new Application/Traffic/CBR]
# Attach UDP agents to nodes
$ns attach-agent $n0 $udp0
$ns attach-agent $n4 $udp1
# Attach CBR traffic to UDP agents
$cbr0 attach-agent $udp0
$cbr1 attach-agent $udp1
# Set traffic parameters (packet size, interval)
$cbr0 set packetSize_ 512
$cbr0 set interval_ 0.1
$cbr1 set packetSize_ 512
$cbr1 set interval_ 0.1
# Start traffic
$ns at 1.0 “$cbr0 start”
$ns at 1.0 “$cbr1 start”
# Set end times for traffic
$ns at 4.0 “$cbr0 stop”
$ns at 4.0 “$cbr1 stop”
# Finish the simulation
$ns at 5.0 “finish”
# Define finish procedure
proc finish {} {
global ns
$ns flush-trace
exit 0
}
# Run the simulation
$ns run
Explanation of the Script:
- Create the Simulator Object:
- set ns [new Simulator]: It helps to make the NS2 simulator entity.
- Create Nodes:
- In this example, five nodes are made by $ns node. These nodes can build the decentralized network.
- Node Placement:
- The nodes are located at particular places within a 500×500 area to use random positions as required.
- Routing Protocol:
- set ns rtproto AODV: In the network, AODV routing protocol is allowed for decentralized routing.
- Traffic Generation:
- Two CBR (Constant Bit Rate) traffic sources are made that one traffic source (udp0 and cbr0) transmits the traffic from nodes like n0 to n4, and the other (udp1 and cbr1) forwards the traffic again.
- Traffic Control:
- Traffic begins at 1.0 seconds and ends at 4.0 seconds.
- Finish the Simulation:
- The end of simulation is known as finish the simulation which stops at 5.0 seconds.
- Run the Simulation:
- The simulation executes and utilises a trace file including the packet transmission information.
Step 6: Run the Simulation
We need to store the simulation script like decentralized_network.tcl and execute the simulation with NS2:
ns decentralized_network.tcl
Step 7: Analyze the Results
When simulation is executed then we acquire running trace file (*.tr) with simulation event record. We will need to examine diverse performance parameters like packet delivery ratio, latency, throughput, and routing efficiency with AWK or Xgraph.
For example, to analyze the packets received by the destination node:
awk ‘{ if ($1 == “r”) print $0 }’ tracefile.tr > received_packets.txt
Step 8: Extend the Simulation
Deliberate more aspects of decentralized networks to prolong the simulation:
- Mesh Network:
- In a mesh network, integrate additional nodes and replicate the decentralized routing.
- Dynamic Traffic Generation:
- Launch dynamic traffic models in which nodes can alter the traffic sources or destinations nodes in the course of the simulation.
- Security:
- Execute the security protocols for defending the interaction within decentralized network.
- Fault Tolerance:
- Mimic node failures or link failures for experimenting decentralized network’s robustness and fault tolerance.
- Scalability:
- Maximize the volume of nodes for replicating how the network measures and how routing performance is impacted by network size.
Conclusion
To replicate a decentralized network in NS2 which is generally utilised for peer-to-peer communication, distributed routing, and autonomous decision-making in a network. We need to design decentralized interaction with AODV or DSR protocols and focus on diverse network performance parameters like latency, throughput, and packet loss. We need to prolong the simulation by exploring more complex network scenarios with mesh networks, dynamic traffic, and security features.
We have completed the simulations for Decentralized Networks Projects using a structured stepwise approach in NS2 environment. We plan to distribute more innovative insights and concepts about this project in future.