Network Simulation Using Ns2

NS2 is a license-free simulation tool which assists a broad range of protocols and network techniques. It is specifically designed for its flexibility to simulate wired as well as wireless networks and this has been vastly implemented in networking exploration.

Getting Started with NS2

  1. Installation: NS2 is usually implemented on Linux and UNIX systems often, while it can be installed on different operating systems. The source code can be compiled for certain requirements and installation packages are accessible.
  2. Learning TCL: To describe network simulations, NS2 utilizes Tool Command language (TCL) scripts. For developing simulation scripts in NS2, it is necessary to make yourself proficient with TCL.
  3. Understanding NS2 Architecture: By designing examples of agents, connections, packets and nodes inside TCL scripts, NS2 simulations are explained. Various network protocols can be denoted by the Agents.

Simple Steps in a NS2 Simulation

  1. Define the Topology: Model your network topology by developing nodes and configuring connections among them. You can indicate the parameters like queue kind, delay and connection bandwidth.
  2. Select Protocols: Especially for your simulation, select the networking protocols. For transport, applications and routing, NS2 assists a vast amount of protocols.
  3. Configure Traffic: NS2 is used for several traffic frameworks like Constant Bit Rate (CBR), TCP and UDP traffic and others. Explain the sources and destination of traffic.
  4. Run the Simulation: To execute the simulation, run your TCL scripts. In terms of the particular parameters, NS2 simulates the described network situations and works on the script.
  5. Analyze Results: The trace files which record complete incidents like drops, receptions and packet transmissions should be made by the NS-2. To research the protocol actions, all metrics and network efficacy, these files can be observed.

Example NS2 Simulation Script

To initiate a network topology with two nodes linked by connectivity and produce TCP traffic from one node to the other, we suggest a basic example of an NS2 script.

# Create a simulator instance

set ns [new Simulator]

# Define a finish procedure

proc finish {} {

global ns

$ns flush-trace

exec nam out.nam &

exit 0


# Create nodes

set n0 [$ns node]

set n1 [$ns node]

# Create a duplex link between nodes

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

# Setup a TCP agent and attach it to node n0

set tcp [new Agent/TCP]

$ns attach-agent $n0 $tcp

# Setup a sink agent (TCP sink) and attach it to node n1

set sink [new Agent/TCPSink]

$ns attach-agent $n1 $sink

# Connect the TCP agent and the sink

$ns connect $tcp $sink

# Setup a traffic source and attach it to the TCP agent

set traffic [new Application/Traffic/Exponential]

$traffic set packetSize_ 1000

$traffic set burst_time_ 0.5

$traffic set idle_time_ 0.5

$traffic attach-agent $tcp

# Schedule the traffic source to start and stop

$ns at 0.5 “$traffic start”

$ns at 4.5 “$traffic stop”

# Call the finish procedure after 5 seconds of simulation time

$ns at 5.0 “finish”

# Setup tracing and run the simulation

set tracefile [open w]

$ns trace-all $tracefile

set namfile [open out.nam w]

$ns namtrace-all $namfile

$ns run

This specified script presents the main elements of an NS2 simulation script such as traffic production, protocol configuration. Connection setting and node development and also establishes a simple simulation. To utilize NS2 efficiently, interpreting and altering these scripts based on your simulation requirements is important.

Learning Resources

  • NS2 Documentation: To analyze the properties and abilities of NS-2, the authorized document and tutorials are crucial.
  • Community Forums and Mailing Lists: For receiving assistance, obtaining knowledge from the professional clients and solving queries, it is necessary to involve with the NS2 team.

Is ns-3 compatible with NS2?

NS-3 was developed majorly in C++ that varies from NS-2’s structure specifically which also highly depends on Object-oriented Tool Command Language (OTcl) for simulation scripting. The NS-3 also includes a novel structure and coding framework which was created from the fundamental to the advanced levels:

Main Differences:

  1. Programming Language: NS-2 utilizes an integration of OTcl for simulation setting and configuration, and C++ for the essential simulation. But NS-3 employs Python for scripting and is written in C++. This shows that the frameworks and scripts which are created for NS-2 cannot be executed and unaltered in NS-3.
  2. Model and API Design: NS-3 is developed to be simple to process, modular and highly practical when contrasted with NS-2 by providing a novel collection of APIs and Frameworks. Among NS-3 and NS-2, this remodel shows that simulation elements and frameworks are not exchangeable.
  3. Simulation Capabilities: NS-3 offers specific latest characteristics and enhanced frameworks which are not accessible in NS-2, though NS-2 as well as NS-3 are employed for network simulations. For gaining novel structures and updates which consider advanced networking techniques more nearly, NS-3 is also created dynamically.

Migrating from NS-2 to NS-3:

Transferring simulations from NS-2 to NS-3 contains more than porting scripts because of the mentioned variations. Through the API and frameworks of NS-3, it generally needs a re-execution of the simulation. The following are a few notes to relocate the simulations:

  1. Familiarize with NS-3: The API, simulation frameworks and structure of NS-3 should be interpreted. For this motive, use some beneficial materials like NS-3 documents, examples and tutorials.
  2. Map Concepts and Models: Discover the parallel and similar structures in NS-3 and detect the NS-2 properties and frameworks that are utilized in your simulation. To produce effective or highly-precise simulations, NS-3 might provide enhanced frameworks in a few situations.
  3. Rewrite Simulation Scripts: This task mostly includes specific alterations on how the simulation is configured and formatted. By implementing NS-3’s API and frameworks, transform your NS-2 simulation scripts into C++ or Python scripts for NS-3.
  4. Test and Validate: Experiment and check the outcomes completely to assure that the simulation acts as anticipated, once your simulation to NS-3 is ported. Support in detecting other inconsistencies which require to be solved by contrasting outcomes with the actual NS-2 simulation.

Network Simulation Topics Using NS2

Network Simulation Projects Using Ns2

Our team at specializes in conducting a range of Network Simulation Projects using Ns2. We are dedicated to offering top-notch solutions for your ideas at a reasonable price. Feel free to reach out to us for guidance and support every step of the way.

  1. Graph based routing algorithm for torus topology and its evaluation for the Angara interconnect
  2. Hybrid FFBAT optimized multi-hop routing in Internet of Nano-Things
  3. AOR: Adaptive opportunistic routing based on reinforcement learning for planetary surface exploration
  4. Accessible taxi routing strategy based on travel behavior of people with disabilities incorporating vehicle routing problem and Gaussian mixture model
  5. Generation of Homotopy Classes for Unconstrained 3D Wire Routing from Characteristic Loops
  6. A double-adaptive general variable neighborhood search for an unmanned electric vehicle routing and scheduling problem in green manufacturing systems
  7. An optimal ambulance routing model using simulation based on patient medical severity
  8. Multi-attribute two-echelon location routing: Formulation and dynamic discretization discovery approach
  9. An intelligent data routing strategy based on deep reinforcement learning for IoT enabled WSNs
  10. AGV dispatching and bidirectional conflict-free routing problem in automated container terminal
  11. Effects of the tool geometry, cutting and ultrasonic vibration parameters on the cutting forces, tool wear, machined surface integrity and subsurface damages in routing of glass-fibre-reinforced honeycomb cores
  12. New integrated routing and surveillance model with drones and charging station considerations
  13. Fault-aware routing approach for mesh-based Network-on-Chip architecture
  14. Study on the wireless sensor networks routing for Low-Power FPGA hardware in field applications
  15. A Task-Oriented Hybrid Routing Approach based on Deep Deterministic Policy Gradient
  16. Quantum spider prioritized routing and Cramer Shoup cryptosecured data transmission in wireless body area network
  17. A branch-and-cut embedded matheuristic for the inventory routing problem
  18. Utilizing a hybrid metaheuristic algorithm to solve capacitated vehicle routing problem
  19. Solving the multi-compartment vehicle routing problem by an augmented Lagrangian relaxation method
  20. Secure routing framework for mitigating time-delay Trojan attack in System-on-Chip
Opening Time


Lunch Time


Break Time


Closing Time


  • award1
  • award2