How to Begin Implement Network Spectral Efficacy in NS3
To implement Network Spectral Efficiency in NS3, we estimate the effectiveness of network terms of data rate communicated per unit bandwidth. This metric is especially vital in wireless communication systems for assign the effective utilization of the spectrum.
Steps to Implement Network Spectral Efficiency in NS3
- Understand Spectral Efficiency
- Definition: Spectral efficiency (ηs\eta_sηs) calculate the total of data communicated over a specified bandwidth.
ηs=Throughput (bps)Bandwidth (Hz)\eta_s = \frac{\text{Throughput (bps)}}{\text{Bandwidth (Hz)}}ηs=Bandwidth (Hz)Throughput (bps)
- Units: bits per second per Hertz (bps/Hz).
- Key Metrics:
- Throughput: Complete data rate is achieved.
- Bandwidth: Amount of frequency spectrum assigned.
- Set Up NS3 Simulation Environment
- Install NS3:
- Assure the NS3 is installed and efficient. We can download it from the NS3 website.
- Choose a Wireless Network Model:
- Use Wifi, Lte, or Nr (5G) components in which the spectrum efficiency is complex.
- Configure Key Parameters
- Describe the bandwidth according to the kinds of network.
- Example: WiFi typically uses 20 MHz or 40 MHz channels.
- Use FlowMonitor to during the replication for track throughput.
- Implement Spectral Efficiency Calculation
Under is a sample script to estimate the spectral efficiency in a WiFi network.
Example Script: Spectral Efficiency in NS3
#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 “ns3/flow-monitor-helper.h”
using namespace ns3;
class SpectralEfficiencyCalculator {
public:
SpectralEfficiencyCalculator(double bandwidth) : m_bandwidth(bandwidth), m_totalThroughput(0.0) {}
void AddThroughput(double throughput) {
m_totalThroughput += throughput;
}
void CalculateSpectralEfficiency() {
double spectralEfficiency = m_totalThroughput / m_bandwidth; // bps/Hz
NS_LOG_UNCOND(“Total Throughput: ” << m_totalThroughput / 1e6 << ” Mbps”);
NS_LOG_UNCOND(“Bandwidth: ” << m_bandwidth / 1e6 << ” MHz”);
NS_LOG_UNCOND(“Spectral Efficiency: ” << spectralEfficiency << ” bps/Hz”);
}
private:
double m_bandwidth; // Bandwidth in Hz
double m_totalThroughput; // Throughput in bits per second
};
SpectralEfficiencyCalculator seCalculator(20e6); // 20 MHz bandwidth
void MonitorThroughput(Ptr<FlowMonitor> monitor, double simulationTime) {
FlowMonitor::FlowStatsContainer stats = monitor->GetFlowStats();
double totalThroughput = 0.0;
for (auto const &flow : stats) {
totalThroughput += (flow.second.rxBytes * 8.0) / simulationTime; // Throughput in bits/s
}
seCalculator.AddThroughput(totalThroughput);
}
int main(int argc, char *argv[]) {
CommandLine cmd;
cmd.Parse(argc, argv);
// Create nodes
NodeContainer apNode, staNodes;
apNode.Create(1); // Access point
staNodes.Create(10); // 10 stations (users)
// Configure WiFi
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211n);
WifiMacHelper mac;
Ssid ssid = Ssid(“ns3-ssid”);
mac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(ssid), “ActiveProbing”, BooleanValue(false));
NetDeviceContainer staDevices = wifi.Install(wifiPhy, mac, staNodes);
mac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(ssid));
NetDeviceContainer apDevices = wifi.Install(wifiPhy, mac, apNode);
// Configure mobility
MobilityHelper mobility;
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(apNode);
mobility.SetPositionAllocator(“ns3::RandomRectanglePositionAllocator”,
“X”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=50.0]”),
“Y”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=50.0]”));
mobility.Install(staNodes);
// Install Internet stack
InternetStackHelper stack;
stack.Install(apNode);
stack.Install(staNodes);
// Assign IP addresses
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer apInterfaces = address.Assign(apDevices);
Ipv4InterfaceContainer staInterfaces = address.Assign(staDevices);
// Configure applications
UdpEchoServerHelper server(9);
ApplicationContainer serverApp = server.Install(apNode.Get(0));
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
for (uint32_t i = 0; i < staNodes.GetN(); ++i) {
UdpEchoClientHelper client(apInterfaces.GetAddress(0), 9);
client.SetAttribute(“MaxPackets”, UintegerValue(100));
client.SetAttribute(“Interval”, TimeValue(MilliSeconds(100)));
client.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = client.Install(staNodes.Get(i));
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(10.0));
}
// Monitor throughput
FlowMonitorHelper flowmonHelper;
Ptr<FlowMonitor> monitor = flowmonHelper.InstallAll();
Simulator::Schedule(Seconds(10.0), &MonitorThroughput, monitor, 10.0);
// Calculate spectral efficiency
Simulator::Schedule(Seconds(10.0), &SpectralEfficiencyCalculator::CalculateSpectralEfficiency, &seCalculator);
Simulator::Run();
Simulator::Destroy();
return 0;
}
Explanation of the Script
- WiFi Network Setup:
- Set-up the points are allocates 10 stations in an 802.11n WiFi network.
- Bandwidth:
- The bandwidth is fixed to 20 MHz for compute the spectral efficiency.
- Throughput Monitoring:
- FlowMonitor is used for evaluate the amount of throughput achieved through all stations.
- Spectral Efficiency Calculation:
- Is calculated the ratio of total throughput in bandwidth.
- Run the Simulation
- Construct the script:
./waf –run “spectral-efficiency-example”
- Examine the logs for throughput, bandwidth, and spectral efficiency.
- Analyze Results
- Impact of User Count:
- Improve the number of users and follow the impact of spectral effectiveness.
- Impact of Bandwidth:
- Alter the bandwidth for estimate the role of spectral efficiency.
- Wireless Protocols:
- It associates the spectral efficiency with various standards WiFi for sample 802.11n, 802.11ac.
In the above events were very helpful to implement the spectral efficiency over the network using the ns3 simulation tool and also we provide the more information about the spectral efficiency.