To simulate a Partial Mesh Topology using NS2 that includes making a network in which few nodes are interconnected with several links, however not every node is associated to every other node as within a full mesh topology. It permits for redundancy and numerous paths without the complexity and resource demands of a full mesh network.
In the following below, we delivered the sequential steps regarding the simulation of Partial Mesh Topology in NS2:
Steps to Simulate Partial Mesh Topology Projects in NS2
- Set Up the NS2 Environment
Make sure that NS2 (Network Simulator 2) is installed and set up on the machine. We can download NS2 from the official website. We will be writing a TCL (Tool Command Language) script to describe the network topology, set up the nodes, and replicate traffic patterns.
- Understand Partial Mesh Topology
- Partial Mesh Topology: In this topology, few nodes are associated to several other nodes, however not all nodes are interconnected. It offers a balance amongst redundancy and resource utilization.
- Advantages: Enhanced reliability over bus or star topologies, including less complexity than a full mesh.
- Create a TCL Script for Partial Mesh Topology
Below is an instance of how to replicate a Partial Mesh Topology in NS2.
# Create a new simulator instance
set ns [new Simulator]
# Open a NAM trace file for visualization
set nf [open partial_mesh.nam w]
$ns namtrace-all $nf
# Define the nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
# Create duplex links to form a partial mesh topology
# n0 connects to n1, n2, and n3
$ns duplex-link $n0 $n1 10Mb 10ms DropTail
$ns duplex-link $n0 $n2 10Mb 10ms DropTail
$ns duplex-link $n0 $n3 10Mb 10ms DropTail
# n1 connects to n2 and n4
$ns duplex-link $n1 $n2 10Mb 10ms DropTail
$ns duplex-link $n1 $n4 10Mb 10ms DropTail
# n2 connects to n3 and n5
$ns duplex-link $n2 $n3 10Mb 10ms DropTail
$ns duplex-link $n2 $n5 10Mb 10ms DropTail
# n3 connects to n5
$ns duplex-link $n3 $n5 10Mb 10ms DropTail
# n4 connects to n5
$ns duplex-link $n4 $n5 10Mb 10ms DropTail
# Define UDP agents and attach them to nodes
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set udp1 [new Agent/UDP]
$ns attach-agent $n4 $udp1
# Define Null agents to act as traffic sinks
set null0 [new Agent/Null]
$ns attach-agent $n5 $null0
set null1 [new Agent/Null]
$ns attach-agent $n3 $null1
# Connect the agents to simulate traffic
$ns connect $udp0 $null0 ;# Traffic from n0 to n5
$ns connect $udp1 $null1 ;# Traffic from n4 to n3
# Create CBR traffic sources 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 traffic
$ns at 1.0 “$cbr0 start”
$ns at 1.5 “$cbr1 start”
$ns at 5.0 “$cbr0 stop”
$ns at 5.5 “$cbr1 stop”
# Define the finish procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam partial_mesh.nam &
exit 0
}
# Schedule the end of the simulation
$ns at 6.0 “finish”
# Run the simulation
$ns run
- Explanation of the Code
- Node Creation
- Nodes n0 to n5 are made to signify the network devices within the partial mesh.
- Link Configuration
- Links are launched among the nodes to form a partial mesh.
- n0 is connected to n1, n2, and n3.
- n1 is connected to n2 and n4.
- n2 is connected to n3 and n5.
- n3 is connected to n5.
- n4 is connected to n5.
- This set up make sure that not every node is associated to every other node, so forming a partial mesh.
- Agent and Traffic Configuration
- UDP Agents are connected to n0 and n4 to generate traffic.
- Null Agents are attached to n5 and n3 to perform as data sinks.
- CBR (Constant Bit Rate) Applications are associated to the UDP agents to make traffic with specified packet size and rate.
- Traffic Connections
- $ns connect $udp0 $null0: Traffic from n0 to n5.
- $ns connect $udp1 $null1: Traffic from n4 to n3.
- Traffic Scheduling
- Traffic begins at 1.0s and 1.5s for cbr0 and cbr1, correspondingly.
- Traffic ends at 5.0s and 5.5s.
- Simulation Execution
- The simulation runs until 6.0s, after which the finish approach is called to flush traces, close files, and introduce NAM for visualization.
- Running the Simulation
- Save the Script
- We can save the TCL script in a file named partial_mesh.tcl.
- Execute the Script
- Open a terminal.
- Traverse to the directory containing partial_mesh.tcl.
- We can execute the simulation using the command:
ns partial_mesh.tcl
- Visualization with NAM
- After running the simulation, Network Animator (NAM) should automatically open and show the network topology and traffic flow.
- If NAM does not open automatically then we can open the partial_mesh.nam file manually:
nam partial_mesh.nam
- Customizing the Simulation
- Adding More Nodes
- To enlarge the network, make more nodes and describe links among them.
- Make sure that the new links maintain the partial mesh property (not every node connected to every other node).
Example: Adding Node n6
# Create a new node
set n6 [$ns node]
# Connect n6 to n2 and n5
$ns duplex-link $n6 $n2 10Mb 10ms DropTail
$ns duplex-link $n6 $n5 10Mb 10ms DropTail
- Changing Traffic Patterns
- Change the traffic sources to replicate diverse scenarios.
- Utilize TCP agents rather than UDP for reliable communication.
Example: Using TCP
# Create TCP agents
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink0 [new Agent/TCPSink]
$ns attach-agent $n5 $sink0
# Connect the TCP agent to the sink
$ns connect $tcp0 $sink0
# Create an FTP application and attach it to the TCP agent
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
# Start and stop FTP traffic
$ns at 1.0 “$ftp0 start”
$ns at 5.0 “$ftp0 stop”
- Adjusting Link Properties
- Adjust bandwidth and delay to replicate distinct network conditions.
- Example: Set a link among n1 and n4 with higher delay.
$ns duplex-link $n1 $n4 10Mb 50ms DropTail
- Performance Analysis
- Enabling Trace Files
- Make a trace file to gather data for analysis.
set tracefile [open partial_mesh.tr w]
$ns trace-all $tracefile
- Analyzing Metrics
- Throughput: Estimate the amount of data effectively delivered over a network path.
- Latency: Measure the time it takes for a packet to travel from origin to destination.
- Packet Loss: Compute the amount of packets, which are dropped because of congestion or errors.
- Using AWK or Perl Scripts
- Process the trace file utilizing scripts to extract and compute the performance parameters.
- Advanced Configurations
- Simulating Node or Link Failures
- Disable a link at a certain time to replicate failure.
# At 3 seconds, disable the link between n2 and n3
$ns rtmodel-at 3.0 down $n2 $n3
- Re-enable the link later if wanted.
# At 4 seconds, re-enable the link between n2 and n3
$ns rtmodel-at 4.0 up $n2 $n3
- Implementing QoS Mechanisms
- Utilize diverse queue types such as RED (Random Early Detection) for congestion control.
$ns queue-limit $n0 $n1 50
$ns duplex-link-op $n0 $n1 queueType RED
- Multicast Traffic
- Replicate multicast traffic if required by setting up the multicast agents and groups.
- Tips and Best Practices
- Comment the code to enhance readability.
- Modularize the script by utilizing techniques for repetitive tasks.
- Confirm the topology by envisioning it in NAM to make sure links and nodes are properly set up.
- Backup the scripts before creating important changes.
We followed the delivered demonstration on how we can set up NS2 environment, customize the simulation and how to analyse its performance by replicating a Partial Mesh Topology and we provided advanced sets up, and tips for this topology using NS2 tool. You can also customize the simulation depends on your requirements.
Explore phdprime.com for assistance with simulating Partial Mesh Topology Projects utilizing the NS2 tool. If you require robust research support and simulation expertise, our specialists are ready to assist you. We offer comparative analysis results tailored to your projects. Our team has a strong focus on full mesh topology, so stay connected for optimal results.