How to Simulate Network Projects Using NS2

To simulate Network Projects in NS2 has needs to set up the diverse kinds of networks like wired, wireless, mobile ad-hoc networks (MANETs), or more complex telecommunication systems. NS2 enable you to generate a wide variety of simulations using Tcl (Tool Command Language) scripts that describe network topologies, traffic models, routing protocols, and other network properties.

Here’s a guide to simulating Network Projects in NS2:

Steps for Simulating Network Projects in NS2

  1. Install NS2: Make sure that NS2 is installed on the system. If you’re using Linux, we can install it using the subsequent command:

sudo apt-get install ns2

After installation, you can verify it by typing:

ns -version

  1. Understand the NS2 Structure: In NS2, simulations are usually composed in Tcl scripts that describe the network elements and features. The main components to set up in Tcl scripts are:
    • Network Topology: Describes nodes, links, and communication paths.
    • Traffic Models: Represents the type of data being routed (such as FTP, HTTP, CBR).
    • Routing Protocols: Manage on how data is transmitted among nodes (e.g., AODV, DSR for mobile nodes).
    • Mobility Models: signify the movement patterns of mobile nodes (optional).
  2. Basic Network Simulation in NS2 Using Tcl Script: Here’s a simple Tcl script to replicate a wired network with FTP traffic:

Example Tcl Script for a Simple Network Simulation

# Create a new simulator object

set ns [new Simulator]

# Open trace and NAM files

set tracefile [open simple_out.tr w]

$ns trace-all $tracefile

set namfile [open simple_out.nam w]

$ns namtrace-all $namfile

# Define the network topology: 2 nodes connected by a duplex link

set node1 [$ns node]

set node2 [$ns node]

# Create a duplex link between node1 and node2

$ns duplex-link $node1 $node2 10Mb 10ms DropTail

# Define traffic: FTP over TCP

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 an FTP application attached to the TCP agent

set ftp [new Application/FTP]

$ftp attach-agent $tcp

# Schedule events: start and stop FTP traffic

$ns at 0.5 “$ftp start”

$ns at 4.5 “$ftp stop”

# Schedule the simulation to end after 5 seconds

$ns at 5.0 “finish”

# Define finish procedure to end the simulation and close files

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam simple_out.nam &

exit 0

}

# Run the simulation

$ns run

Explanation of the Tcl Script:

  1. Simulator Object:
    • The line set ns [new Simulator] generates the NS2 simulator object, that controls the entire simulation.
  2. Trace and NAM Files:
    • These files (tracefile and namfile) are utilized to store simulation data for evaluation and visualization.
    • Trace file: Contains details of every packet (such as sent, received, dropped) for analysis.
    • NAM file: Utilized for envision the simulation with Network Animator (NAM).
  3. Network Topology:
    • Nodes (node1 and node2) are associated using a duplex link (bi-directional), with a bandwidth of 10Mbps and 10ms delay. The DropTail queue type is used to handle packet buffering.
  4. Traffic Model:
    • FTP traffic is simulated over TCP using a TCPSink agent at the receiving node (node2) and a TCP agent at the sending node (node1).
    • FTP traffic is scheduled to initiate at 0.5 seconds and terminate at 4.5 seconds.
  5. Simulation End:
    • The finish procedure is called at 5.0 seconds to terminate the simulation, close files, and open the NAM visualizer.
  1. Running the Simulation:
  • Save the script as simple_simulation.tcl and execute it using NS2:

ns simple_simulation.tcl

  • After the simulation done, open the NAM visualizer to see the animation:

nam simple_out.nam

  1. Analysing the Results:
  • Trace File Analysis: The trace file (simple_out.tr) contains complete information about each packet sent, received, or dropped in the course of the simulation. We can process this trace file to estimate the parameters such as throughput, packet loss, and delay.
  • Utilize AWK scripts or other evaluation tools to extract parameters.

Extending the Simulation:

  1. Simulate Wireless Networks:
    • NS2 supports wireless network simulations that contain Mobile Ad Hoc Networks (MANETs) and cellular networks. Wireless nodes interact over a wireless channel using protocols such as AODV, DSR, or TORA.

Here’s an instance of a simple wireless network Tcl script with mobile nodes:

# Create a new simulator object

set ns [new Simulator]

# Define a wireless channel

set chan_1_ [new Channel/WirelessChannel]

# Create mobile nodes

set node1 [$ns node]

set node2 [$ns node]

# Set up wireless communication and mobility

$node1 set X_ 100

$node1 set Y_ 100

$node2 set X_ 200

$node2 set Y_ 200

# Define UDP traffic

set udp [new Agent/UDP]

$ns attach-agent $node1 $udp

set sink [new Agent/Null]

$ns attach-agent $node2 $sink

# Connect UDP to sink

$ns connect $udp $sink

# Define CBR traffic over UDP

set cbr [new Application/Traffic/CBR]

$cbr set packetSize_ 512

$cbr set interval_ 0.01

$cbr attach-agent $udp

# Schedule traffic

$ns at 1.0 “$cbr start”

$ns at 5.0 “$cbr stop”

# End the simulation

$ns at 6.0 “finish”

# Define finish procedure

proc finish {} {

global ns

$ns flush-trace

exec nam wireless_out.nam &

exit 0

}

# Run the simulation

$ns run

  1. Simulate Mobile Networks:
    • We can replicate mobile networks in which nodes move around using mobility models such as Random Waypoint or Random Walk. Adjust the positions of nodes enthusiastically in the course of the simulation.
  2. Add More Traffic Types:
    • Establish different traffic models such as FTP over TCP, VoIP over UDP, or multicast traffic.
  3. Simulate Larger Networks:
    • Scale up the simulation by incorporate more nodes and routers and replicate larger networks like data center networks, ISP networks, or mesh networks.
  4. Performance Metrics:
    • Analyse the parameters like throughput, latency, packet delivery ratio, and end-to-end delay using AWK scripts or external evaluation tools.

Through this brief procedure, you can get to understand more about the implementation and their approaches regarding the Network Projects including sample snippets using ns2 tool. We plan to deliver the more information regarding the Network Projects so share with us all your details we will help you with best simulation results .

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2