How to Start Flat Topology Projects Using NS2
To stimulate a Flat Topology project in NS2 (Network Simulator 2) has includes the replication environment in which all nodes are treated similarly, deprived of a hierarchical structure. The flat topologies are generally used in peer-to-peer, ad-hoc, or sensor networks in which all nodes distribute the same roles.
Here’s how to set up and simulate a Flat Topology project in NS2:
Steps to Start Flat Topology Projects Using NS2
- Understand Flat Topology
- Flat Topology:
- All nodes are similar level, by no hierarchy.
- Nodes are communicated directly or through neighbours in a multi-hop fashion.
- Applications:
- Wireless sensor networks.
- Peer-to-peer networks.
- Wireless ad-hoc networks.
- Key Features:
- Simplicity.
- Appropriate the decentralized transmission.
- Set Up NS2
- Install NS2:
- Install NS2 and validate its functionality:
ns example.tcl
- Tools for Analysis:
- NAM (Network Animator) for visualization.
- Trace Analysis Tools for estimate the parameter metrics such as throughput, delay, and packet delivery ratio.
- Plan the Flat Topology
- Network Design:
- Use the nodes for arbitrarily or in a grid.
- Use the direct or multi-hop communication.
- Traffic Pattern:
- Peer-to-peer communication.
- Metrics to Analyze:
- Packet delivery ratio (PDR).
- Latency.
- Throughput.
- Write the Simulation Script
Step 4.1: Create the TCL Script
Store the script as flat_topology.tcl.
Step 4.2: Initialize the Simulator
Set up the wireless simulator:
# Initialize the simulator
set ns [new Simulator]
set tracefile [open trace.tr w]
$ns trace-all $tracefile
set namfile [open flat_topology.nam w]
$ns namtrace-all-wireless $namfile
# Set up the wireless topology parameters
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) Queue/DropTail/PriQueue
set val(ll) LL
set val(ant) Antenna/OmniAntenna
set val(x) 500
set val(y) 500
set val(ifqlen) 50
set val(seed) 0.0
Step 4.3: Create Nodes
Define the nodes and configure their positions:
# Number of nodes
set val(nn) 10
# Create the nodes
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns node]
$node_($i) random-motion 0 ;# Disable random motion
}
# Randomly place nodes
for {set i 0} {$i < $val(nn)} {incr i} {
set x [expr {int(rand() * $val(x))}]
set y [expr {int(rand() * $val(y))}]
$node_($i) set X_ $x
$node_($i) set Y_ $y
$node_($i) set Z_ 0.0
}
Step 4.4: Configure Traffic
Add peer-to-peer traffic flows between nodes:
# Traffic from node_0 to node_5
set udp1 [new Agent/UDP]
$ns attach-agent $node_(0) $udp1
set null1 [new Agent/Null]
$ns attach-agent $node_(5) $null1
$ns connect $udp1 $null1
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set packetSize_ 512
$cbr1 set rate_ 50kb
$ns at 1.0 “$cbr1 start”
# Traffic from node_3 to node_7
set udp2 [new Agent/UDP]
$ns attach-agent $node_(3) $udp2
set null2 [new Agent/Null]
$ns attach-agent $node_(7) $null2
$ns connect $udp2 $null2
set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $udp2
$cbr2 set packetSize_ 512
$cbr2 set rate_ 50kb
$ns at 2.0 “$cbr2 start”
Step 4.5: Enable Routing Protocol
Use the tool AODV, DSR, or any routing protocol for facilitates the multi-hop communication:
$ns rtproto AODV
Step 4.6: Finalize the Script
Add simulation end conditions:
# End simulation
$ns at 10.0 “finish”
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam flat_topology.nam &
exit 0
}
$ns run
- Run the Simulation
- Store the script as flat_topology.tcl.
- Implement it:
ns flat_topology.tcl
- Start NAM for envision the topology:
nam flat_topology.nam
- Analyze Results
- Trace File Analysis:
- Use trace.tr for estimate the parameter metrics such as throughput, latency, and PDR.
- Sample AWK script for throughput:
awk ‘{if ($1 == “r” && $4 == “udp”) sum += $8} END {print “Throughput: “, sum}’
- Metrics:
- Packet Delivery Ratio (PDR): Calculate the reliability.
- Latency: Examine the delays for transmission.
- Throughput: Estimate the effectiveness for data delivery.
- Expand the Simulation
- Introduce Mobility:
- Permit the arbitrary motion for nodes:
$node_($i) random-motion 1
- Simulate Node Failures:
- Establish the node failures for validate the network resilience:
$ns at 5.0 “$node_(3) down”
- Add More Traffic Flows:
- Improve the traffic intensity for estimate the network scalability.
- Experiment with Routing Protocols:
- Associate the performance of using the AODV, DSR, or DSDV.
- Document the Project
- Objective: Define the purpose for replicate the flat topology.
- Setup: It contains the specifics for node placement, traffic patterns, and routing protocols.
- Results: Present the parameter metrics such as throughput, latency, and PDR.
- Conclusions: Summarize the detection and refer the improvements.
The comprehensive procedures contain the explained approach which will help you to get started with the configuration of flat topology and how to detect the node place and protocol using ns2. Other further details will be provided concerning this topic in upcoming manuals.