How to Start Cognitive Radio Networks Projects Using NS3

To start the Cognitive Radio Network (CRN) projects using NS3 which encompass to replicate the wireless networks in which nodes can be detected the radio spectrum and actively modified its transmission parameters. CRNs are utilized enhancing the spectrum utilization by means of once they are not occupied by primary users that is licensed users then permitting the secondary users like unlicensed users to utilize licensed frequency bands. NS3 environment have CRN simulations via customize executions and expansions of existing WiFi or LTE modules. We will guide you through the given procedure to get started with Cognitive Radio Network projects in NS3.

Steps to Start Cognitive Radio Networks Projects in NS3

  1. Install NS3 and Required Modules
  1. Download and Install NS3:

git clone https://gitlab.com/nsnam/ns-3-dev.git ns-3

cd ns-3

./waf configure –enable-examples –enable-tests

./waf build

  1. Verify Installation: Execute a basic WiFi or LTE example verifying that NS3 is properly installed.

./waf –run=wifi-simple-adhoc

  1. Understand Cognitive Radio Network Components

We will normally function with the following modules in a CRN:

  • Primary Users (PUs): Licensed users who contain precedence on the spectrum.
  • Secondary Users (SUs): Unlicensed users who can get into the spectrum once it is not to be utilized by PUs.
  • Spectrum Sensing: For SUs, mechanisms identifying whether an often band is engaged.
  • Dynamic Spectrum Access (DSA): It permits SUs, according to the sensing outcomes to get into the spectrum.
  • Routing Protocols: It manages active routing since SUs may switch channels depends on the spectrum availability.
  1. Set Up Basic Network Topology for Cognitive Radio

Initially, we configure a basic network in which SUs sense the spectrum and try to interact at an available channel. We can be replicated it to utilize WiFi including custom spectrum sensing logic within ad-hoc mode.

Example: Basic Cognitive Radio Setup with WiFi in Ad-hoc Mode

This instance explains a CRN along with SUs to utilize WiFi. Spectrum sensing is replicated by verifying occasionally if a frequency band is obtainable.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/wifi-module.h”

#include “ns3/mobility-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE(“CognitiveRadioExample”);

void SpectrumSensing(Ptr<Node> node, Ptr<WifiNetDevice> device) {

// Simple sensing logic: simulate a primary user on channel 6

uint16_t primaryChannel = 6;

uint16_t currentChannel = device->GetChannelNumber();

if (currentChannel == primaryChannel) {

// Change to a different channel if the primary user is active

NS_LOG_UNCOND(“Node ” << node->GetId() << ” senses primary user on channel ” << primaryChannel << “. Switching channel.”);

device->SetChannelNumber(11); // Switch to a different channel

} else {

NS_LOG_UNCOND(“Node ” << node->GetId() << ” finds channel ” << currentChannel << ” available.”);

}

// Schedule the next spectrum sensing event

Simulator::Schedule(Seconds(1.0), &SpectrumSensing, node, device);

}

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

CommandLine cmd;

cmd.Parse(argc, argv);

// Create secondary user nodes

NodeContainer suNodes;

suNodes.Create(3);

// Set up WiFi in ad-hoc mode for secondary users

YansWifiChannelHelper channel = YansWifiChannelHelper::Default();

YansWifiPhyHelper phy = YansWifiPhyHelper::Default();

phy.SetChannel(channel.Create());

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211b);

WifiMacHelper mac;

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

NetDeviceContainer suDevices = wifi.Install(phy, mac, suNodes);

// Assign initial channels to the devices

for (uint32_t i = 0; i < suDevices.GetN(); ++i) {

Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice>(suDevices.Get(i));

wifiDevice->SetChannelNumber(6); // Initially all SUs are on channel 6

}

// Set up mobility model

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

“MinX”, DoubleValue(0.0),

“MinY”, DoubleValue(0.0),

“DeltaX”, DoubleValue(5.0),

“DeltaY”, DoubleValue(5.0),

“GridWidth”, UintegerValue(3),

“LayoutType”, StringValue(“RowFirst”));

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

mobility.Install(suNodes);

// Install the Internet stack

InternetStackHelper internet;

internet.Install(suNodes);

// Assign IP addresses

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer suInterfaces = address.Assign(suDevices);

// Set up UDP echo server on the first SU node

UdpEchoServerHelper echoServer(9);

ApplicationContainer serverApp = echoServer.Install(suNodes.Get(0));

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(10.0));

// Set up UDP echo client on another SU node

UdpEchoClientHelper echoClient(suInterfaces.GetAddress(0), 9);

echoClient.SetAttribute(“MaxPackets”, UintegerValue(10));

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

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

ApplicationContainer clientApp = echoClient.Install(suNodes.Get(1));

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(10.0));

// Schedule Spectrum Sensing

for (uint32_t i = 0; i < suNodes.GetN(); ++i) {

Ptr<WifiNetDevice> device = DynamicCast<WifiNetDevice>(suDevices.Get(i));

Simulator::Schedule(Seconds(1.0), &SpectrumSensing, suNodes.Get(i), device);

}

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Configure Spectrum Sensing

In this instance, spectrum sensing is replicated by means of verifying if the primary user is on the present channel. Spectrum sensing is more difficult and it might include to identify the signal energy or to utilize cooperative sensing between several SUs in real CRNs.

We can prolong it:

  • Use Energy Detection: Replicate the energy detection by estimating received signal strength.
  • Cooperative Sensing: It can distribute sensing outcomes between several SUs enhancing the sensing exactness.
  1. Configure Dynamic Spectrum Access

Once they identify the PUs then SUs switch channels. We can be replicated diverse DSA strategies:

  • Random Channel Selection: Change to an arbitrary available channel.
  • Greedy Selection: According to the sensed quality or occupancy, to choose the optimal channel.
  1. Set Up Traffic Generation

Replicate diverse traffic patterns utilizing applications such as UdpEchoApplication, OnOffApplication, or BulkSendApplication. It can support to examine the CRN’s performance in diverse traffic loads.

Example with OnOffApplication:

OnOffHelper onOff(“ns3::UdpSocketFactory”, InetSocketAddress(suInterfaces.GetAddress(0), 9));

onOff.SetAttribute(“DataRate”, StringValue(“500Kbps”));

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

ApplicationContainer app = onOff.Install(suNodes.Get(1));

app.Start(Seconds(2.0));

app.Stop(Seconds(10.0));

  1. Evaluate and Analyze CRN Performance

We accumulate the performance parameters like:

  • Spectrum Utilization: Estimate how successfully SUs utilize the available spectrum.
  • Throughput: We can measure data rate that are attained by SUs.
  • Interference: Monitor instances in which SUs interfere including PUs.
  • Handoff Latency: Once SUs switch channels by reason of PU activity, we measure delay.

Collect throughput and packet loss data to utilize FlowMonitor:

FlowMonitorHelper flowmon;

Ptr<FlowMonitor> monitor = flowmon.InstallAll();

monitor->SerializeToXmlFile(“crn-flowmon.xml”, true, true);

  1. Visualize and Analyze the Results
  • NetAnim: Envision the replication monitoring channel switching and node interaction.
  • Trace Analysis: For in-depth event analysis, utilize NS3 trace files.
  • Plotting Tools: Transfer data to plot performance parameters such as throughput, interference instances, and channel usage over time.
  1. Extend to Advanced CRN Scenarios

When we have some knowledge regarding the basics then we discover more complex situations:

  • Multi-Channel Routing: Execute the routing protocols, which can be managed the multi-channel operation and channel switching.
  • Cooperative Sensing: We execute a cooperative sensing mechanism in which several SUs share sensing data enhancing the exactness.
  • Machine Learning for Spectrum Sensing: Test with machine learning models forecasting the PU behavior and to enhance SU access.

The Cognitive Radio Networks project’s framework has been systematically provided that contains crucial information and example coding, which was executed using NS3 tool. We are available to offer expanded insights as required.

phdprojects.org will be your go to partner To start the Cognitive Radio Network (CRN) projects using NS3 tool, once you share your details to us our help team will give you novel ideas and topics, as we have  more than 17+ years of research service you will get best research guidance from us.