How to Begin Implement Network Lifetime in NS3
To begin implementing and analysing the Network Lifetime within ns3, we can follow these comprehensive steps. Network Lifetime is a crucial metric, which is specifically utilised within wireless networks that estimates the time while waiting for the initial node or a specific rate of nodes exhausts their energy. Below is a step-by-step guide to get started:
Steps to Begin Implement Network Lifetime in NS3
- Understand Network Lifetime
Network Lifetime in NS3 based on:
- Energy consumption of nodes which helps to send, inherit, idle, and sleep states.
- Traffic patterns: Observe how frequently nodes broadcast or receive the information.
- Energy models: It is used for designing energy utilization and energy sources.
- Set Up Your Environment
Make sure we have installed ns3 on the system and working properly. We can get more knowledge about ns3’s Energy Framework.
- Create the Network Topology
Example: Wireless Topology
NodeContainer nodes;
nodes.Create(10); // Create 10 nodes
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
“MinX”, DoubleValue(0.0),
“MinY”, DoubleValue(0.0),
“DeltaX”, DoubleValue(50.0),
“DeltaY”, DoubleValue(50.0),
“GridWidth”, UintegerValue(5),
“LayoutType”, StringValue(“RowFirst”));
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
phy.SetChannel(channel.Create());
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211n);
WifiMacHelper mac;
mac.SetType(“ns3::AdhocWifiMac”);
NetDeviceContainer devices = wifi.Install(phy, mac, nodes);
InternetStackHelper stack;
stack.Install(nodes);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign(devices);
- Integrate the Energy Framework
Add Energy Source
Insert an energy source to every single node. Make use of BasicEnergySource to design energy levels:
BasicEnergySourceHelper energySourceHelper;
energySourceHelper.Set(“BasicEnergySourceInitialEnergyJ”, DoubleValue(100.0)); // Initial energy in Joules
EnergySourceContainer energySources = energySourceHelper.Install(nodes);
Add Device Energy Model
Append an energy utilization model to the network devices:
WifiRadioEnergyModelHelper radioEnergyHelper;
radioEnergyHelper.Set(“TxCurrentA”, DoubleValue(0.017)); // Transmission current in Amperes
radioEnergyHelper.Set(“RxCurrentA”, DoubleValue(0.013)); // Reception current in Amperes
radioEnergyHelper.Set(“IdleCurrentA”, DoubleValue(0.001)); // Idle current in Amperes
DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install(devices, energySources);
- Install Applications to Generate Traffic
Example: UDP Traffic
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApps = echoServer.Install(nodes.Get(0));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(100.0));
UdpEchoClientHelper echoClient(interfaces.GetAddress(0), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(100));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(0.5))); // 0.5-second interval
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApps = echoClient.Install(nodes.Get(9)); // Last node sends traffic
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(100.0));
- Monitor Energy Levels
Observe the balance energy of every single node for computing the network lifetime.
Callback to Monitor Energy
void EnergyDepletionCallback(Ptr<BasicEnergySource> source) {
std::cout << “Node ” << source->GetNode()->GetId()
<< ” depleted energy at ” << Simulator::Now().GetSeconds() << “s\n”;
}
void SetupEnergyCallbacks(EnergySourceContainer energySources) {
for (auto it = energySources.Begin(); it != energySources.End(); ++it) {
Ptr<BasicEnergySource> source = DynamicCast<BasicEnergySource>(*it);
source->TraceConnectWithoutContext(“RemainingEnergy”,
MakeCallback(&EnergyDepletionCallback));
}
}
Add callback:
SetupEnergyCallbacks(energySources);
- Calculate Network Lifetime
Network lifetime is normally described by time once the initial node executes via energy, or when a particular rate of nodes reduce its energy. Record the depletion times utilising callback.
- Analyze Results
Record the simulation outcomes:
- Once initial node exhausts their energy to analyze the time.
- Examine time when a particular rate of nodes that exhaust the energy.
- Transfer outcomes into a file using the tools such as MATLAB or Excel for fraphical analysis.
- Visualize the Simulation
Envision the node simulation activity using NetAnim:
AnimationInterface anim(“network_lifetime.xml”);
- Experiment and Optimize
- Modify first energy levels:
energySourceHelper.Set(“BasicEnergySourceInitialEnergyJ”, DoubleValue(50.0));
- In the application, fine-tune transmission intervals or packet sizes.
- Experiment various energy patterns such as LTE, custom.
- Run the Simulation
Execute the simulation and then monitor the network lifetime:
Simulator::Run();
Simulator::Destroy();
- Extend the Analysis
- Execute more advanced sleep-wake approaches to store energy for nodes.
- Focus on impact of routing protocols at energy utilization.
- Replicate the heterogeneous energy patterns for various nodes.
This guide simplifies implementing and examining the Network Lifetime through clear stepwise instructions and sample coding using NS3 simulation tool. Furthermore, we will give detailed explanation regarding this topic in upcoming tool.