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

How to Calculate Overhead in routing in Ns3

To calculate the overhead in routing in ns3, we need to measure the amount of control traffic, number of routing packets, their size, and the frequency of their transmission that are generated by the routing protocol which is related to the data traffic.

To figure out the overhead in routing in ns3, just send us your parameters. We’ll give you the best results because our developers have been working in this area for over a decade.

The following steps will guide to calculate the Routing Overhead in ns3.

Step-by-Step Guide to Calculate Routing Overhead in ns3

  1. Set Up the Simulation Environment:
    • Make sure ns3 is installed and set up correctly.
    • Include necessary modules for the simulation (e.g., Internet, Mobility, specific routing protocol like OLSR, AODV).
  2. Create Network Topology:
    • Define nodes and configure the network topology.
    • Set up routing protocols as needed (e.g., OLSR, AODV).
  3. Configure Applications:
    • Install traffic-generating applications (e.g., UDP, TCP) on the nodes.
  4. Enable Tracing and Metrics Collection:
    • Enable tracing to capture relevant metrics such as routing packets and data packets.
  5. Run the Simulation:
    • Execute the simulation and collect the trace data.
  6. Analyze the Results:
    • Post-process the trace data to calculate the routing overhead.

Example Code Snippet for Routing Overhead

Here’s an example of how to set up a network with OLSR routing, generate traffic, and capture metrics to calculate routing overhead 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/olsr-helper.h”

#include “ns3/flow-monitor-module.h”

#include “ns3/log.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“RoutingOverheadExample”);

uint32_t totalRoutingBytes = 0;

void RxRoutingPacket (Ptr<const Packet> packet, const Address &address)

{

totalRoutingBytes += packet->GetSize ();

}

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

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

for (uint32_t i = 0; i < nodes.GetN () – 1; ++i)

{

devices.Add (pointToPoint.Install (nodes.Get (i), nodes.Get (i + 1)));

}

// Install Internet stack and OLSR routing protocol

InternetStackHelper internet;

OlsrHelper olsr;

internet.SetRoutingHelper (olsr);

internet.Install (nodes);

// Assign IP addresses

Ipv4AddressHelper ipv4;

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

Ipv4InterfaceContainer interfaces = ipv4.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 (nodes.GetN () – 1));

serverApp.Start (Seconds (1.0));

serverApp.Stop (Seconds (10.0));

UdpClientHelper client (interfaces.GetAddress (nodes.GetN () – 1), 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 (10.0));

// Trace routing packets

Config::ConnectWithoutContext (“/NodeList/*/DeviceList/*/$ns3::olsr::RoutingProtocol/RxRoutingPacket”, MakeCallback (&RxRoutingPacket));

// Set up FlowMonitor to collect performance metrics

FlowMonitorHelper flowmon;

Ptr<FlowMonitor> monitor = flowmon.InstallAll ();

// Run the simulation

Simulator::Stop (Seconds (11.0));

Simulator::Run ();

// Calculate total data packets transmitted

monitor->CheckForLostPackets ();

Ptr<Ipv4FlowClassifier>classifier=DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());

std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();

double totalDataBytes = 0.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.10”))

{

totalDataBytes += i->second.txBytes;

}

}

// Calculate routing overhead

double overhead = static_cast<double> (totalRoutingBytes) / totalDataBytes;

NS_LOG_UNCOND (“Total Routing Overhead: ” << overhead);

// Clean up

Simulator::Destroy ();

return 0;

}

Explanation:

  1. Setup Logging:
    • Enable logging for the UDP applications to track their activities.
  2. Create Nodes:
    • Create a set of nodes representing devices in the network.
  3. Install Mobility Model:
    • Install a mobility model on the nodes (e.g., ConstantPositionMobilityModel).
  4. Create Point-to-Point Links:
    • Install point-to-point links between the nodes.
  5. Install Internet Stack and Routing Protocol:
    • Install the Internet stack and set OLSR as the routing protocol.
  6. Assign IP Addresses:
    • Assign IP addresses to the network interfaces.
  7. Install Applications:
    • Install UDP server and client applications on the nodes.
  8. Trace Routing Packets:
    • Connect to the RxRoutingPacket trace source to track routing packets and accumulate their sizes.
  9. Set Up FlowMonitor:
    • Install FlowMonitor to collect and analyze flow statistics.
  10. Run Simulation:
    • Run the simulation for the specified duration.
  11. Calculate Total Data Packets Transmitted:
    • Extract the flow statistics and calculate the total data bytes transmitted.
  12. Calculate Routing Overhead:
    • Calculate the routing overhead as the ratio of total routing bytes to total data bytes.

Analyzing the Results:

  • Routing Overhead:
    • Routing overhead is calculated as the ratio of the total routing bytes to the total data bytes transmitted.
    • This metric provides an indication of the efficiency of the routing protocol in terms of control traffic relative to data traffic.

From the above steps we had clearly get to know Overhead in routing in ns3 is calculated by dividing the total routing bytes to total data bytes and analyzing the results using the metrics provided.We’ll also help you understand about simulation performance, with clear explanations from us.