How to Simulate Physical Topology Projects Using NS2

To simulate a Physical Topology using NS2 that has sequence of steps, comprises to define the real physical connections among the network nodes, like routers, switches, and hosts. This kind of topology signifies the real-world layout of the network in which devices are interconnected by physical links. We can be replicated numerous kinds of physical topologies like bus, star, ring, mesh, and so on, by making nodes and relating them with the help of duplex links within NS2.

The given demonstration will help you to accomplish this topology in ns2:

Steps to Simulate Physical Topology Projects in NS2

  1. Set up NS2 Environment:

Make sure that NS2 is installed and working correctly on the computer. We will describe a physical network layout and replicate data transmission among the nodes using a TCL script.

  1. Understanding Physical Topology:
  • Physical Topology refers to the actual layout of devices on a network that encompassing how nodes are physically associated by cables or wireless links.
  • The kind of physical topology selected (e.g., bus, star, ring, or mesh) based on the network design and the communication requirements.
  1. Create a TCL Script for a Physical Topology:

Following is a TCL script, which replicates a Star Physical Topology with 5 nodes are connected to a central switch (hub) within NS2. We can change this script to denote other topologies, like bus, ring, or mesh.

Example: Star Physical Topology

# 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

# ======= Physical Topology: Star Topology =======

# Create nodes for the star topology

set central_switch [$ns node]  ;# Central hub/switch node

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 between the central switch and each node

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

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

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

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

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

# ======= Traffic Generation =======

# Attach UDP agents to some nodes

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set udp1 [new Agent/UDP]

$ns attach-agent $n2 $udp1

# Attach Null agents (traffic sinks) to other nodes

set null0 [new Agent/Null]

$ns attach-agent $n1 $null0

set null1 [new Agent/Null]

$ns attach-agent $n3 $null1

# Connect the UDP agents to Null agents (data flow in the star topology)

$ns connect $udp0 $null0

$ns connect $udp1 $null1

# Create CBR traffic generators and attach them to the UDP agents

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 512

$cbr0 set rate_ 100Kb

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

$cbr1 set packetSize_ 512

$cbr1 set rate_ 100Kb

# Schedule the CBR traffic to start and stop

$ns at 1.0 “$cbr0 start”

$ns at 1.5 “$cbr1 start”

$ns at 5.0 “$cbr0 stop”

$ns at 5.5 “$cbr1 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: Six nodes are made (central_switch, n0, n1, n2, n3, n4). central_switch performs as the central hub or switch in the star topology, even though the other nodes are associated to it.
  • Links: Duplex links are ascertained among the central switch and each node that constructing a star topology with a bandwidth of 10Mb and a delay of 10ms.
  • Traffic: Two UDP agents are connected to nodes n0 and n2. Null agents (traffic sinks) are associated to nodes n1 and n3. Traffic is made from n0 to n1 and from n2 to n3 utilizing Constant Bit Rate (CBR) traffic generators.
  • Traffic Scheduling: Traffic begins at 1.0 and 1.5 seconds and ends at 5.0 and 5.5 seconds, correspondingly.
  • Simulation End: The simulation stops at 6 seconds, and for visualization, the outputs are saved in a .nam file.
  1. Run the Simulation:
  1. We can save the script as star_topology.tcl.
  2. Open a terminal and traverse to the folder in which the script is saved.
  3. Execute the simulation using:

ns star_topology.tcl

  1. The simulation will make an out.nam file, which can be opened with the help of Network Animator (NAM) for visualization.
  1. Visualization in NAM:
  • We can open the out.nam file in NAM to envision the star topology. We will observe the nodes are associated within a star formation, including traffic flowing from n0 to n1 and from n2 to n3.
  1. Customization and Enhancements:
  • Change Topology: We can change the script to replicate diverse physical topologies such as bus, ring, or mesh by modifying the connections among the nodes. For instance:
    • Bus Topology: Attach all nodes to a unique backbone link such as a shared cable.
    • Ring Topology: Associate nodes within a circular fashion in which each node is related to two adjacent nodes.
    • Mesh Topology: Connect each node to numerous other nodes, which making a fully or partly connected mesh.
  • TCP Traffic: Substitute UDP agents including TCP agents to mimic reliable communication:

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set sink0 [new Agent/TCPSink]

$ns attach-agent $n1 $sink0

$ns connect $tcp0 $sink0

  • Performance Metrics: We can insert tracing to compute the performance parameters like throughput, delay, and packet loss:

set tracefile [open trace.tr w]

$ns trace-all $tracefile

  1. Performance Analysis:

To examine the performance of the physical topology, we can:

  • Calculate the throughput to find out the number of data effectively sent through links.
  • Assess latency (delay) for data as it travels among the nodes.
  • Investigate packet loss to estimate the reliability of the network under diverse traffic conditions.

Example of Other Topologies:

Ring Topology Example:

# Ring Topology: Connect nodes in a circular fashion

$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

$ns duplex-link $n4 $n0 10Mb 10ms DropTail  ;# Complete the ring

Mesh Topology Example:

# Mesh Topology: Fully connect all nodes

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

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

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

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

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

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

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

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

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

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

These projects offer a simple Physical Topology simulation using NS2, which can be modified to simulate numerous kinds of topologies. If you want additional assistance or customizations, we will be presented in upcoming manual.

Visit phdprime.com for assistance with simulating Physical Topology Projects using the NS2 tool. If you’re looking for reliable research support and simulation guidance, our experts are ready to help. We offer project performance analysis results tailored to your needs. Our team specializes in various types of physical topologies, so stay connected for optimal results.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2