To simulate a Mixed Topology in NS2 has includes to generate a network which integrates numerous kinds of topology like star, mesh, bus, or tree topologies. A mixed topology can be utilized to design real-world networks in which numerous networking structures concur to enhance interaction based on the network desires and restrictions.
Here is an approach on how to simulate the Mixed Topology in ns2
Steps to Simulate Mixed Topology Projects in NS2
Step 1: Understand Mixed Topology
In a Mixed Topology, numerous topological structures like star, mesh, and bus are incorporated to create a hybrid network. This allows you to implement the strengths of each topology for numerous parts of the network. For instance:
- Star Topology for local client-to-server communication.
- Mesh Topology for surplus and fault-tolerant communication paths.
- Bus Topology for shared medium access among nodes in a sub-network.
Step 2: Design the Network Topology
We will mimic a mixed topology in which:
- A star topology is used to connect client nodes to a central server.
- A mesh topology is used to linked routers for redundancy.
- A bus topology is utilized to associate multiple nodes in a linear manner.
Step 3: Create an NS2 TCL Script for Simulating a Mixed Topology
Below is an NS2 TCL script which mimics a Mixed Topology with star, mesh, and bus structures.
Example: Mixed Topology Simulation in NS2
# Create a new NS2 simulator object
set ns [new Simulator]
# Define nodes for different topologies
set star_client1 [$ns node] ;# Star topology client 1
set star_client2 [$ns node] ;# Star topology client 2
set star_server [$ns node] ;# Star topology central server
set mesh_router1 [$ns node] ;# Mesh topology router 1
set mesh_router2 [$ns node] ;# Mesh topology router 2
set mesh_router3 [$ns node] ;# Mesh topology router 3
set bus_node1 [$ns node] ;# Bus topology node 1
set bus_node2 [$ns node] ;# Bus topology node 2
set bus_node3 [$ns node] ;# Bus topology node 3
# Create links for star topology
$ns duplex-link $star_client1 $star_server 1Mb 10ms DropTail
$ns duplex-link $star_client2 $star_server 1Mb 10ms DropTail
# Create links for mesh topology (full connectivity between routers)
$ns duplex-link $mesh_router1 $mesh_router2 1Mb 10ms DropTail
$ns duplex-link $mesh_router1 $mesh_router3 1Mb 10ms DropTail
$ns duplex-link $mesh_router2 $mesh_router3 1Mb 10ms DropTail
# Create links for bus topology (linear connections)
$ns duplex-link $bus_node1 $bus_node2 1Mb 10ms DropTail
$ns duplex-link $bus_node2 $bus_node3 1Mb 10ms DropTail
# Connect bus topology to the star server (bus nodes connect through routers)
$ns duplex-link $bus_node3 $mesh_router1 1Mb 10ms DropTail
# Attach agents for star clients and the server
set udp_star_client1 [new Agent/UDP]
set udp_star_client2 [new Agent/UDP]
$ns attach-agent $star_client1 $udp_star_client1
$ns attach-agent $star_client2 $udp_star_client2
# Attach a UDP sink to the star server
set udp_star_sink [new Agent/Null]
$ns attach-agent $star_server $udp_star_sink
# Connect star clients to the star server
$ns connect $udp_star_client1 $udp_star_sink
$ns connect $udp_star_client2 $udp_star_sink
# Attach agents for mesh routers (UDP traffic between routers)
set udp_mesh1 [new Agent/UDP]
set udp_mesh2 [new Agent/UDP]
set udp_mesh3 [new Agent/UDP]
$ns attach-agent $mesh_router1 $udp_mesh1
$ns attach-agent $mesh_router2 $udp_mesh2
$ns attach-agent $mesh_router3 $udp_mesh3
# Create traffic applications (CBR) for star clients
set cbr_star_client1 [new Application/Traffic/CBR]
$cbr_star_client1 set packetSize_ 512
$cbr_star_client1 set interval_ 0.1 ;# 10 packets per second
$cbr_star_client1 attach-agent $udp_star_client1
set cbr_star_client2 [new Application/Traffic/CBR]
$cbr_star_client2 set packetSize_ 512
$cbr_star_client2 set interval_ 0.1 ;# 10 packets per second
$cbr_star_client2 attach-agent $udp_star_client2
# Create traffic applications (CBR) for mesh routers
set cbr_mesh1 [new Application/Traffic/CBR]
$cbr_mesh1 set packetSize_ 512
$cbr_mesh1 set interval_ 0.1
$cbr_mesh1 attach-agent $udp_mesh1
set cbr_mesh2 [new Application/Traffic/CBR]
$cbr_mesh2 set packetSize_ 512
$cbr_mesh2 set interval_ 0.1
$cbr_mesh2 attach-agent $udp_mesh2
set cbr_mesh3 [new Application/Traffic/CBR]
$cbr_mesh3 set packetSize_ 512
$cbr_mesh3 set interval_ 0.1
$cbr_mesh3 attach-agent $udp_mesh3
# Start traffic for star clients at 1.0 and 1.5 seconds
$ns at 1.0 “$cbr_star_client1 start”
$ns at 1.5 “$cbr_star_client2 start”
# Start traffic for mesh routers at 2.0, 2.5, and 3.0 seconds
$ns at 2.0 “$cbr_mesh1 start”
$ns at 2.5 “$cbr_mesh2 start”
$ns at 3.0 “$cbr_mesh3 start”
# Define traffic for the bus topology (connects to mesh routers)
set udp_bus_node1 [new Agent/UDP]
$ns attach-agent $bus_node1 $udp_bus_node1
set udp_bus_sink [new Agent/Null]
$ns attach-agent $mesh_router1 $udp_bus_sink
# Connect bus nodes to mesh router
$ns connect $udp_bus_node1 $udp_bus_sink
# Define CBR traffic for bus node 1
set cbr_bus_node1 [new Application/Traffic/CBR]
$cbr_bus_node1 set packetSize_ 512
$cbr_bus_node1 set interval_ 0.1
$cbr_bus_node1 attach-agent $udp_bus_node1
# Start traffic for the bus topology at 4.0 seconds
$ns at 4.0 “$cbr_bus_node1 start”
# Trace file for recording the simulation events
set tracefile [open “mixed_topology.tr” w]
$ns trace-all $tracefile
# NAM file for network animation
set namfile [open “mixed_topology.nam” w]
$ns namtrace-all $namfile
# Define the finish procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam mixed_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
- Mixed Topology Setup:
- Star Topology: Two client nodes (star_client1 and star_client2) are associated to a central server (star_server).
- Mesh Topology: Three routers (mesh_router1, mesh_router2, and mesh_router3) are linked in a fully meshed topology for redundancy and fault tolerance.
- Bus Topology: Three nodes (bus_node1, bus_node2, and bus_node3) are associated in a linear bus topology, with bus_node3 linked to the mesh network via mesh_router1.
- Traffic Generation:
- Star Clients: Transmit UDP traffic using CBR (Constant Bit Rate) to the star server.
- Mesh Routers: create CBR traffic among each other to mimic mesh network communication.
- Bus Nodes: Transmit traffic via the bus topology that is linked to the mesh network.
- Tracing and Visualization:
- A trace file (mixed_topology.tr) records all network events like packet transmissions and receptions.
- A NAM file (mixed_topology.nam) is generated to envision the mixed topology and its traffic flows.
Step 5: Run the Simulation
- Save the script as mixed_topology.tcl.
- Execute the script in NS2:
ns mixed_topology.tcl
This will create two files:
- mixed_topology.tr: A trace files which logs packet-level information.
- mixed_topology.nam: A NAM file for envisioning the network behaviour in NAM.
Step 6: Visualize the Simulation Using NAM
To envision the mixed topology in NAM:
nam mixed_topology.nam
In NAM, you will see:
- The star topology in which the clients communicate with a central server.
- The mesh topology connecting the routers with full connectivity.
- The bus topology in which nodes interact linearly, with one bus node associated to the mesh network.
Step 7: Analyse the Trace File
The trace file (mixed_topology.tr) logs all packet transmissions, receptions, and drops via the network. We can evaluate the trace file using tools such as AWK, Python, or custom scripts to extract key parameters like:
- Packet delivery ratio (PDR).
- Throughput via different topologies.
- Network latency and delays among different nodes.
Step 8: Enhance the Simulation
Here are ways to expand or optimize the simulation:
- Add More Complex Traffic Patterns: Replicate various kinds of traffic flows among different topologies such as FTP, HTTP.
- Simulate Failures in the Mesh Network: Establish link failures in the mesh topology and learn on how the redundancy of the mesh network supports in sustaining communication.
- Introduce QoS (Quality of Service): Mimic different levels of priority or bandwidth allocation for various kinds of traffic in the mixed topology.
- Simulate Larger Networks: Prolong the mixed topology to contain more nodes and more complex hierarchical structures, like integrating tree topologies.
In this setup, we clearly learned and gain knowledge on how the Mixed Topology project will perform in the network simulation environment using the tool of ns2 and also we deliver the sample snippets to complete the process. More details regarding this process will also be shared.
To facilitate the simulation of Mixed Topology Projects utilizing the NS2 tool, we will provide you with comprehensive solutions and guidance for your simulations. Additionally, we will present you with optimal thesis ideas and topics customized to align with your concepts.