How to Implement Line Topology in NS2

 

To implement the Line Topology is also called as a Linear Topology that network arrangement in which every node is related to accurately two other nodes, excepting for the two destination nodes, where are connected to only one other node. It makes a straight-line structure in which the data is passed from one node to another in sequence. In Network Simulator 2, we can execute the line topology by making an order of nodes and connecting everyone to its neighbouring node. We provide stepwise approach to implement this topology in NS2:

Steps to Implement Line Topology in NS2:

  1. Set Up the Line Network Topology:
    • Describe the nodes.
    • Make a duplex links among the consecutive nodes, connecting them in a linear chain.
  2. Simulate Traffic Flow:
    • Create a traffic among the destination nodes or any pair of the nodes in the line that permitting the data to traverse via intermediate nodes.

Example of Line Topology Implementation in NS2:

The following is an instance script that establishes how to configure a line topology with 5 nodes and simulate traffic among them:

# Create a new simulator

set ns [new Simulator]

# Open trace file for output

set tracefile [open out.tr w]

$ns trace-all $tracefile

# Define nodes for the line topology (5 nodes for simplicity)

set n0 [$ns node]  ;# Node 0

set n1 [$ns node]  ;# Node 1

set n2 [$ns node]  ;# Node 2

set n3 [$ns node]  ;# Node 3

set n4 [$ns node]  ;# Node 4

# Create duplex links to form the line topology

$ns duplex-link $n0 $n1 1Mb 10ms DropTail  ;# Link between node 0 and node 1

$ns duplex-link $n1 $n2 1Mb 10ms DropTail  ;# Link between node 1 and node 2

$ns duplex-link $n2 $n3 1Mb 10ms DropTail  ;# Link between node 2 and node 3

$ns duplex-link $n3 $n4 1Mb 10ms DropTail  ;# Link between node 3 and node 4

# ======= TRAFFIC SIMULATION =======

# Define TCP agents for communication between nodes

# Traffic from node 0 to node 4 (across the entire line topology)

set tcp0 [new Agent/TCP]

set sink0 [new Agent/TCPSink]

$ns attach-agent $n0 $tcp0

$ns attach-agent $n4 $sink0

$ns connect $tcp0 $sink0

# Simulate FTP traffic from node 0 to node 4

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ns at 1.0 “$ftp0 start”   ;# Start traffic at 1 second

# Traffic from node 1 to node 3

set tcp1 [new Agent/TCP]

set sink1 [new Agent/TCPSink]

$ns attach-agent $n1 $tcp1

$ns attach-agent $n3 $sink1

$ns connect $tcp1 $sink1

# Simulate FTP traffic from node 1 to node 3

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ns at 2.0 “$ftp1 start”   ;# Start traffic at 2 seconds

# End the simulation after 10 seconds

$ns at 10.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Run the simulation

$ns run

Explanation of the Script:

  1. Nodes:
    • The node n0, n1, n2, n3, and n4 are signify the five nodes connected in a linear chain that is line topology.
  2. Links:
    • Duplex links are made among the consecutive nodes, forming the line topology. For instance, the node n0 is connected to node n1, and n1 is connected to n2, proceeding this process in a straight-line structure until n4.
  3. Traffic Simulation:
    • TCP agents mimic communication among the nodes.
    • FTP (File Transfer Protocol) generates traffic, mimicking file transfers among the nodes.
    • In this sample, the traffic flows from the node n0 to n4, traversing the whole line, and from n1 to n3.
  4. Simulation Duration:
    • The replication runs for 10 seconds and permitting traffic to flow from one end of the line to the other.

Post-Simulation Analysis:

  1. Trace File Analysis:
    • Here, open the trace file (out.tr) to monitor how packets are forwarded among the nodes along the line. Estimate the parameters such as packet delivery, delay, and throughput for the communication among the nodes.
  2. NAM Visualization:
    • We can use the NAM (Network Animator) to visualize the line topology. We will observe the nodes connected in a straight line and how traffic flows among them.
  3. Performance Metrics:
    • Compute the network parameters such as delay, throughput, and packet loss to evaluate how successfully the line topology manages the traffic.

Enhancing the Simulation:

  1. Simulating Traffic in Both Directions:
    • Configure the extra traffic in the reverse direction such as from n4 to n0 to mimic bidirectional communication along the line.
  2. Changing Traffic Type:
    • Swap the TCP with UDP or use CBR (Constant Bit Rate) rather than FTP to replicate various kinds of traffic and evaluate how the network behaves.
  3. Adding More Nodes:
    • Append more nodes to expand the line and monitor how behaviours alters with a longer chain of nodes.
  4. Varying Link Parameters:
    • Analyse with various link parameters like bandwidth, delay, and queue type such as DropTail or RED to learn how the network performance modifies under several conditions.
  5. Simulating Link Failures:
    • Mimic link failures such as disconnect a link among two nodes to monitor how the line topology manages disruptions. Because the topology is linear, a failure can separate part of the network.

Here, we shown the essential informations and stepwise procedure that helps to implement and estimate the Line topology using the ns2 environment. If you require further insights, we will provide.

We’re here to help you achieve your Line Topology in NS2 implementation! For tailored solutions, feel free to visit ns2project.com. Our team offers simulation support, focusing on full comparison analysis of the nodes relevant to your project.