Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

# How to Calculate Network Availability in ns3

Calculating network availability in ns3 includes measuring the time that the network (or a specific link/node) is operational and available for communication relative to the total simulation time. Network availability is typically defined as a percentage of the time the network is up and running. Below are the steps to calculate network availability in ns3.

Steps for calculating network burstiness

1. Set up the simulation :
• To simulate the network, create a network topology with nodes, protocols and links configured.
1. Simulate Failures and Recoveries :
• During the simulation, introduce and recover from node or link failures.
1. Trace Availability Metrics :
• To record the operational status of nodes or links, use ns3 tracing capabilities.
1. Calculate network availability :
• Calculate the ratio of uptime to the total simulation time.

Example of a simple Network Availability Calculation

Create a basic network topology and measure the availability of a specific link by simulating failures and recoveries.

set up the simulation

#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”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“NetworkAvailabilityExample”);

class AvailabilityModel

{

public:

AvailabilityModel (Ptr<Node> node1, Ptr<Node> node2)

: m_node1 (node1),

m_node2 (node2),

m_totalUptime (0.0),

m_lastDownTime (0.0),

m_isUp (true)

{

}

void SetDown (Time downTime)

{

if (m_isUp)

{

m_totalUptime += (downTime.GetSeconds () – m_lastDownTime);

m_isUp = false;

}

}

void SetUp (Time upTime)

{

if (!m_isUp)

{

m_lastDownTime = upTime.GetSeconds ();

m_isUp = true;

}

}

double GetTotalUptime () const

{

return m_totalUptime;

}

private:

Ptr<Node> m_node1;

Ptr<Node> m_node2;

double m_totalUptime;

double m_lastDownTime;

bool m_isUp;

};

void LinkDown (Ptr<AvailabilityModel> model, Time downTime)

{

model->SetDown (downTime);

std::cout << “Link down at time ” << downTime.GetSeconds () << ” seconds” << std::endl;

}

void LinkUp (Ptr<AvailabilityModel> model, Time upTime)

{

model->SetUp (upTime);

std::cout << “Link up at time ” << upTime.GetSeconds () << ” seconds” << std::endl;

}

int main (int argc, char *argv[])

{

// Create two nodes

NodeContainer nodes;

nodes.Create (2);

// Set up the point-to-point link

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));

pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));

// Install link devices on nodes

NetDeviceContainer devices;

devices = pointToPoint.Install (nodes);

// Install the internet stack

InternetStackHelper stack;

stack.Install (nodes);

// Set up the UDP echo server on Node 1

uint16_t port = 9; // well-known echo port number

UdpEchoServerHelper echoServer (port);

ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (20.0));

// Set up the UDP echo client on Node 0

echoClient.SetAttribute (“MaxPackets”, UintegerValue (100));

echoClient.SetAttribute (“Interval”, TimeValue (Seconds (0.1))); // 10 packets per second

echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));

ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (20.0));

// Create an availability model for the link between Node 0 and Node 1

Ptr<AvailabilityModel> model = CreateObject<AvailabilityModel> (nodes.Get (0), nodes.Get (1));

// Schedule link down and up events

Simulator::Schedule (Seconds (5.0), &LinkDown, model, Seconds (5.0));

Simulator::Schedule (Seconds (10.0), &LinkUp, model, Seconds (10.0));

Simulator::Schedule (Seconds (15.0), &LinkDown, model, Seconds (15.0));

Simulator::Schedule (Seconds (18.0), &LinkUp, model, Seconds (18.0));

// Run the simulation

Simulator::Run ();

// Calculate network availability

double totalSimulationTime = 20.0; // Total simulation time in seconds

double totalUptime = model->GetTotalUptime ();

double availability = (totalUptime / totalSimulationTime) * 100;

std::cout << “Total Uptime: ” << totalUptime << ” seconds” << std::endl;

std::cout << “Network Availability: ” << availability << ” %” << std::endl;

Simulator::Destroy ();

return 0;

}

Explanation

1. Simulation setup :

Two nodes are created. Those nodes are connected using a point-to-point link.

1. Simulate Failures and Recoveries :

To simulate failures and recoveries, Schedule link down and up events using the Simulator::Schedule function.

1. Tracing Availability Metrics :

To track the uptime of the link, use a custom AvailabilityModel class. The SetDown and SetUp methods are used to update the uptime based on the link’s status.

1. Calculate Network Availability :

Calculate the availability as the ratio of the total uptime to the total simulation time.

Step-by-step breakdown

1. Create Nodes and Links :

Two nodes are created. Those nodes are connected using a point-to-point link with a specified data rate and delay.

1. Install Internet Stack and Applications :

On the nodes, the Internet stack is installed and a UDP echo server and client are set up to generate and receive traffic.