To simulate an Irregular Topology in NS2 has includes to generating a network in which the connections among the nodes do not stick to a regular or predefined structure like star, mesh, or tree topologies. In an irregular topology, nodes can be attached randomly; construct a more convincing or ad-hoc structure which is improved that demonstrates real-world networks such as wireless sensor networks (WSNs), mobile ad-hoc networks (MANETs), or IoT (Internet of Things) systems.
Here is an approach on how to simulate the Irregular Topology in ns2
Steps to Simulate Irregular Topology Projects in NS2
Step 1: Understand Irregular Topology
In an Irregular Topology:
- The nodes are connected randomly, without a certain pattern or structure.
- This configuration can be utilized to design networks with non-uniform connections, like heterogeneous networks, in which diverse nodes can have fluctuating roles, links, or communication ranges.
- The topology can include random node placement and connections according to distance, communication range, or certain network constraints.
Step 2: Design the Irregular Topology
We will mimic a randomly connected irregular topology where:
- Nodes are randomly located within a specific area.
- Links are generated among nodes according to their proximity or communication range.
- Random traffic flows are launched among altered nodes to mimic network communication.
Step 3: Create an NS2 TCL Script for Simulating an Irregular Topology
Below is an NS2 TCL script which replicates an Irregular Topology with random node placement and random links among the nodes.
Example: Irregular Topology Simulation in NS2
# Create a new NS2 simulator object
set ns [new Simulator]
# Define the network area (dimensions for random node placement)
set x_dim 500 ;# X dimension of the network area
set y_dim 500 ;# Y dimension of the network area
set num_nodes 10 ;# Number of nodes in the network
# Define wireless channel and parameters for irregular topology
set chan [new Channel/WirelessChannel]
set prop [new Propagation/TwoRayGround]
set netif [new Phy/WirelessPhy]
set mac [new Mac/802_11]
set ifq [new Queue/DropTail/PriQueue]
set ll [new LL]
set ant [new Antenna/OmniAntenna]
# Create a topology object
set topo [new Topography]
$topo load_flatgrid $x_dim $y_dim
# General Operations Director (GOD) for ad-hoc networks
create-god $num_nodes
# Configure node properties (wireless nodes for irregular topology)
$ns node-config -adhocRouting AODV \
-llType $ll \
-macType $mac \
-ifqType $ifq \
-ifqLen 50 \
-antType $ant \
-propType $prop \
-phyType $netif \
-channelType $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON
# Create the nodes and randomly place them in the topology
set nodes {}
for {set i 0} {$i < $num_nodes} {incr i} {
set node [$ns node]
lappend nodes $node
# Randomly place the node within the defined area
set x_pos [expr rand() * $x_dim]
set y_pos [expr rand() * $y_dim]
$node set X_ $x_pos
$node set Y_ $y_pos
$node set Z_ 0.0
}
# Create random links based on distance and communication range
# If the distance between two nodes is less than a threshold, create a link
set comm_range 200 ;# Communication range (threshold for creating links)
proc calculate_distance {x1 y1 x2 y2} {
return [expr sqrt(pow(($x1 – $x2), 2) + pow(($y1 – $y2), 2))]
}
for {set i 0} {$i < $num_nodes} {incr i} {
set node1 [lindex $nodes $i]
set x1 [$node1 set X_]
set y1 [$node1 set Y_]
for {set j [expr $i + 1]} {$j < $num_nodes} {incr j} {
set node2 [lindex $nodes $j]
set x2 [$node2 set X_]
set y2 [$node2 set Y_]
# Calculate the distance between node1 and node2
set distance [calculate_distance $x1 $y1 $x2 $y2]
# Create a link if the distance is within the communication range
if { $distance < $comm_range } {
$ns duplex-link $node1 $node2 1Mb 10ms DropTail
}
}
}
# Attach UDP agents to some nodes for random communication
set udp_agents {}
set sinks {}
# Create UDP agents for communication
for {set i 0} {$i < $num_nodes} {incr i} {
set udp [new Agent/UDP]
$ns attach-agent [lindex $nodes $i] $udp
lappend udp_agents $udp
set sink [new Agent/Null]
$ns attach-agent [lindex $nodes [expr ($i + 1) % $num_nodes]] $sink
lappend sinks $sink
# Connect UDP agent to the sink on the next node
$ns connect $udp [lindex $sinks [expr ($i + 1) % $num_nodes]]
}
# Create CBR traffic between nodes
for {set i 0} {$i < $num_nodes} {incr i} {
set cbr [new Application/Traffic/CBR]
$cbr set packetSize_ 512
$cbr set interval_ 0.1
$cbr attach-agent [lindex $udp_agents $i]
# Start traffic at different times for random nodes
set start_time [expr $i * 0.5 + 1.0]
$ns at $start_time “$cbr start”
}
# Trace file for recording simulation events
set tracefile [open “irregular_topology.tr” w]
$ns trace-all $tracefile
# NAM file for network animation
set namfile [open “irregular_topology.nam” w]
$ns namtrace-all-wireless $namfile $x_dim $y_dim
# Define the finish procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam irregular_topology.nam &
exit 0
}
# Finish the simulation after 10 seconds
$ns at 10.0 “finish”
# Run the simulation
$ns run
Step 4: Explanation of the Script
- Node Setup:
- A total of 10 nodes are generated, and each node is arbitrarily placed within the well-defined area (500×500 units) using random coordinates for the X and Y positions.
- Irregular Topology:
- Nodes are associated according to their distance from each other. If two nodes are in a predefined communication range (200 units in this case), a duplex link is generated among them. This generates an irregular, random topology in which some nodes have multiple neighbours since others can have smaller quantity.
- Traffic Generation:
- UDP agents are attached to nodes to replicate communication. CBR (Constant Bit Rate) traffic is created among random pairs of nodes, with each node transmit traffic to another randomly chosen node.
- Distance Calculation:
- A function (calculate_distance) is utilized to estimate the Euclidean distance among two nodes, that regulates either they should be associated by a link.
- Tracing and Visualization:
- A trace file (irregular_topology.tr) logs all network events that involve packet transmissions, receptions, and link creations.
- A NAM file (irregular_topology.nam) is generated to envision the irregular topology and the packet flows among nodes.
Step 5: Run the Simulation
- Save the script as irregular_topology.tcl.
- Execute the script in NS2:
ns irregular_topology.tcl
This will generate two files:
- irregular_topology.tr: A trace files which logs packet-level information.
- irregular_topology.nam: A NAM file for envisioning the network behaviour in NAM.
Step 6: Visualize the Simulation Using NAM
To envision the Irregular Topology in NAM:
nam irregular_topology.nam
In NAM, we will see:
- The randomly placed nodes and the links generated according to proximity.
- Packet transmissions between randomly designated nodes.
Step 7: Analyse the Trace File
The trace file (irregular_topology.tr) logs all network events, such as:
- Packet transmissions and receptions among nodes.
- Packet drops or latency because of network congestion or lack of connectivity.
We can evaluate the trace file using tools such as AWK, Python, or custom scripts to extract key parameters like:
- Packet delivery ratio (PDR).
- End-to-end delay between nodes.
- Network throughput.
Step 8: Enhance the Simulation
Here are some ways to prolong or improve the simulation:
- Add More Nodes: Upsurge the amount of nodes to mimic larger irregular topologies with more complex node distributions.
- Simulate Mobility: Apply node mobility to mimic the environment as mobile ad-hoc networks (MANETs) or IoT networks, in which the nodes move around randomly.
- Implement Routing Protocols: Utilize routing protocols such as AODV or DSDV to manage packet forwarding in the irregular topology.
- Measure Performance Metrics: evaluate parameters like latency, throughput, and packet loss in different network conditions such as high traffic, link failures.
With the help of this procedure you can obtain the knowledge and can be able to simulate the Irregular Topology project in ns2 tool. Additional specific details regarding the Irregular Topology project also provided.
Our offerings are designed to support researchers across various academic stages. Our specialists proficiently model Irregular Topology Projects utilizing the NS2 tool, addressing practical networks including wireless sensor networks (WSNs), mobile ad-hoc networks (MANETs), and Internet of Things (IoT) systems. For tailored assistance, we invite you to visit phdprime.com, where our dedicated team of experts is prepared to provide support.