How to Start Network Project Using NS2
To create a network project using NS2 (Network Simulator 2) has includes the replicating of communication systems and understanding network topology, protocols, and congestion models. NS2 is widely used for replicating together wired and wireless networks. Here’s a step-by-step guide on how to start a network project using NS2.
Steps to Start Network project Using NS2
- Install NS2
Previously starting the project, we want to assure which NS2 is installed on your machine. If you do not have the NS2 installed yet, we can follow these common installation procedures:
For Linux/Ubuntu:
- Start a terminal and install NS2 requirements:
sudo apt-get update
sudo apt-get install build-essential autoconf gcc g++ libxmu-dev
- Download NS2:
- Download NS2 from NS2 Official Website.
- Or use the following 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
- Configure the environment variables: Add the following to your ~/.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
- Define the Type of Network
We want start to decide what kind of network we require to replicate. Some general network kinds they are:
- Wired Networks: Replicate the wired networks LANs, Ethernet, TCP/IP.
- Wireless Networks: The wireless network are replicating the Wi-Fi, MANET, and sensor networks.
- Mobile Networks: The networks are replicating the mobile ad hoc networks (MANETs), GSM, LTE, etc.
- Routing Protocols: Designed for routing protocols like as OSPF, RIP, AODV, DSR, etc.
- Quality of Service (QoS) Networks: Replicate the QoS of bandwidth, delay, jitter, and packet loss.
For example, we could replicate a simple TCP/IP network or a Mobile Ad Hoc Network (MANET).
- Set Up a Basic NS2 Simulation
A basic replication has includes the node generation, connection among them, and build a congestion.
Example: Basic Wired Network with TCP/IP
This sample replicates a simple wired network by two nodes are communicating using TCP.
# Create simulator instance
set ns [new Simulator]
# Create nodes
set node1 [$ns node]
set node2 [$ns node]
# Set up a link between nodes (1 Mbps, 10ms delay)
$ns duplex-link $node1 $node2 1Mb 10ms DropTail
# Set up TCP connection
set tcp [new Agent/TCP]
$ns attach-agent $node1 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $node2 $sink
$ns connect $tcp $sink
# Create traffic (FTP)
set ftp [new Application/Traffic/FTP]
$ftp attach-agent $tcp
# Set up simulation time and run the simulation
$ns at 0.5 “start”
$ns at 5.0 “finish”
$ns run
# Procedures to finish the simulation
proc start {} {
global ns node1 node2
$ns at 0.0 “$node1 start”
}
proc finish {} {
global ns
$ns flush-trace
exit 0
}
Explanation:
- Simulator Instance: Setting the ns [new Simulator] builds the replication things.
- Nodes: Two nodes such as node1 and node2 are created.
- Link: The connection is created among the two nodes by a bandwidth of 1 Mbps and a delay of 10 ms.
- TCP Connection: A TCP connection is introduce among the nodes such as $tcp and $sink.
- Traffic: The congestion is built through the FTP application attached to the TCP agent.
- Simulation Control: The replication is controlled using $ns at commands we explain the movements like as starting the replication and finishing it.
- Choose a Topology for Your Network
NS2 assigns we build the network for topologies like as:
- Star Topology: One central node connected to as many other nodes are called the star topology.
- Bus Topology: A linear network in which nodes are linked with distribute the medium.
- Mesh Topology: A enhance the complex topology through many interconnections among nodes.
- Ring Topology: Nodes form a circular connection for ring topology.
We can build topologies using manual setting or tools such as NS2’s Topology Generator.
Example: Star Topology
# Create a star topology with a central node
set ns [new Simulator]
# Create nodes
set central_node [$ns node]
set node1 [$ns node]
set node2 [$ns node]
# Create links (central node connected to others)
$ns duplex-link $central_node $node1 1Mb 10ms DropTail
$ns duplex-link $central_node $node2 1Mb 10ms DropTail
# Set up TCP connection between nodes
set tcp [new Agent/TCP]
$ns attach-agent $node1 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $node2 $sink
$ns connect $tcp $sink
# Start and finish the simulation
$ns at 0.5 “start”
$ns at 5.0 “finish”
$ns run
- Define and Configure the Protocols
We can state the routing protocols and transport layer protocols for the network, including:
- Routing Protocols: Intended for wired or wireless networks such as RIP, OSPF, AODV, and DSR.
- Transport Protocols: Designed for handling the data transfer among nodes like as TCP, UDP.
For instance, if we need to use the AODV (Ad-hoc On-demand Distance Vector) protocol for MANET replication:
# Set up AODV routing protocol
set ns [new Simulator]
set aodv [new AODV]
# Create nodes and configure routing protocol
set node1 [$ns node]
set node2 [$ns node]
$node1 set protocol AODV
$node2 set protocol AODV
# Set up links, traffic, and simulation as in previous examples
- Configure Mobility Models (For Mobile Networks)
If we are operates on a mobile network such as MANET or VANET, we want to explain the mobility model for the nodes.
The NS2 delivers the several mobility designs, such as:
- Random Waypoint: Random movement are explained the region.
- Gauss-Markov: For enhance the predictable movement.
- Manhattan Grid: For replicating the city-like actions such as a Manhanttan Grid.
Example: Random Waypoint Mobility Model
# Mobility model for mobile nodes
$ns at 0.0 “$node1 set X_ 10”
$ns at 0.0 “$node1 set Y_ 10”
$ns at 1.0 “$node1 random-motion”
- Generate Traffic
We can replicate the different congestion design using several application models like as:
- CBR (Constant Bit Rate) used for the simultaneous data transfer.
- FTP (File Transfer Protocol) use for the file transfers.
- Telnet for interactive transmission.
Example: CBR Traffic for Mobile Network
# Create a CBR traffic generator
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $node1
$cbr set packetSize_ 512
$cbr set rate_ 1000
$cbr set dstNode $node2
- Run the Simulation and Collect Results
Next we have the setting a topology, protocols, mobility, and congestion designs, we can process for the replication and gather the outcomes.
To run the simulation:
ns network_simulation.tcl
This will implement the TCL script and replicate a network. The replication creates a suggest files (.tr) includes the data on packet transmission, routing, delays, etc.
- Analyze Results
Next the process for replication, we can examine the trace files for performance parameter metrics like as:
- Throughput: The throughput is rate of successful message delivery.
- Latency: Time taken for packets we travel from source to destination.
- Packet Loss: Number of packets that were stopped the packet loss.
- End-to-end delay: Delay among forwarding and receiving a packet.
We can use tools such as AWK scripts to parse and examine the suggest files, and NAM (Network Animator) for visualizing the simulation.
To visualize with NAM:
nam network_simulation.nam
- Extend and Experiment
Once you have done the basic project, we can extend it by:
- Improve the routing protocols such as OSPF or DSR for specific networks.
- Replicating the wireless or mobile networks through mobility models and handovers.
- Establish the Quality of Service (QoS) parameters for bandwidth, jitter, and delay.
- Validate the network failures or link degradation below the various environment.
Conclusion
We initialize the network project in NS2, follow these key steps:
- Install NS2 and configure the environment.
- Define the type of network we need to replicate such as wired, wireless, mobile.
- Create the basic simulation setup through the nodes, connection, and congestion.
- Choose appropriate protocols like as TCP, UDP, routing protocols.
- Define mobility models if replicating the mobile networks for mobility models.
- Generate traffic and process for the replication to build the congestion.
- Analyze the results using suggest files and envision tools such as NAM.
By following these steps, you can simulate a wide range of network scenarios, experiment with various protocols and topologies, and analyze network performance.
In the comprehensive manual, we were guided and helped you to get started by defining Start network topology and then simulating a basic network encryption projects in ns2. You can also analyse the simulation. If you need any details for further references, we can provide you.