How to Simulate Line Topology Projects Using NS2

To simulate a Line Topology in NS2 has includes to configure a series of nodes associated sequentially, in which each node is linked to exactly two other nodes, excluding for the two endpoints, that are related to only one other node. In this topology, data flows via the network in a straight line, creating it simple and efficient for some applications.

Here’s how you can simulate a Line Topology in NS2:

Steps to Simulate Line Topology Projects in NS2

  1. Set up NS2 Environment:

Make sure that NS2 is installed and configured correctly. The simulation will be completed by using a TCL script that describes the line topology and replicates data flow among nodes.

  1. Understanding Line Topology:
  • In a Line Topology, nodes are organized in a straight line, where each node (except the first and last) is associated to two other nodes.
  • Data flows from one end of the line to the other, passing via intermediate nodes along the way.
  • This topology is simple and easy to configured, nevertheless has limited redundancy and fault tolerance.
  1. Create a TCL Script for Line Topology:

Below is a TCL script to replicate a Line Topology with 5 nodes 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 line topology

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

# Create duplex links between nodes to form a line topology

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

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

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

$ns duplex-link $n3 $n4 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 (n4)

set null0 [new Agent/Null]

$ns attach-agent $n4 $null0

# Connect the UDP agent to the Null agent (n0 to n4)

$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: Five nodes (n0, n1, n2, n3, and n4) are generated to form the line topology.
  • Links: Duplex links are generated among consecutive nodes, forming a line with a bandwidth of 10Mb and a delay of 10ms.
  • UDP Traffic: A UDP agent is attached to the first node (n0), and a Null agent is attached to the last node (n4) to receive the traffic.
  • CBR Traffic: A Constant Bit Rate (CBR) traffic generator transmits traffic from n0 to n4 at a rate of 100Kb with packet sizes of 512 bytes.
  • Traffic Scheduling: The traffic initiates at 1 second and terminates 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 line_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 line_topology.tcl

  1. The simulation will creates out.nam file that can be envisioned using Network Animator (NAM).
  1. Visualization in NAM:
  • Open the out.nam file in NAM to envision the line topology. We should see a linear arrangement of nodes, with traffic flowing from n0 to n4.
  1. Customization and Enhancements:
  • More Nodes: We can add the number of nodes in the line by generating additional nodes and associates them in sequence.
  • TCP Traffic: Replace the UDP agent with a TCP agent for reliable data transmission:

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set sink0 [new Agent/TCPSink]

$ns attach-agent $n4 $sink0

$ns connect $tcp0 $sink0

  • Different Traffic Rates: Test with different packet sizes, data rates, and traffic patterns to replicate numerous network conditions.
  • Performance Metrics: we can incorporate trace files to evaluate key 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 line topology, we can:

  • Evaluate throughput by measuring the amount of data successfully routed among the first and last nodes.
  • Evaluate latency (delay) as data travels via intermediate nodes in the line.
  • Evaluate packet loss if the network experiences congestion or if the link capacity is surpassed.

In this simulation setup, we have been clearly understood the concepts and learn the essential procedures to simulate the Line Topology project that has contain the installation procedures and generating the network topology and then visualized the outcomes through ns2 analysis too. Further details will be provided later.

Receive expert guidance on nodes for your projects. Utilize the NS2 tool to simulate line topology projects. Our team of specialists is ready to assist you; simply send us an email for top-notch research support and unique topic suggestions.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2