Network resiliency in ns3 is describes as the network’s ability to maintain acceptable levels of performance in the face of failures and challenges which includes node failures, link failures, or high traffic loads. To calculate network resiliency, we need to simulate various failure scenarios and measure how well the network continues to perform. Metrics like packet delivery ratio, end-to-end delay, and throughput before and after failures can be used to quantify resiliency.
Here are the steps to calculate network resiliency in ns3.
Steps for calculating Network Resiliency
- Set up the simulation :
- Make sure that ns3 is installed in the computer. If not, install it and include necessary modules.
- Create Network Topology:
- create nodes and configure the network topology.
- Set up point-to-point links, Wi-Fi devices, and mobility models for the nodes.
- Configure Applications:
- On the nodes, setup applications to generate and receive traffic.
- Introduce Failures:
- During the simulation, define scenarios where nodes or links fail at specific times.
- Enable tracing and Metrics Collection:
- To capture relevant metrics such as packet delivery ratio, end-to-end delay, and throughput before and after failures, use ns3 tracing capabilities.
- Run the simulation :
- Execute the simulation and collect the trace data.
- Analyze the results :
- Post-process the trace data to analyze the network’s performance before and after failures and calculate resiliency.
Example to Calculate the Network Resiliency
Create a basic set up of network, introduce failures, and capture metrics to calculate network resiliency in ns3.
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/applications-module.h”
#include “ns3/mobility-module.h”
#include “ns3/flow-monitor-module.h”
#include “ns3/log.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“NetworkResiliencyExample”);
void IntroduceNodeFailure (Ptr<Node> node)
{
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
if (ipv4)
{
for (uint32_t i = 0; i < ipv4->GetNInterfaces (); ++i)
{
ipv4->SetDown (i);
}
}
}
int main (int argc, char *argv[])
{
// Set up logging
LogComponentEnable (“UdpClient”, LOG_LEVEL_INFO);
LogComponentEnable (“UdpServer”, LOG_LEVEL_INFO);
// Create nodes
NodeContainer nodes;
nodes.Create (6);
// Install Mobility model
MobilityHelper mobility;
mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);
mobility.Install (nodes);
// Create point-to-point links
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer devices;
devices.Add (pointToPoint.Install (nodes.Get (0), nodes.Get (1)));
devices.Add (pointToPoint.Install (nodes.Get (1), nodes.Get (2)));
devices.Add (pointToPoint.Install (nodes.Get (2), nodes.Get (3)));
devices.Add (pointToPoint.Install (nodes.Get (3), nodes.Get (4)));
devices.Add (pointToPoint.Install (nodes.Get (4), nodes.Get (5)));
// Install Internet stack
InternetStackHelper internet;
internet.Install (nodes);
// Assign IP addresses
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices);
// Install and start applications on nodes
uint16_t port = 9; // Discard port (RFC 863)
UdpServerHelper server (port);
ApplicationContainer serverApp = server.Install (nodes.Get (5));
serverApp.Start (Seconds (1.0));
serverApp.Stop (Seconds (20.0));
UdpClientHelper client (interfaces.GetAddress (5), port);
client.SetAttribute (“MaxPackets”, UintegerValue (320));
client.SetAttribute (“Interval”, TimeValue (MilliSeconds (50)));
client.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApp = client.Install (nodes.Get (0));
clientApp.Start (Seconds (2.0));
clientApp.Stop (Seconds (20.0));
// Set up FlowMonitor to collect performance metrics
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll ();
// Introduce node failure at 10 seconds
Simulator::Schedule (Seconds (10.0), &IntroduceNodeFailure, nodes.Get (3));
// Run the simulation
Simulator::Stop (Seconds (21.0));
Simulator::Run ();
// Calculate performance metrics before and after the failure
monitor->CheckForLostPackets ();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
double preFailureThroughput = 0.0;
double postFailureThroughput = 0.0;
uint32_t preFailurePackets = 0;
uint32_t postFailurePackets = 0;
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
if (t.sourceAddress == Ipv4Address (“10.1.1.1”) && t.destinationAddress == Ipv4Address (“10.1.1.6”))
{
if (i->second.timeFirstTxPacket.GetSeconds () < 10.0)
{
preFailureThroughput += i->second.rxBytes * 8.0 / 10.0;
preFailurePackets += i->second.rxPackets;
}
else
{
postFailureThroughput += i->second.rxBytes * 8.0 / 10.0;
postFailurePackets += i->second.rxPackets;
}
}
}
NS_LOG_UNCOND (“Pre-Failure Throughput: ” << preFailureThroughput << ” bps”);
NS_LOG_UNCOND (“Post-Failure Throughput: ” << postFailureThroughput << ” bps”);
NS_LOG_UNCOND (“Pre-Failure Packet Delivery Ratio: ” << preFailurePackets / 320.0);
NS_LOG_UNCOND (“Post-Failure Packet Delivery Ratio: ” << postFailurePackets / 320.0);
// Clean up
Simulator::Destroy ();
return 0;
}
Explanation:
- Setup Logging:
- To track activities, enable logging for the UDP applications.
- Create Nodes:
- Create a set of nodes representing devices in the network.
- Install Mobility Model:
- On the nodes, install a mobility model (e.g., ConstantPositionMobilityModel).
- Create Point-to-Point Links:
- Between the nodes, install point-to-point links.
- Install Internet Stack:
- On the nodes, install the Internet stack.
- Assign IP Addresses:
- Assign IP addresses to the network interfaces.
- Install Applications:
- On the nodes, install UDP server and client applications.
- Set Up FlowMonitor:
- To collect and analyze flow statistics, install FlowMonitor.
- Introduce Node Failure:
- To simulate a node failure at a specific time (e.g., at 10 seconds), schedule a function.
- Run Simulation:
- Run the simulation for the specified duration.
- Calculate Performance Metrics Before and After the Failure:
- Extract flow statistics and calculate throughput and packet delivery ratio before and after the failure.
Analyzing the Results:
- Pre-Failure and Post-Failure Throughput:
- Throughput is calculated as the total received bytes per second before and after the failure.
- Pre-Failure and Post-Failure Packet Delivery Ratio:
- Packet delivery ratio is calculated as the ratio of received packets to the total transmitted packets before and after the failure.
At the end, we had our implementation results on calculating network resiliency in ns3 by simulating various failure scenarios and measuring how well the network continues to perform. Also, we provide a detailed overview on Network Resiliency.
To calculate network resiliency for you project we conduct proper simulation in ns3 scenarios and measure how well the network continues, get networking comparative analysis done from ns3simulation.com.