To simulate the Cognitive Ad-Hoc Networks (CAHNs) within NS3 which contains integrating two significant concepts: Cognitive Radio Networks (CRNs) and Mobile Ad-Hoc Networks (MANETs). In a Cognitive Ad-Hoc Network, mobile nodes can actively sense and adjust to the radio spectrum environment, then permitting the effective use of spectrum via spectrum sensing and sharing mechanisms. For best simulation be in touch with phdprime.com we are ready with all types of tools and resources to provide you with your needs. The followings are simple procedure for Cognitive Ad-Hoc Networks (CAHNs) that can be simulated using NS3.
Steps to Simulate Cognitive Ad Hoc Network Projects in NS3
Step 1: Install NS3 and Necessary Modules
Initially, make certain that we have NS3 installed. We follow the guidelines below to install NS3 and configure the modules are required for replicating Cognitive Radio (CR) and Ad-Hoc Networks.
- Clone NS3 Repository:
git clone https://gitlab.com/nsnam/ns-3-dev.git
cd ns-3-dev
- Configure and Build NS3:
./waf configure
./waf
Step 2: Understand the Architecture of Cognitive Ad-Hoc Networks
In a Cognitive Ad-Hoc Network (CAHN):
- Cognitive Radio (CR): The nodes are furnished with cognitive radios able of sensing the spectrum, detecting obtainable channels, and switching frequencies according to the environment.
- Ad-Hoc Network: The mobile nodes are capable of communicating within a decentralized manner, routing packets without fixed infrastructure.
- Spectrum Sensing and Management: The network should be contained spectrum sensing to identify the primary users (licensed users) and secondary users (unlicensed users) for opportunistic spectrum access.
Step 3: Set Up the Basic Network Topology
- Create Mobile Nodes (Cognitive Radio Nodes): We can use NodeContainer to make a nodes which signify the cognitive ad-hoc nodes.
NodeContainer crNodes;
crNodes.Create(5); // Create 5 cognitive radio nodes
- Install a Wireless Ad-Hoc Protocol: We can be used ad-hoc routing protocols such as AODV, DSDV, or OLSR for communication among nodes in the network.
AodvHelper aodv;
InternetStackHelper internet;
internet.SetRoutingHelper(aodv); // Use AODV for ad-hoc routing
internet.Install(crNodes);
- Set Up Wireless Communication: Now, we can use the Wi-Fi in ad-hoc mode to allow communication among the cognitive radio nodes.
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211a); // Using 802.11a for spectrum adaptability
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiMacHelper wifiMac;
wifiMac.SetType(“ns3::AdhocWifiMac”);
NetDeviceContainer wifiDevices;
wifiDevices = wifi.Install(wifiPhy, wifiMac, crNodes);
- Assign IP Addresses: After configuring the wireless devices, we allocate an IP addresses to the cognitive nodes.
Ipv4AddressHelper ipv4;
ipv4.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = ipv4.Assign(wifiDevices);
Step 4: Set Up Mobility Model
Cognitive Ad-Hoc Networks are frequently contain mobile nodes. We can set up a mobility model for the cognitive nodes to replicate the real-world movement.
- Set Mobility for Cognitive Nodes: We can use the MobilityHelper to describe mobility for each cognitive radio node.
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
“MinX”, DoubleValue(0.0),
“MinY”, DoubleValue(0.0),
“DeltaX”, DoubleValue(50.0),
“DeltaY”, DoubleValue(50.0),
“GridWidth”, UintegerValue(3),
“LayoutType”, StringValue(“RowFirst”));
mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,
“Speed”, StringValue(“ns3::UniformRandomVariable[Min=5|Max=10]”),
“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=2]”),
“PositionAllocator”, PointerValue(positionAlloc));
mobility.Install(crNodes);
Step 5: Simulate Cognitive Radio Spectrum Sensing
The key aspect of cognitive radio nodes is their capability to sense and adjust to the spectrum. In NS3, we can be executed the spectrum sensing logic in the application or we use the SpectrumPhy model that enables the nodes to identify obtainable channels and prevent interference with primary users.
- Install Spectrum Model for Spectrum Sensing: We can use the SpectrumWifiPhy to allow spectrum sensing for cognitive radios.
SpectrumWifiPhyHelper spectrumPhy;
spectrumPhy.SetChannel(wifiChannel.Create());
spectrumPhy.SetErrorRateModel(“ns3::NistErrorRateModel”);
// Set spectrum sensing parameters
spectrumPhy.Set(“EnergyDetectionThreshold”, DoubleValue(-90.0)); // dBm
spectrumPhy.Set(“CcaMode1Threshold”, DoubleValue(-85.0)); // dBm
- Enable Spectrum Sensing: Execute the spectrum sensing functionality by describing a custom application, which listens to obtainable channels and creates decisions on which channel to use according to the spectrum environment.
// Custom Cognitive Radio Application that senses and selects channels
class CognitiveRadioApp : public Application {
public:
void StartApplication() override {
// Implement spectrum sensing and decision-making logic
}
void StopApplication() override {
// Clean up when the application stops
}
void SpectrumSensing() {
// Sense available channels and avoid primary user interference
// Implement logic to switch channels or avoid occupied bands
}
};
// Install CognitiveRadioApp on cognitive nodes
Ptr<CognitiveRadioApp> crApp = CreateObject<CognitiveRadioApp>();
crNodes.Get(0)->AddApplication(crApp);
Step 6: Implement Dynamic Spectrum Access
Cognitive Ad-Hoc Networks depends on the Dynamic Spectrum Access (DSA) to opportunistically access the underutilized spectrum. We can be replicated DSA by enabling the nodes to actively choose various frequency channels according to the spectrum sensing outcomes.
- Define Multiple Channels for Dynamic Access: Configure various wireless channels (frequencies) for the nodes to select from.
YansWifiChannelHelper wifiChannel1 = YansWifiChannelHelper::Default();
wifiPhy.SetChannel(wifiChannel1.Create()); // Channel 1
YansWifiChannelHelper wifiChannel2 = YansWifiChannelHelper::Default();
wifiPhy.SetChannel(wifiChannel2.Create()); // Channel 2
- Switch Channels Based on Spectrum Sensing: Execute the logic in the application to switch channels when the present channel is engaged or occupied by a primary user.
void CognitiveRadioApp::SpectrumSensing() {
// Simulate spectrum sensing by switching to a different channel if the current one is busy
if (IsChannelBusy()) {
SwitchToAvailableChannel();
}
}
void CognitiveRadioApp::SwitchToAvailableChannel() {
// Switch the Wi-Fi device to a new channel
Ptr<WifiNetDevice> device = GetNode()->GetDevice(0)->GetObject<WifiNetDevice>();
device->GetPhy()->SetChannel(wifiChannel2.Create());
}
Step 7: Set Up Traffic Applications
Install traffic-generating applications (like UDP or TCP) to replicate the communication among the cognitive radio nodes. We can be used the applications such as UdpEchoClient and UdpEchoServer to make a simple communication among the nodes.
- Install UDP Applications: We install a UDP Echo Server on one of the nodes and a UDP Echo Client on another node.
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApp = echoServer.Install(crNodes.Get(0));
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient(crNodes.Get(0)->GetObject<Ipv4>()->GetAddress(1, 0), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(10));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = echoClient.Install(crNodes.Get(1));
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(10.0));
Step 8: Enable Tracing and Run the Simulation
- Enable Packet Tracing: Allow the packet-level tracing to capture the communication amongst cognitive radio nodes.
wifiPhy.EnablePcap(“cognitive-adhoc”, wifiDevices.Get(0), true);
- Run the Simulation: Set the stop time and we can run the simulation.
Simulator::Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
Step 9: Analyse Results
When the simulation is finish then we can examine the outcomes to calculate the behaviour of the Cognitive Ad-Hoc Network:
- Channel Utilization: Monitor how successfully nodes are switch channels to prevent the interference.
- Network Performance: Compute the network performance protocol such as packet delivery ratio (PDR), throughput, and latency.
- Interference Avoidance: Check how effectively nodes are prevent the interference with primary users.
We can envision the simulation using NetAnim or examine the packet traces using Wireshark if we allowed pcap tracing.
Step 10: Advanced Features for Cognitive Ad-Hoc Networks
When we have the simple simulation operating then we can prolong it with more furthered aspects:
- AI/ML-Based Spectrum Management: Execute the AI or machine learning algorithms to enhance spectrum sensing and decision-making.
- Primary User Emulation: Replicate primary users occupying portions of the spectrum and monitor how cognitive nodes are adjust.
- Heterogeneous Cognitive Networks: Integrate various wireless standards (e.g., Wi-Fi and LTE) to replicate the heterogeneous cognitive networks.
- Cooperative Spectrum Sensing: Execute the cooperative spectrum sensing, in which several nodes work together to enhance the accuracy of spectrum sensing.
Here, we had illustrated above regarding the Cognitive adhoc network projects, which was implemented and replicated through the simulation framework NS3. We plan to deliver more information regarding these projects.