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

How To Implement Cognitive Radio Networks in NS3

To implement the cognitive radio network (CRN) in ns-3 encompasses

  • Set-up simulation environment
  • Configure the cognitive radio nodes.
  • Creating communication channels.

We give all types of simulation set up support rely on us for more backup. Here, the given below are the step-by-step procedures to how implement a basic CRN in ns-3 environment.

Prerequisites

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

Steps to Implement a Cognitive Radio 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

  1. Include Necessary Headers: Include the required headers for cognitive radio and related modules in your script.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/mobility-module.h”

#include “ns3/cognitive-radio-helper.h”

#include “ns3/internet-module.h”

#include “ns3/wifi-module.h”

  1. Create Cognitive Radio Nodes: Create nodes for primary users (PUs) and secondary users (SUs).

NodeContainer puNodes;

NodeContainer suNodes;

puNodes.Create(2);

suNodes.Create(2);

  1. Set Up Mobility Model: Configure the mobility model for the nodes to simulate movement.

MobilityHelper mobility;

mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);

mobility.Install(puNodes);

mobility.SetMobilityModel(“ns3::ConstantVelocityMobilityModel”);

mobility.Install(suNodes);

  1. Install Cognitive Radio Devices: Install cognitive radio devices on the nodes using CognitiveRadioHelper.

CognitiveRadioHelper cognitiveRadio;

NetDeviceContainer puDevices = cognitiveRadio.InstallPuDevice(puNodes);

NetDeviceContainer suDevices = cognitiveRadio.InstallSuDevice(suNodes);

  1. Configure Communication Channels: Configure the communication channels for the primary and secondary users.

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();

wifiPhy.SetChannel (wifiChannel.Create ());

NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();

WifiHelper wifi = WifiHelper::Default ();

wifi.SetRemoteStationManager (“ns3::AarfWifiManager”);

NetDeviceContainer puNetDevices = wifi.Install (wifiPhy, wifiMac, puNodes);

NetDeviceContainer suNetDevices = wifi.Install (wifiPhy, wifiMac, suNodes);

  1. Install Internet Stack: Install the internet stack on the nodes to allow IP communication.

InternetStackHelper internet;

internet.Install(puNodes);

internet.Install(suNodes);

  1. Assign IP Addresses: Assign IP addresses to the devices.

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer puInterfaces = address.Assign(puNetDevices);

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

Ipv4InterfaceContainer suInterfaces = address.Assign(suNetDevices);

  1. Create Applications: Create and install applications on the nodes to generate traffic.

uint16_t port = 9;  // Discard port

UdpEchoServerHelper server (port);

ApplicationContainer serverApps = server.Install (puNodes.Get (1));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

UdpEchoClientHelper client (puInterfaces.GetAddress (1), port);

client.SetAttribute (“MaxPackets”, UintegerValue (1));

client.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));

client.SetAttribute (“PacketSize”, UintegerValue (1024));

ApplicationContainer clientApps = client.Install (suNodes.Get (0));

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));

  1. Run the Simulation: Finally, run the simulation and clean up.

Simulator::Stop (Seconds (10.0));

Simulator::Run ();

Simulator::Destroy ();

Example Complete Script

In this direction we provide the instances to complete the scrip that are given below,

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/mobility-module.h”

#include “ns3/cognitive-radio-helper.h”

#include “ns3/internet-module.h”

#include “ns3/wifi-module.h”

using namespace ns3;

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

{

  NodeContainer puNodes;

  NodeContainer suNodes;

  puNodes.Create (2);

  suNodes.Create (2);

  MobilityHelper mobility;

  mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);

  mobility.Install (puNodes);

  mobility.SetMobilityModel (“ns3::ConstantVelocityMobilityModel”);

  mobility.Install (suNodes);

  CognitiveRadioHelper cognitiveRadio;

  NetDeviceContainer puDevices = cognitiveRadio.InstallPuDevice (puNodes);

  NetDeviceContainer suDevices = cognitiveRadio.InstallSuDevice (suNodes);

  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();

  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();

  wifiPhy.SetChannel (wifiChannel.Create ());

 

  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();

  WifiHelper wifi = WifiHelper::Default ();

  wifi.SetRemoteStationManager (“ns3::AarfWifiManager”);

  NetDeviceContainer puNetDevices = wifi.Install (wifiPhy, wifiMac, puNodes);

  NetDeviceContainer suNetDevices = wifi.Install (wifiPhy, wifiMac, suNodes);

  InternetStackHelper internet;

  internet.Install (puNodes);

  internet.Install (suNodes);

  Ipv4AddressHelper address;

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

  Ipv4InterfaceContainer puInterfaces = address.Assign (puNetDevices);

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

  Ipv4InterfaceContainer suInterfaces = address.Assign (suNetDevices);

  uint16_t port = 9;  // Discard port

  UdpEchoServerHelper server (port);

  ApplicationContainer serverApps = server.Install (puNodes.Get (1));

  serverApps.Start (Seconds (1.0));

  serverApps.Stop (Seconds (10.0));

  UdpEchoClientHelper client (puInterfaces.GetAddress (1), port);

  client.SetAttribute (“MaxPackets”, UintegerValue (1));

  client.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));

  client.SetAttribute (“PacketSize”, UintegerValue (1024));

  ApplicationContainer clientApps = client.Install (suNodes.Get (0));

  clientApps.Start (Seconds (2.0));

  clientApps.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 discussed and provide all kinds of information about the cognitive radio network in NS-3 environment and additionally we support any kinds of Cognitive radio networks.