Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How To Implement Vehicular Sensor Network in NS3

To implement a Vehicular Sensor Network (VSN) in ns-3 by simulating a network in which vehicles are equipped with sensors that communicate wirelessly. This can be achieved by setting up a network of vehicles using WiFi or WiFi 802.11p (WAVE) for communication. The following steps will step guide on how to implement a basic VSN in ns-3.

Prerequisites

  • ns-3 installed on your system.
  • Basic understanding of ns-3 and C++ programming.

Step-by-step Implement a Vehicular Sensor Network in ns-3

  1. 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

Include Necessary Headers: Include the required headers for network modules, mobility, internet, and WiFi.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/mobility-module.h”

#include “ns3/internet-module.h”

#include “ns3/wifi-module.h”

#include “ns3/applications-module.h”

Create Network Topology: Create nodes representing vehicles equipped with sensors.

NodeContainer vehicleNodes;

vehicleNodes.Create(10); // Create 10 vehicle nodes

Set Up Mobility Model: Configure the mobility model to simulate vehicle movement.

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::GaussMarkovMobilityModel”,

                          “Bounds”, RectangleValue(Rectangle(0, 500, 0, 500)),

                          “TimeStep”, TimeValue(Seconds(0.5)),

                          “Alpha”, DoubleValue(0.85),

                          “MeanVelocity”, StringValue(“ns3::UniformRandomVariable[Min=20.0|Max=30.0]”),

                          “MeanDirection”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=6.283185307]”),

                          “MeanPitch”,StringValue(“ns3::UniformRandomVariable[Min=-0.261799388|Max=0.261799388]”),

                          “NormalVelocity”, StringValue(“ns3::NormalRandomVariable[Mean=0.0|Var=1.0]”),

                          “NormalDirection”, StringValue(“ns3::NormalRandomVariable[Mean=0.0|Var=1.0]”),

                          “NormalPitch”, StringValue(“ns3::NormalRandomVariable[Mean=0.0|Var=1.0]”));

mobility.Install(vehicleNodes);

Install WiFi Devices: Install WiFi devices on the vehicle nodes.

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();

wifiPhy.SetChannel(wifiChannel.Create());

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211p);

NqosWaveMacHelper wifiMac = NqosWaveMacHelper::Default();

Ssid ssid = Ssid(“ns-3-ssid”);

wifiMac.SetType(“ns3::AdhocWifiMac”);

NetDeviceContainer wifiDevices = wifi.Install(wifiPhy, wifiMac, vehicleNodes);

Install Internet Stack: Install the internet stack on the vehicle nodes.

InternetStackHelper stack;

stack.Install(vehicleNodes);

Ipv4AddressHelper address;

address.SetBase(“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign(wifiDevices);

Create Applications: Create and install applications to simulate data transmission between vehicles.

uint16_t port = 9;

OnOffHelperonoff(“ns3::UdpSocketFactory”, Address(InetSocketAddress(interfaces.GetAddress(1), port)));

onoff.SetConstantRate(DataRate(“1Mbps”));

 

ApplicationContainer apps = onoff.Install(vehicleNodes.Get(0));

apps.Start(Seconds(1.0));

apps.Stop(Seconds(10.0));

PacketSinkHelpersink(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port)));

apps = sink.Install(vehicleNodes.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

Below is an example complete script for setting up a basic VSN in ns-3:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/mobility-module.h”

#include “ns3/internet-module.h”

#include “ns3/wifi-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

int main(int argc, char *argv[])

{

    NodeContainer vehicleNodes;

    vehicleNodes.Create(10); // Create 10 vehicle 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::GaussMarkovMobilityModel”,

                              “Bounds”, RectangleValue(Rectangle(0, 500, 0, 500)),

                              “TimeStep”, TimeValue(Seconds(0.5)),

                              “Alpha”, DoubleValue(0.85),

                              “MeanVelocity”, StringValue(“ns3::UniformRandomVariable[Min=20.0|Max=30.0]”),

                              “MeanDirection”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=6.283185307]”),

                              “MeanPitch”,StringValue(“ns3::UniformRandomVariable[Min=-0.261799388|Max=0.261799388]”),

                              “NormalVelocity”, StringValue(“ns3::NormalRandomVariable[Mean=0.0|Var=1.0]”),

                              “NormalDirection”, StringValue(“ns3::NormalRandomVariable[Mean=0.0|Var=1.0]”),

                              “NormalPitch”, StringValue(“ns3::NormalRandomVariable[Mean=0.0|Var=1.0]”));

    mobility.Install(vehicleNodes);

 

    YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

    YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();

    wifiPhy.SetChannel(wifiChannel.Create());

    WifiHelper wifi;

    wifi.SetStandard(WIFI_PHY_STANDARD_80211p);

    NqosWaveMacHelper wifiMac = NqosWaveMacHelper::Default();

    Ssid ssid = Ssid(“ns-3-ssid”);

    wifiMac.SetType(“ns3::AdhocWifiMac”);

    NetDeviceContainer wifiDevices = wifi.Install(wifiPhy, wifiMac, vehicleNodes);

    InternetStackHelper stack;

    stack.Install(vehicleNodes);

    Ipv4AddressHelper address;

    address.SetBase(“10.1.1.0”, “255.255.255.0”);

    Ipv4InterfaceContainer interfaces = address.Assign(wifiDevices);

    uint16_t port = 9;

    OnOffHelperonoff(“ns3::UdpSocketFactory”, Address(InetSocketAddress(interfaces.GetAddress(1), port)));

    onoff.SetConstantRate(DataRate(“1Mbps”));

    ApplicationContainer apps = onoff.Install(vehicleNodes.Get(0));

    apps.Start(Seconds(1.0));

    apps.Stop(Seconds(10.0));

 

    PacketSinkHelpersink(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port)));

    apps = sink.Install(vehicleNodes.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 have get to know how a Vehicular Sensor Network (VSN) is implemented in

ns-3.Implementation on Vehicular Sensor Network (VSN) are carried on by our team so rely on us.