How to Start Wireless Projects Using NS2
To start a wireless network project in NS2 (Network Simulator 2) which needs to replicate the wireless interaction systems with wireless nodes, protocols such as TCP, UDP, and routing protocols, mobility models, and traffic models. NS2 environment offers a robust environment for replicating wireless networks like Wi-Fi, MANETs (Mobile Ad Hoc Networks), and sensor networks.
Below is a sequential method on how to start a wireless network project in NS2.
Steps to Start Wireless Network Project in NS2
- Install NS2 (Network Simulator 2)
Initially, we make sure that NS2 is installed on the machine. If not, we adhere to these steps based on OS like Linux/Ubuntu:
- Install dependencies:
sudo apt-get update
sudo apt-get install build-essential autoconf gcc g++ libxmu-dev
- Download NS2:
- We can download the NS2 source code using NS2 official website.
- Otherwise, we need to download it to utilise below command:
wget https://www.isi.edu/nsnam/ns/ns-allinone-2.35.tar.gz
- Extract and Install:
tar -xvzf ns-allinone-2.35.tar.gz
cd ns-allinone-2.35
./install
- Set environment variables: Integrate the below command lines to the ~/.bashrc file:
export PATH=$PATH:/path/to/ns-allinone-2.35/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/ns-allinone-2.35/lib
- Run NS2:
ns
- Create the Basic Wireless Network Topology
When NS2 is installed then we need to make a simple wireless network including nodes, which interact through the wireless channels.
Example: Basic Wireless Network (Two Nodes)
This basic example illustrates a simple wireless communication among two nodes with the support of UDP.
# Create the NS simulator instance
set ns [new Simulator]
# Create wireless nodes
set node1 [$ns node]
set node2 [$ns node]
# Set up the wireless link between the two nodes (1 Mbps, 10ms delay)
$ns wireless-link $node1 $node2 1Mb 10ms
# Set up UDP communication between nodes
set udp [new Agent/UDP]
$ns attach-agent $node1 $udp
set sink [new Agent/Null]
$ns attach-agent $node2 $sink
$ns connect $udp $sink
# Start the UDP data transmission at time 1.0s
$ns at 1.0 “$udp send”
$ns at 5.0 “finish”
# Run the simulation
$ns run
# Procedure to finish the simulation
proc finish {} {
global ns
$ns flush-trace
exit 0
}
Explanation:
- Wireless Link: $ns wireless-link makes a wireless link among two nodes including a delay of 10ms and a bandwidth of 1 Mbps.
- UDP Traffic: A UDP agent is connected to node1, and a Null agent is linked to node2. The UDP agent transmits packets to the Null agent.
- Simulation Control: After 1 second ($ns at 1.0 “$udp send”), traffic is transmitted and the simulation ends at 5 seconds.
- Add Mobility to Wireless Nodes
Wireless networks are frequently moveable such as in Mobile Ad Hoc Networks (MANETs), and we can describe mobility models. NS2 environment offer numerous mobility models for replicating realistic movement models for nodes.
Example: Random Waypoint Mobility Model
In this case, we may utilise Random Waypoint mobility pattern in which nodes arbitrarily move in a defined area.
# Set up simulator
set ns [new Simulator]
# Create mobile nodes
set node1 [$ns node]
set node2 [$ns node]
# Set up the wireless link
$ns wireless-link $node1 $node2 1Mb 10ms
# Set up UDP communication
set udp [new Agent/UDP]
$ns attach-agent $node1 $udp
set sink [new Agent/Null]
$ns attach-agent $node2 $sink
$ns connect $udp $sink
# Set mobility model for random movement
$node1 set X_ 0.0
$node1 set Y_ 0.0
$node2 set X_ 100.0
$node2 set Y_ 100.0
# Use random waypoint mobility
$ns at 0.0 “$node1 random-motion”
$ns at 0.0 “$node2 random-motion”
# Start UDP data transmission
$ns at 1.0 “$udp send”
# Run the simulation
$ns at 5.0 “finish”
$ns run
proc finish {} {
global ns
$ns flush-trace
exit 0
}
Explanation:
- Mobility: The random-motion approach creates the nodes that arbitrarily shift in a defined area.
- Random Waypoint: A mobility model, which allocates a random destination and speed to nodes at each time stage.
- Implement Routing Protocols for Wireless Networks
Routing protocols handle how data packets are sent among the nodes in wireless networks. NS2 environment offers a various kinds of wireless routing protocols like AODV (Ad hoc On-Demand Distance Vector) and DSR (Dynamic Source Routing).
Example: Using AODV for Routing
# Set up simulator and create nodes
set ns [new Simulator]
set node1 [$ns node]
set node2 [$ns node]
# Set the routing protocol to AODV
$node1 set protocol AODV
$node2 set protocol AODV
# Set up wireless link between nodes
$ns wireless-link $node1 $node2 1Mb 10ms
# Set up UDP communication
set udp [new Agent/UDP]
$ns attach-agent $node1 $udp
set sink [new Agent/Null]
$ns attach-agent $node2 $sink
$ns connect $udp $sink
# Start data transmission at time 1.0s
$ns at 1.0 “$udp send”
# Run the simulation
$ns at 5.0 “finish”
$ns run
proc finish {} {
global ns
$ns flush-trace
exit 0
}
Explanation:
- Routing Protocol: The set protocol AODV command configures the routing protocol to AODV for both nodes.
- Data Transmission: The UDP agent transmits the packets among the nodes.
- Add Traffic and Applications
We will need to replicate various kinds of traffic such as FTP, CBR (Constant Bit Rate), Telnet, and so on, and applications for producing network load and monitor how wireless nodes interact.
Example: CBR Traffic for Wireless Nodes
# Create simulator and nodes
set ns [new Simulator]
set node1 [$ns node]
set node2 [$ns node]
# Set up wireless link
$ns wireless-link $node1 $node2 1Mb 10ms
# Create CBR traffic for UDP communication
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $node1
$cbr set packetSize_ 512
$cbr set rate_ 1000
$cbr set dstNode $node2
# Start the traffic at 1 second
$ns at 1.0 “$cbr start”
# End the simulation at 5 seconds
$ns at 5.0 “finish”
# Run the simulation
$ns run
proc finish {} {
global ns
$ns flush-trace
exit 0
}
Explanation:
- CBR Traffic: this configuration a Constant Bit Rate (CBR) traffic source, which makes continuous traffic at particular rate as 1000 packets for each second.
- Traffic Generation: The start technique establishes the traffic generation at 1 second.
- Run the Simulation and Analyze Results
When we have described the topology, mobility, routing protocols, and traffic then execute the simulation:
ns wireless_network_simulation.tcl
It will be replicated the network and produced output files like:
- Trace File (.tr): It has in-depth data regarding packet transfers, node movements, and so on.
- NAM File (.nam): Envision the simulation to utilise Network Animator (NAM).
We can examine the simulation to utilise:
- AWK Scripts to execute the trace file for performance parameters like throughput, latency, and packet loss.
- Denote how the nodes and packets communicate visually using NAM.
nam wireless_network_simulation.nam
- Extend the Simulation
When, we’ve configured the simple wireless simulation then we will need to prolong it by:
- Integrating additional nodes to the network and monitoring the scalability.
- Executing more routing protocols such as DSR, OLSR, or TORA.
- Replicating various mobility models for more complex mobility models.
- Launching network failures for replicating reliability problems.
- Incorporating QoS metrics like bandwidth, jitter, and delay.
Conclusion
Starting a wireless network project using NS2:
- Initially, install NS2 and configure the environment.
- Create a network topology and make nodes.
- Configure wireless communication link among the nodes.
- Execute routing protocols and set traffic generation.
- If replicating mobile networks then integrate mobility models.
- Execute the simulation using NAM for visualization.
- Examine the outcomes to utilise trace files and performance parameters.
You can begin simulating a various kinds of Wireless Networks and testing with protocols, mobility and traffic models in OMNeT++ by following these steps with more information will be added later.