To calculate coverage reliability in ns3, we need to evaluate the consistency of a network how it provides the continuous coverage to the nodes in a particular area over a time. Coverage reliability can be said to be the percentage of time that nodes are in the coverage area of an access point or base station. In this type of reliability signal strength and connectivity may fluctuate, which are specifically relevant for wireless networks.
Additionally, we provide a supplementary networking comparison analysis for your project.
The steps given below will guide on how to calculate coverage reliability in ns3:
Steps to Calculate Coverage Reliability in ns3
- Set Up ns-3 Environment:
- Make sure ns3 is installed on the system.
- Create a New ns-3 Script:
- Create a new script file in the scratch directory of ns3, e.g., coverage_reliability.cc.
- Include Necessary Headers:
- Include the necessary ns3 headers in the script.
- Define Network Topology:
- Set up a network topology with multiple nodes and an AP.
- Implement Coverage Reliability Calculation Logic:
- Track the coverage status of each node over time.
- Calculate the percentage of time each node is within the coverage area of the AP.
- Run the Simulation:
- Set the simulation time and run the simulation using Simulator::Run() and Simulator::Destroy().
Example Code:
#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”
#include <vector>
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“CoverageReliability”);
class CoverageMonitor
{
public:
CoverageMonitor(NodeContainer &apNodes, NodeContainer &staNodes, double range)
: m_apNodes(apNodes), m_staNodes(staNodes), m_range(range)
{
m_coverageTime.assign(staNodes.GetN(), 0.0);
}
void CheckCoverage(Time interval)
{
Ptr<Node> apNode = m_apNodes.Get(0); // Assuming single AP for simplicity
Ptr<MobilityModel> apMobility = apNode->GetObject<MobilityModel>();
Vector apPosition = apMobility->GetPosition();
for (uint32_t i = 0; i < m_staNodes.GetN(); ++i)
{
Ptr<Node> staNode = m_staNodes.Get(i);
Ptr<MobilityModel> staMobility = staNode->GetObject<MobilityModel>();
Vector staPosition = staMobility->GetPosition();
double distance = CalculateDistance(apPosition, staPosition);
if (distance <= m_range)
{
m_coverageTime[i] += interval.GetSeconds();
}
}
Simulator::Schedule(interval, &CoverageMonitor::CheckCoverage, this, interval);
}
void ReportCoverageReliability(double totalTime)
{
for (uint32_t i = 0; i < m_staNodes.GetN(); ++i)
{
double reliability = (m_coverageTime[i] / totalTime) * 100.0;
std::cout << “Node ” << i << ” coverage reliability: ” << reliability << “%” << std::endl;
}
}
private:
NodeContainer &m_apNodes;
NodeContainer &m_staNodes;
double m_range;
std::vector<double> m_coverageTime;
};
int main(int argc, char *argv[])
{
uint32_t nStas = 10; // Number of stations
double range = 50.0; // Coverage range of the AP
double totalTime = 10.0; // Total simulation time
double checkInterval = 0.1; // Interval to check coverage
CommandLine cmd;
cmd.AddValue(“nStas”, “Number of stations”, nStas);
cmd.AddValue(“range”, “Coverage range of the AP”, range);
cmd.AddValue(“totalTime”, “Total simulation time”, totalTime);
cmd.AddValue(“checkInterval”, “Interval to check coverage”, checkInterval);
cmd.Parse(argc, argv);
NodeContainer wifiStaNodes;
wifiStaNodes.Create(nStas);
NodeContainer wifiApNode;
wifiApNode.Create(1);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
phy.SetChannel(channel.Create());
WifiHelper wifi = WifiHelper::Default();
wifi.SetRemoteStationManager(“ns3::AarfWifiManager”);
WifiMacHelper mac;
Ssid ssid = Ssid(“ns-3-ssid”);
mac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(ssid), “ActiveProbing”, BooleanValue(false));
NetDeviceContainer staDevices;
staDevices = wifi.Install(phy, mac, wifiStaNodes);
mac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(ssid));
NetDeviceContainer apDevice;
apDevice = wifi.Install(phy, mac, wifiApNode);
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
“MinX”, DoubleValue(0.0),
“MinY”, DoubleValue(0.0),
“DeltaX”, DoubleValue(10.0),
“DeltaY”, DoubleValue(10.0),
“GridWidth”, UintegerValue(5),
“LayoutType”, StringValue(“RowFirst”));
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(wifiApNode);
mobility.SetMobilityModel(“ns3::RandomWalk2dMobilityModel”,
“Bounds”, RectangleValue(Rectangle(-50, 50, -50, 50)));
mobility.Install(wifiStaNodes);
InternetStackHelper stack;
stack.Install(wifiApNode);
stack.Install(wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer staInterfaces = address.Assign(staDevices);
Ipv4InterfaceContainer apInterface = address.Assign(apDevice);
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApps = echoServer.Install(wifiApNode.Get(0));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(totalTime));
UdpEchoClientHelper echoClient(apInterface.GetAddress(0), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(1));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApps = echoClient.Install(wifiStaNodes);
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(totalTime));
CoverageMonitor monitor(wifiApNode, wifiStaNodes, range);
monitor.CheckCoverage(Seconds(checkInterval));
Simulator::Stop(Seconds(totalTime));
Simulator::Run();
monitor.ReportCoverageReliability(totalTime);
Simulator::Destroy();
return 0;
}
Explanation:
- Nodes and Links:
- Created nodes for the access point (AP) and multiple stations (STA).
- Configured the Wi-Fi channel, physical layer, and MAC layer for the AP and STA nodes.
- Mobility:
- Set the AP node’s position to a constant location.
- Set the STA nodes’ mobility to random walk within a bounded area.
- Applications:
- Installed a UDP echo server on the AP node.
- Installed a UDP echo client on the STA nodes to generate traffic.
- Coverage Reliability Calculation Logic:
- Created a CoverageMonitor class to track the coverage status of each node over time.
- The CheckCoverage method checks if each STA node is within the specified range of the AP and increments the coverage time for nodes that are in range.
- The ReportCoverageReliability method calculates and prints the coverage reliability for each STA node as a percentage of the total simulation time.
- Running the Simulation:
- The simulation runs with the STA nodes moving within the bounded area, and the coverage reliability is calculated and printed at the end.
The coverage reliability is calculated successfully by implementing coverage reliability calculation logic to track the coverage status of each node over time.