How to Implement Star Topology in NS2

 

To implement Star Topology in ns2 needs to execute by connecting multiple nodes to a central node (hub or switch). All the interaction among the nodes in a star topology permits across this central node that mimics the behaviour of a switch or router. This central node acts as the intermediary for all data traffic, related to a real-world star network. We provide guidance on the implementation of Star Topology in NS2. For tailored ideas and topics, feel free to visit ns2project.com. Our team offers exceptional simulation support to meet your needs.The below are the detailed structured to implement the start topology in ns2:

Steps to Simulate a Star Topology in NS2:

  1. Define the Network Topology:
    • We need to configure a central node that acts as the hub or switch and connect all other nodes to this central node using point-to-point (duplex) links.
  2. Simulate Communication Between Nodes:
    • Every communication among nodes will be transmitted via the central hub node that mimics a star topology in which the hub manages all traffic among nodes.

Example of Star Topology Implementation in NS2 (Hub-Based):

# 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 (4 leaf nodes and 1 central hub node)

set n0 [$ns node]  ;# Leaf node 0

set n1 [$ns node]  ;# Leaf node 1

set n2 [$ns node]  ;# Leaf node 2

set n3 [$ns node]  ;# Leaf node 3

set hub [$ns node] ;# Central hub (switch/router)

# Create duplex links between leaf nodes and the central hub (simulating a star topology)

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

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

$ns duplex-link $n2 $hub 1Mb 10ms DropTail

$ns duplex-link $n3 $hub 1Mb 10ms DropTail

# Define TCP agents for communication between nodes

set tcp0 [new Agent/TCP]

set sink0 [new Agent/TCPSink]

$ns attach-agent $n0 $tcp0

$ns attach-agent $n1 $sink0

$ns connect $tcp0 $sink0

# Simulate traffic from node 0 to node 1 through the hub

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ns at 1.0 “$ftp0 start”

# Set up another TCP connection from node 2 to node 3

set tcp1 [new Agent/TCP]

set sink1 [new Agent/TCPSink]

$ns attach-agent $n2 $tcp1

$ns attach-agent $n3 $sink1

$ns connect $tcp1 $sink1

# Simulate traffic from node 2 to node 3 through the hub

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ns at 2.0 “$ftp1 start”

# 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:
    • n0, n1, n2, and n3 signify the leaf nodes in the star topology.
    • hub signifies the central hub or switch that mimic the central point of interaction in the star topology.
  2. Links:
    • Duplex links are generated among each leaf node and the central hub. These links have 1 Mb bandwidth and 10 ms latency; replicate the point-to-point connections in a star topology.
  3. Traffic Simulation:
    • TCP agents are used to mimic the traffic among the nodes. For example, traffic flows from n0 to n1 and from n2 to n3, with all traffic passing via the hub.
    • FTP applications are used to create file transfer traffic among the nodes.
  4. End of Simulation:
    • The simulation executes for 10 seconds and then terminates. During this time, we can track the interaction among the nodes and the flow of traffic via the hub node.

Post-Simulation Analysis:

  1. Trace File Analysis:
    • Open the trace file (out.tr) to monitor on how traffic flows among the leaf nodes via the hub. We need to evaluate the packet delivery, latency, and throughput in the network.
  2. NAM Visualization:
    • Use NAM (Network Animator) to visualize the star topology. We will see all interaction being transmitted via the central hub; mimic a typical star network setup.
  3. Performance Metrics:
    • We can evaluate the parameters such as packet loss, delay, and throughput to evaluate on how well the star topology operates in this simulation.

Enhancing the Simulation:

  1. Collision and Congestion Simulation:
    • Add more nodes or traffic flows to mimic on how congestion or collisions might occur in a star topology while multiple nodes send traffic via the hub consecutively.
  2. Broadcast Traffic:
    • Adjust the script to mimic broadcast traffic, in which a single node sends a message that is transmitted to all other nodes through the hub.
  3. Varying Traffic Types:
    • Validate with diverse traffic types like UDP rather than TCP, or use different applications such as CBR (Constant Bit Rate) traffic to evaluate performance in diverse conditions.
  4. Simulating Failures:
    • To mimic node or link failures in the star topology to monitor on how the loss of a node or the central hub impacts the interaction in the network.

We had help walk you to implement the star topology in ns2 simulator that connects with the multiple nodes to transfer the information to the central node. More information about star topology will be shared according to your needs.