How to Implement Software defined WSN in ns2
To implement a Software-Defined Wireless Sensor Network (SD-WSN) in Network Simulator 2 (ns2) has needs to emulate the network that sensor nodes’ control plane and data plane are decoupled, and a centralized controller handles the network. In SD-WSN, the controller is liable for making decisions about routing, resource allocation, and network configuration since the sensor nodes concentrates on data collection and transmission.
Step-by-Step Implementation:
Conceptual Overview
In a Software-Defined Wireless Sensor Network:
- Sensor Nodes: Nodes that gathers the data and send it to the controller or directly to the sink.
- Centralized Controller: The controller handles the network by making decisions about routing, resource management, and network configuration.
- Sink Node: A central node that gathers the data from sensor nodes and act as the interface to the outside network.
Step 1: Conceptualize the SD-WSN Simulation
In this simulation, we will make a basic SD-WSN scenario with numerous sensor nodes, a centralized controller, and a sink node. The controller will handles the routing paths of the sensor nodes.
Step 2: Create the Tcl Script
The given below is an example Tcl script that emulates a Software-Defined Wireless Sensor Network scenario in ns2.
Example Tcl Script for Simulating Software-Defined WSN in ns2
# Create a simulator object
set ns [new Simulator]
# Define the topography object (for a moderate area)
set topo [new Topography]
$topo load_flatgrid 1000 1000 # 1km x 1km area
# Create the General Operations Director (GOD) for wireless simulations
create-god 7 # Number of nodes (5 sensor nodes + 1 sink + 1 controller)
# Configure the nodes for the software-defined WSN
$ns node-config -adhocRouting AODV \
-llType LL \
-macType Mac/802_11 \
-ifqType Queue/DropTail/PriQueue \
-ifqLen 50 \
-antType Antenna/OmniAntenna \
-propType Propagation/TwoRayGround \
-phyType Phy/WirelessPhy \
-channelType Channel/WirelessChannel \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF
# Open trace and NAM files for recording the simulation
set tracefile [open sdwsn_out.tr w]
$ns trace-all $tracefile
set namfile [open sdwsn_out.nam w]
$ns namtrace-all-wireless $namfile 1000 1000
# Define a finish procedure to close files and end the simulation
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam sdwsn_out.nam &
exit 0
}
# Create sensor nodes
set sensor1 [$ns node]
set sensor2 [$ns node]
set sensor3 [$ns node]
set sensor4 [$ns node]
set sensor5 [$ns node]
# Create a sink node (central data collection node)
set sink [$ns node]
# Create a centralized controller node
set controller [$ns node]
# Set initial positions for sensor nodes, sink, and controller
$sensor1 set X_ 100.0
$sensor1 set Y_ 200.0
$sensor1 set Z_ 0.0
$sensor2 set X_ 300.0
$sensor2 set Y_ 400.0
$sensor2 set Z_ 0.0
$sensor3 set X_ 500.0
$sensor3 set Y_ 600.0
$sensor3 set Z_ 0.0
$sensor4 set X_ 700.0
$sensor4 set Y_ 800.0
$sensor4 set Z_ 0.0
$sensor5 set X_ 900.0
$sensor5 set Y_ 900.0
$sensor5 set Z_ 0.0
$sink set X_ 500.0
$sink set Y_ 900.0
$sink set Z_ 0.0
$controller set X_ 500.0
$controller set Y_ 500.0
$controller set Z_ 0.0
# Define a custom procedure for the centralized controller to manage the network
proc sd_controller {src dst packetSize rate} {
global ns controller
# Simulate the controller sending routing decisions to the nodes
set udp [new Agent/UDP]
$ns attach-agent $controller $udp
set null [new Agent/Null]
$ns attach-agent $dst $null
$ns connect $udp $null
# Simulate data transmission based on controller’s decisions
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ $packetSize
$cbr set rate_ $rate
$cbr start
}
# Simulate the controller managing data flow from sensors to the sink
$ns at 2.0 “sd_controller $sensor1 $sink 512 100Kb”
$ns at 4.0 “sd_controller $sensor2 $sink 512 100Kb”
$ns at 6.0 “sd_controller $sensor3 $sink 512 100Kb”
$ns at 8.0 “sd_controller $sensor4 $sink 512 100Kb”
$ns at 10.0 “sd_controller $sensor5 $sink 512 100Kb”
# Schedule the end of the simulation
$ns at 20.0 “finish”
# Run the simulation
$ns run
Step 3: Run the Tcl Script
Save the script with a .tcl extension, for instance, sdwsn_simulation.tcl. Then, execute the script using the following command in the terminal:
ns sdwsn_simulation.tcl
Step 4: Visualize the Simulation
To visualize the simulation, open the configured NAM file using:
nam sdwsn_out.nam
Script Explanation
- Sensor Nodes: The nodes sensor1 to sensor5 signifies a sensor node that gathers data and send it to the sink node based on the controller’s decisions.
- Sink Node: The sink node denotes the central node in which the sensor data is collected.
- Controller Node: The controller node denotes the centralized control plane that handles the network and makes decisions about routing and resource allocation.
- Custom Controller Procedure: The sd_controller protocol is to mimic the controller’s role in handling the data flow from sensors to the sink.
Customization
- Advanced Controller Logic: Execute more advanced control logic in the sd_controller procedure, like dynamic routing decisions according to the network conditions, energy levels, or QoS requirements.
- Different Traffic Patterns: Test with various kinds of sensor data traffic likw CBR, FTP to mimic different applications in the SD-WSN.
- Energy Efficiency: integrate energy-efficient protocols to emulate power-constrained sensor nodes.
- Mobility: We need to execute mobility models if the sensor nodes or the controller are mobile.
Limitations
- Simplified Control Logic: This script delivers a simple model of centralized control in an SD-WSN and does not account for the full complexity of real-world control techniques or network dynamics.
- No Physical Layer Simulation: This script does not emulate the physical layer characteristic that particular to SD-WSNs, like signal degradation, interference, or bandwidth limitation.
- Limited SDN Features: ns2 does not support directly to an advanced Software-Defined Networking (SDN) characteristics, so the simulation is limited to simple functionality.
From the above implementation process demonstrate how to execute the Software-Defined Wireless Sensor Network in the network through ns2 tool. Additional specific details about the Software-Defined Wireless Sensor Network will also be provided.
To get the best results with Software Defined WSN, keep in touch with us! Our top developers are here to provide you with the best advice.