To implement an underwater sensor network (UWSN) in ns-3 consist of making a network of underwater nodes or sensors that can interact by using acoustic signals. This type of network is unique from terrestrial network because of distinct characteristics of the underwater environment like lower propagation speeds and higher reduction.
Here is the step by procedures on how to implement a basic UWSN in ns-3 using the Aqua-sim module which is particularly modelled for underwater networks.
Prerequisites
- ns-3 installed on your system.
- Aqua-Sim module integrated with ns-3.
- Basic understanding of ns-3 and C++ programming.
Steps to Implement UWSN in ns-3
- Install ns-3: Ensure you have ns-3 installed. You can download it from the official website and follow the installation instructions.
wget https://www.nsnam.org/release/ns-allinone-3.xx.tar.bz2
tar -xjf ns-allinone-3.xx.tar.bz2
cd ns-allinone-3.xx
./build.py –enable-examples –enable-tests
- Integrate Aqua-Sim: Aqua-Sim is an underwater network simulator integrated with ns
You need to download and integrate Aqua-Sim with ns-3.
git clone https://github.com/awgn/aqua-sim-ng.git
cd aqua-sim-ng
./waf configure
./waf build
- Include Necessary Headers: Include the required headers for Aqua-Sim and network modules.
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/mobility-module.h”
#include “ns3/internet-module.h”
#include “ns3/aqua-sim-module.h”
- Create Network Topology: Create nodes representing the underwater sensors.
NodeContainer nodes;
nodes.Create(5); // Create 5 sensor nodes
- Set Up Mobility Model: Configure the mobility model to simulate the placement and movement of the underwater sensors.
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::RandomRectanglePositionAllocator”,
“X”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=500.0]”),
“Y”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=500.0]”));
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
- Install Aqua-Sim Devices: Set up Aqua-Sim devices on the nodes and configure the channel properties.
AquaSimChannelHelper channel = AquaSimChannelHelper::Default();
AquaSimHelper asHelper;
asHelper.SetChannel(channel.Create());
NetDeviceContainer devices = asHelper.Install(nodes);
- Install Internet Stack: Install the internet stack on the nodes
InternetStackHelper internet;
internet.Install(nodes);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign(devices);
- Create Applications: Create and install applications to simulate data transmission between the nodes.
uint16_t port = 9;
OnOffHelper onoff(“ns3::UdpSocketFactory”, Address(InetSocketAddress(interfaces.GetAddress(1), port)));
onoff.SetConstantRate(DataRate(“5kbps”));
ApplicationContainer apps;
for (uint32_t i = 0; i < nodes.GetN(); ++i) {
apps.Add(onoff.Install(nodes.Get(i)));
}
apps.Start(Seconds(1.0));
apps.Stop(Seconds(10.0));
PacketSinkHelper sink(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port)));
apps = sink.Install(nodes.Get(1));
apps.Start(Seconds(0.0));
apps.Stop(Seconds(10.0));
- Run the Simulation:
Finally, run the simulation and clean up.
Simulator::Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
Example Complete Script
Here is the illustrative case of complete scripts are given to set up a basic UWSN in ns-3 environment using Aqua-Sim:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/mobility-module.h”
#include “ns3/internet-module.h”
#include “ns3/aqua-sim-module.h”
using namespace ns3;
int main(int argc, char *argv[])
{
NodeContainer nodes;
nodes.Create(5); // Create 5 sensor nodes
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::RandomRectanglePositionAllocator”,
“X”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=500.0]”),
“Y”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=500.0]”));
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
AquaSimChannelHelper channel = AquaSimChannelHelper::Default();
AquaSimHelper asHelper;
asHelper.SetChannel(channel.Create());
NetDeviceContainer devices = asHelper.Install(nodes);
InternetStackHelper internet;
internet.Install(nodes);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign(devices);
uint16_t port = 9;
OnOffHelper onoff(“ns3::UdpSocketFactory”, Address(InetSocketAddress(interfaces.GetAddress(1), port)));
onoff.SetConstantRate(DataRate(“5kbps”));
ApplicationContainer apps;
for (uint32_t i = 0; i < nodes.GetN(); ++i) {
apps.Add(onoff.Install(nodes.Get(i)));
}
apps.Start(Seconds(1.0));
apps.Stop(Seconds(10.0));
PacketSinkHelper sink(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port)));
apps = sink.Install(nodes.Get(1));
apps.Start(Seconds(0.0));
apps.Stop(Seconds(10.0));
Simulator::Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
Running the Script
Compile and run the script using the following commands:
./waf configure –enable-examples
./waf build
./waf –run <script-name>
Finally we provide information about the underwater sensor network in ns-3 environment and additionally we provide and support all kinds of underwater sensor network works with best simulation.