How to Begin Implement Network Efficiency in ns3
To implement and examine the Network Efficiency in NS3, we calculate on how efficiently for network resources for instance bandwidth, energy, time are used to forward the data successfully. Network has effectiveness for be quantified according to their performance based on parameter metrics such as throughput, delay, packet loss, and energy consumption.
Steps to Implement Network Efficiency in NS3
- Understand Network Efficiency
- Definition: Network effectiveness is a ratio of useful work for instance successfully transmitted data to the total resources used.
- Metrics:
- Efficiency Ratio: Efficiency=Useful Data Transmitted (bps)Total Resources Used\text{Efficiency} = \frac{\text{Useful Data Transmitted (bps)}}{\text{Total Resources Used}}Efficiency=Total Resources UsedUseful Data Transmitted (bps)
- Effectiveness can be designed in terms of:
- Bandwidth Utilization: How much bandwidth for available is used for data transmission.
- Energy Efficiency: Data forwarded for per unit the energy consumed.
- Latency and Packet Loss: Effect for the overall effectiveness.
- Set up NS3 Simulation Environment
- Install NS3:
- Assure the tool NS3 is installed. Download it from the NS3 website.
- Choose a Network Type:
- Use wireless networks for sample Wifi, Lte or wired networks for instance PointToPoint according to their environment.
- Define Efficiency Parameters:
- Choose the parameters for calculate such as bandwidth, energy, delay.
- Enable Metrics Calculation
- Throughput:
- Use the tool FlowMonitor for measure the amount of useful data transmitted.
- Energy Consumption:
- Used the environment has NS3’s in Energy Framework to amount of energy consumption.
- Packet Loss and Delay:
- Trace packet loss and delay for assign the effect of efficiency.
- Implement Network Efficiency Calculation
Under is a sample script for measure the network effectiveness according to throughput and energy usage in a WiFi network.
Example Script: Network 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/energy-module.h”
#include “ns3/applications-module.h”
#include “ns3/flow-monitor-helper.h”
using namespace ns3;
class NetworkEfficiencyCalculator {
public:
NetworkEfficiencyCalculator() : m_totalThroughput(0), m_totalEnergyConsumed(0) {}
void AddThroughput(double throughput) {
m_totalThroughput += throughput;
}
void AddEnergyConsumption(double energy) {
m_totalEnergyConsumed += energy;
}
void CalculateEfficiency() {
NS_LOG_UNCOND(“Total Throughput: ” << m_totalThroughput / 1e6 << ” Mbps”);
NS_LOG_UNCOND(“Total Energy Consumed: ” << m_totalEnergyConsumed << ” Joules”);
if (m_totalEnergyConsumed > 0) {
double efficiency = m_totalThroughput / m_totalEnergyConsumed;
NS_LOG_UNCOND(“Network Efficiency (bps/Joule): ” << efficiency);
}
}
private:
double m_totalThroughput; // Throughput in bps
double m_totalEnergyConsumed; // Energy in Joules
};
NetworkEfficiencyCalculator calculator;
void MonitorThroughput(Ptr<FlowMonitor> monitor, double simulationTime) {
FlowMonitor::FlowStatsContainer stats = monitor->GetFlowStats();
double totalThroughput = 0;
for (auto const &flow : stats) {
totalThroughput += (flow.second.rxBytes * 8.0) / simulationTime; // Throughput in bits/s
}
calculator.AddThroughput(totalThroughput);
}
void MonitorEnergyConsumption(Ptr<BasicEnergySource> energySource) {
double initialEnergy = energySource->GetInitialEnergy();
double remainingEnergy = energySource->GetRemainingEnergy();
double energyConsumed = initialEnergy – remainingEnergy;
calculator.AddEnergyConsumption(energyConsumed);
}
int main(int argc, char *argv[]) {
CommandLine cmd;
cmd.Parse(argc, argv);
// Create nodes
NodeContainer nodes;
nodes.Create(2);
// Configure WiFi
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211g);
WifiMacHelper mac;
mac.SetType(“ns3::AdhocWifiMac”);
NetDeviceContainer devices = wifi.Install(wifiPhy, mac, nodes);
// Configure mobility
MobilityHelper mobility;
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
// Configure energy sources
BasicEnergySourceHelper energySourceHelper;
energySourceHelper.Set(“BasicEnergySourceInitialEnergyJ”, DoubleValue(100.0)); // 100 Joules initial energy
EnergySourceContainer energySources = energySourceHelper.Install(nodes);
// Configure device energy models
WifiRadioEnergyModelHelper wifiRadioEnergyHelper;
wifiRadioEnergyHelper.Install(devices, energySources);
// Install Internet stack
InternetStackHelper stack;
stack.Install(nodes);
// Configure IP addresses
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign(devices);
// Configure applications
UdpEchoServerHelper server(9);
ApplicationContainer serverApp = server.Install(nodes.Get(1));
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
UdpEchoClientHelper client(interfaces.GetAddress(1), 9);
client.SetAttribute(“MaxPackets”, UintegerValue(100));
client.SetAttribute(“Interval”, TimeValue(MilliSeconds(100)));
client.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = client.Install(nodes.Get(0));
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);
// Monitor energy consumption
Ptr<BasicEnergySource> energySource = DynamicCast<BasicEnergySource>(energySources.Get(0));
Simulator::Schedule(Seconds(10.0), &MonitorEnergyConsumption, energySource);
// Calculate efficiency
Simulator::Schedule(Seconds(10.0), &NetworkEfficiencyCalculator::CalculateEfficiency, &calculator);
Simulator::Run();
Simulator::Destroy();
return 0;
}
Explanation of the Script
- Throughput Measurement:
- FlowMonitor used to estimate the total data of transmitted successfully.
- Energy Consumption:
- BasicEnergySource tracks are first and remaining energy for calculates the total energy usage.
- Efficiency Calculation:
- It associates the throughput and energy usage to measure the network effectiveness in bps/Joule.
- WiFi Configuration:
- A WiFi ad-hoc network is used for the replication.
- Run the Simulation
- It process for the script:
./waf –run “network-efficiency-example”
- Follow the records for throughput, energy consumption, and network efficiency.
- Analyze Results
- Impact of Traffic Load:
- Enhance the packet rate or size for examine the impact of effectiveness.
- Impact of Distance:
- Improve the distance among nodes for follow the impact of energy consumption and effectiveness.
Network Efficiency can be assessed how effectively the network uses its resources to provide the data packets that attain this in ns3 tool. We support and provide the more about how network efficiency performs in different simulation tools.