How to Begin Implement Network Served Number of Users in NS3
To implement and examine the network’s served number of users in NS3, we require to replicate a network by numerous users and estimate on how many users are successfully served according to their detailed criteria such as successful data transmission, launch the connection, or Quality of Service (QoS) thresholds.
Steps to Implement Network Served Number of Users in NS3
- Understand the Metric
- Served Users: The number of users such as devices, nodes which successfully has receive the service or see a state of performance metric.
- Criteria for “Served”:
- Connection introduce for sample a user successfully attaches to a base station.
- Is accomplished the Minimum throughput or Quality of Service (QoS).
- A sure transmitted rate of packets is successfully.
- Set Up the NS3 Simulation
- Install NS3:
- Assure the NS3 is installed. We can download it from the NS3 website.
- Choose a Network Type:
- Use a cellular network for instance LTE module or a WiFi network for replicate the several users.
- Define Criteria for Being “Served”
- Connection-Based:
- A Count user who successfully links allocate a point or base station.
- Performance-Based:
- Amount of users who accomplish the minimum throughput or QoS.
- Implement Served User Calculation
Under is a sample NS3 script to estimate the number of served users in a WiFi network.
Example Script: Served Users 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 UserCounter {
public:
UserCounter(double minThroughput) : m_minThroughput(minThroughput), m_servedUsers(0) {}
void CountServedUsers(Ptr<FlowMonitor> monitor, double simulationTime) {
FlowMonitor::FlowStatsContainer stats = monitor->GetFlowStats();
for (auto const &flow : stats) {
double throughput = (flow.second.rxBytes * 8.0) / simulationTime; // Throughput in bits/second
if (throughput >= m_minThroughput) {
m_servedUsers++;
}
}
NS_LOG_UNCOND(“Served Users: ” << m_servedUsers << ” out of ” << stats.size());
}
private:
double m_minThroughput; // Minimum throughput in bps to consider a user served
int m_servedUsers;
};
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 users (stations)
// Configure WiFi
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211g);
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);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer apInterfaces = address.Assign(apDevices);
Ipv4InterfaceContainer staInterfaces = address.Assign(staDevices);
// Install applications
uint16_t port = 9;
for (uint32_t i = 0; i < staNodes.GetN(); ++i) {
UdpEchoServerHelper server(port);
ApplicationContainer serverApp = server.Install(apNode.Get(0));
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
UdpEchoClientHelper client(apInterfaces.GetAddress(0), port);
client.SetAttribute(“MaxPackets”, UintegerValue(10));
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));
}
// Install Flow Monitor
FlowMonitorHelper flowmonHelper;
Ptr<FlowMonitor> monitor = flowmonHelper.InstallAll();
// Count served users
double simulationTime = 10.0; // seconds
double minThroughput = 1e6; // 1 Mbps minimum throughput
UserCounter userCounter(minThroughput);
Simulator::Schedule(Seconds(simulationTime), &UserCounter::CountServedUsers, &userCounter, monitor, simulationTime);
Simulator::Run();
Simulator::Destroy();
return 0;
}
Explanation of the Script
- WiFi Network Setup:
- Settings a WiFi access point and 10 stations (users) using the WifiHelper.
- Throughput-Based Criteria:
- A user is measured “served” if their throughput sees or exceeds 1 Mbps.
- Application:
- Every station executes an UdpEchoClient, forwarding the congestion to a UdpEchoServer on the access point.
- Flow Monitoring:
- The FlowMonitor component is used to compute the throughput for every flow.
- Served User Calculation:
- The UserCounter class amount the number of users gathered the throughput condition.
- Run the Simulation
- Construct the script:
./waf –run “served-users-example”
- Follow the logs for total of served users.
- Analyze Results
- Impact of User Count:
- Improve the number of users and follow on how well the impact of served user count.
- Impact of Distance:
- Improve the distance among stations and allocate the point to study their impact of connection quality.
We had effectively calculated the network served number of users in ns3 simulation that has make the network then put on the user identification logic for analyse the results. We plan to provide the additional data on how to calculate the network served number of users in other simulation scenarios.