How to Begin Implement Network Availability in NS3

To begin implementing the network availability within NS3, we can replicate and observe the network capability for effectively distributing the data packets in diverse conditions like node failures, link disruptions, or changing topologies. Network availability is normally referred as the rate of time the network stays working or the ratio of data effectively transferred over a time. Now, let’s see how to start executing the network availability using NS3 through the following steps.

Steps to Begin Implement Network Availability in NS3

  1. Understand Network Availability
  • Definition: Network availability expressed to the ratio of time that the network is working and able to distribute the data packets effectively.
  • Metrics:
    • Availability Ratio: Availability=Successful Packet Delivery TimeTotal Simulation Time\text{Availability} = \frac{\text{Successful Packet Delivery Time}}{\text{Total Simulation Time}}Availability=Total Simulation TimeSuccessful Packet Delivery Time​
    • Packet Delivery Ratio (PDR): PDR=Packets Delivered SuccessfullyPackets Sent\text{PDR} = \frac{\text{Packets Delivered Successfully}}{\text{Packets Sent}}PDR=Packets SentPackets Delivered Successfully​
  1. Set Up the NS3 Simulation Environment
  1. Install NS3:
    • We can install and download the new version of NS3 on the system.
  2. Choose a Network Scenario:
    • Make a network topology that contains numerous nodes like wireless, sensor networks, or point-to-point.
  1. Define Conditions for Network Availability
  1. Simulate Failures:
    • During the simulation, launch link or node failures.
    • Make use of NS3’s ChannelFailureModel or custom events ro replicate the interruptions.
  2. Measure Packet Delivery:
    • Monitor the packet transmissions and receptions to leverage NS3 tracing approaches.
  1. Implement Network Availability Measurement

Here’s an instance script of NS3 for estimating the network availability including failure simulation.

Example Script: Network Availability 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”

using namespace ns3;

class AvailabilityTracker {

public:

AvailabilityTracker() : m_packetsSent(0), m_packetsDelivered(0) {}

void PacketSent() {

m_packetsSent++;

}

void PacketReceived() {

m_packetsDelivered++;

}

void CalculateAvailability(Time totalTime) {

double availability = static_cast<double>(m_packetsDelivered) / m_packetsSent * 100.0;

NS_LOG_UNCOND(“Network Availability: ” << availability << “%”);

NS_LOG_UNCOND(“Packet Delivery Ratio (PDR): ” << m_packetsDelivered << ” / ” << m_packetsSent);

}

private:

uint32_t m_packetsSent;

uint32_t m_packetsDelivered;

};

AvailabilityTracker availabilityTracker;

void SimulateFailure(Ptr<Node> node, Ptr<NetDevice> device, Time failTime, Time restoreTime) {

Simulator::Schedule(failTime, &NetDevice::SetAttribute, device, “IsEnabled”, BooleanValue(false));

Simulator::Schedule(restoreTime, &NetDevice::SetAttribute, device, “IsEnabled”, BooleanValue(true));

}

void SentPacketCallback(Ptr<const Packet> packet) {

availabilityTracker.PacketSent();

}

void ReceivedPacketCallback(Ptr<const Packet> packet) {

availabilityTracker.PacketReceived();

}

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

CommandLine cmd;

cmd.Parse(argc, argv);

// Create nodes

NodeContainer nodes;

nodes.Create(2);

// Configure Point-to-Point link

PointToPointHelper pointToPoint;

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

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

NetDeviceContainer devices = pointToPoint.Install(nodes);

// Install Internet stack

InternetStackHelper stack;

stack.Install(nodes);

// Assign IP addresses

Ipv4AddressHelper address;

address.SetBase(“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign(devices);

// Install applications

uint16_t port = 9;

UdpEchoServerHelper server(port);

ApplicationContainer serverApp = server.Install(nodes.Get(1));

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(10.0));

UdpEchoClientHelper client(interfaces.GetAddress(1), port);

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));

// Attach callbacks

devices.Get(0)->TraceConnectWithoutContext(“PhyTxEnd”, MakeCallback(&SentPacketCallback));

devices.Get(1)->TraceConnectWithoutContext(“PhyRxEnd”, MakeCallback(&ReceivedPacketCallback));

// Simulate link failure

SimulateFailure(nodes.Get(1), devices.Get(1), Seconds(4.0), Seconds(6.0)); // Failure from 4s to 6s

// Schedule availability calculation

Simulator::Schedule(Seconds(10.0), &AvailabilityTracker::CalculateAvailability, &availabilityTracker, Seconds(10.0));

Simulator::Run();

Simulator::Destroy();

return 0;

}

Explanation of the Script

  1. Network Topology:
    • It has point-to-point link associates two nodes like source and destination.
  2. Packet Tracking:
    • The AvailabilityTracker class monitors the transmitted and inherited packets by callbacks.
  3. Failure Simulation:
    • The SimulateFailure function inactivates and re-enables the link for replicating the network interruption.
  4. Availability Calculation:
    • Availability is determined as: Availability=Packets DeliveredPackets Sent×100\text{Availability} = \frac{\text{Packets Delivered}}{\text{Packets Sent}} \times 100Availability=Packets SentPackets Delivered​×100
  5. Outputs:
    • Records the network availability and percentage of packet delivery.
  1. Run the Simulation
  1. Build the script and execute the simulation using:

./waf –run “your-script-name”

  1. Monitor the records for network availability and fraction of packet delivery.
  1. Advanced Extensions
  1. Dynamic Topologies:
    • Mimic mobile networks and estimate the availability in diverse topologies using mobility patterns.
  2. Multiple Failures:
    • Replicate several link or node failures and then monitor its influence over availability.
  3. Complex Metrics:
    • Add components such as latency, jitter, and throughput for determining the composite availability metrics.
  4. Visualization:
    • Transfer information into external tools such as MATLAB, Python, or Excel for graphical analysis.

In this set up, Network Availability implementation was systematically demonstrated through simple procedure with sample coding using NS3 environment. We are ready to enhancing it further for advanced-level learning