How to Simulate Grid Topology Projects Using NS2

To simulate Grid Topology in NS2 has includes to organize the nodes in a grid-like structure, in which each node is associated to its neighbouring nodes in rows and columns. This topology is usually utilized in wireless sensor networks, mesh networks, and other distributed systems.

Here’s how to simulate a Grid Topology in NS2:

Steps to Simulate Grid Topology Projects in NS2

  1. Set up NS2 Environment:

Make sure that NS2 is installed and appropriately configured on system. The simulation will be accompanied by composing a TCL script that describes the grid topology and replicate communication among nodes.

  1. Understanding Grid Topology:
  • In a Grid Topology, nodes are organized in rows and columns, with each node associated to its neighbouring nodes (except for the nodes on the edges of the grid).
  • This topology permit for redundancy and multiple paths among nodes, making it robust against failures.
  1. Create a TCL Script for Grid Topology:

Below is a TCL script to mimic a Grid Topology with 9 nodes organized in a 3×3 grid in NS2:

# Create a new simulator instance

set ns [new Simulator]

# Open a NAM trace file for visualization

set nf [open out.nam w]

$ns namtrace-all $nf

# Create nodes for the grid topology (3×3 grid)

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]

set n6 [$ns node]

set n7 [$ns node]

set n8 [$ns node]

# Create duplex links between nodes to form a 3×3 grid

# First row connections

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

$ns duplex-link $n1 $n2 10Mb 10ms DropTail

# Second row connections

$ns duplex-link $n3 $n4 10Mb 10ms DropTail

$ns duplex-link $n4 $n5 10Mb 10ms DropTail

# Third row connections

$ns duplex-link $n6 $n7 10Mb 10ms DropTail

$ns duplex-link $n7 $n8 10Mb 10ms DropTail

# Column connections

$ns duplex-link $n0 $n3 10Mb 10ms DropTail

$ns duplex-link $n1 $n4 10Mb 10ms DropTail

$ns duplex-link $n2 $n5 10Mb 10ms DropTail

$ns duplex-link $n3 $n6 10Mb 10ms DropTail

$ns duplex-link $n4 $n7 10Mb 10ms DropTail

$ns duplex-link $n5 $n8 10Mb 10ms DropTail

# Attach a UDP agent to the first node (n0)

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

# Attach a Null agent (traffic sink) to the last node (n8)

set null0 [new Agent/Null]

$ns attach-agent $n8 $null0

# Connect the UDP agent to the Null agent (n0 to n8 through the grid)

$ns connect $udp0 $null0

# Create a Constant Bit Rate (CBR) traffic generator and attach it to the UDP agent

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 512    ;# Packet size of 512 bytes

$cbr0 set rate_ 100Kb        ;# Data rate of 100Kb

# Schedule the CBR traffic to start and stop

$ns at 1.0 “$cbr0 start”

$ns at 5.0 “$cbr0 stop”

# End the simulation at 6 seconds

$ns at 6.0 “finish”

proc finish {} {

global ns nf

$ns flush-trace

close $nf

exec nam out.nam &

exit 0

}

# Run the simulation

$ns run

  1. Explanation of the Code:
  • Nodes: Nine nodes (n0, n1, …, n8) are generated and organized in a 3×3 grid.
  • Links: Duplex links are generated among neighboring nodes to form the grid. For example, node n0 is linked to nodes n1 (right neighbor) and n3 (downward neighbor).
  • UDP Traffic: A UDP agent is attached to node n0 (starting point), and a Null agent is attached to node n8 (ending point) to receive the traffic.
  • CBR Traffic: A Constant Bit Rate (CBR) traffic generator transmits packets from n0 to n8 at a rate of 100Kb with packet sizes of 512 bytes.
  • Traffic Scheduling: The traffic begins at 1 second and ends at 5 seconds.
  • Simulation End: The simulation terminates at 6 seconds, and the outcomes are saved in a .nam file for visualization.
  1. Run the Simulation:
  1. Save the script as grid_topology.tcl.
  2. Open a terminal and navigate to the folder in which the script is saved.
  3. Execute the simulation using the following command:

ns grid_topology.tcl

  1. The simulation will create an out.nam file that can be envisioned by using Network Animator (NAM).
  1. Visualization in NAM:
  • Open the out.nam file in NAM to envision the grid topology. We should see a grid structure with traffic flowing from node n0 to node n8.
  1. Customization and Enhancements:
  • Increase Grid Size: We can increase the number of rows and columns by inserting more nodes and links to form a larger grid. For instance, to generate a 4×4 grid, we would increase 16 nodes and apposite links among them.
  • TCP Traffic: Replace the UDP agent with a TCP agent to replicate reliable communication:

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set sink0 [new Agent/TCPSink]

$ns attach-agent $n8 $sink0

$ns connect $tcp0 $sink0

  • Different Traffic Patterns: We can incorporate multiple traffic sources and sinks to replicate diverse communication patterns via the grid.
  • Performance Metrics: Insert tracing to evaluate parameters such as packet loss, delay, and throughput:

set tracefile [open trace.tr w]

$ns trace-all $tracefile

  1. Performance Analysis:

To measure the performance of the grid topology that we can:

  • Assess throughput to regulate the amount of data successfully routed via the grid.
  • Evaluate latency (delay) because of data travels via multiple nodes in the grid.
  • Assess packet loss if the network know-hows congestion or if the link capacity is surpassed.

The above the detailed project about grid topology that was simulated and executed using ns2 tool and it has contain sample codes, detailed explanation about coding and provide the performance analysis regarding this project. Further details will be added later. Phdprime.com team are well  specialize in handling nodes for your projects and can assist you in simulating Grid Topology Projects using the NS2 tool. Feel free to email us with the details of your project, and we promise to provide you with top-notch research services.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2