To calculate the maximum transfer unit (MTU) in ns3, we need to configure the parameters for network devices and links that describe the largest sizes of a packet that can transfer over the network. MTU is predefined values we need to evaluate the efficiency of MTU in network that look out the smallest MTU across the path among two nodes. Here are the procedures on how to calculate and setup the MTU in ns3.
Step-by-Step Guide to Configure and Check MTU in ns3
- Set up Your Simulation Environment: Create a network topology; configure nodes, links, and protocols.
- Configure MTU for Network Devices: Set the MTU value for each network device in the simulation.
- Install Applications: Set up applications on the nodes to generate and receive traffic.
- Check MTU in the Simulation: Verify the MTU settings and observe the behaviour.
Example: Configuring and Verifying MTU in ns3
Here we generate the basic network topology then configure the MTU for the network devices and then validate the MTU settings.
Step 1: Set Up Your Simulation Environment
#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 (“MtuExample”);
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 with a specified MTU
NetDeviceContainer devices = pointToPoint.Install (nodes);
for (uint32_t i = 0; i < devices.GetN (); ++i)
{
Ptr<NetDevice> device = devices.Get (i);
device->SetMtu (1400); // Set MTU to 1400 bytes
}
// Install the 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);
// 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 (10.0));
// Set up the UDP echo client on Node 0
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), port);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (10));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0))); // 1 packet per second
echoClient.SetAttribute (“PacketSize”, UintegerValue (1200)); // Packet size smaller than MTU
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
// Enable pcap tracing
pointToPoint.EnablePcapAll (“mtu-example”);
// Run the simulation
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Explanation
- Set up Your Simulation Environment: Create two nodes and connect them with a point-to-point link.
- Configure MTU for Network Devices: Use the SetMtu method to configure the MTU for each network device in the simulation. In this example, we set the MTU to 1400 bytes.
- Install Applications: Install a UDP echo server on Node 1 and a UDP echo client on Node 0. Configure the client to send packets with a size smaller than the MTU to avoid fragmentation.
- Check MTU in the Simulation: Enable pcap tracing to capture packets and verify the MTU settings.
Step-by-Step Breakdown
- Create Nodes and Links: Two nodes are created and connected with a point-to-point link with a specified data rate and delay.
- Configure MTU for Network Devices: The MTU is set to 1400 bytes for each network device.
- Install Internet Stack and Applications: The Internet stack is installed on the nodes, and a UDP echo server and client are set up to generate and receive traffic.
- Verify MTU Settings: Pcap tracing is enabled to capture packets and verify that the packet size does not exceed the MTU.
Additional Steps to Check Effective MTU in a Multi-Hop Network
To check the effectiveness of MTYU in the multi-hop network defined by the smallest MTU along with the path and also we need to setup and configure with numerous links and validate its effectiveness in MTU by spotting the packet fragmentation or by performed the path MTU by traceroute application.
#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 (“MtuMultiHopExample”);
int main (int argc, char *argv[])
{
// Create three nodes
NodeContainer nodes;
nodes.Create (3);
// Set up point-to-point links
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
// Install link devices on nodes with different MTUs
NetDeviceContainer devices1 = pointToPoint.Install (nodes.Get (0), nodes.Get (1));
devices1.Get (0)->SetMtu (1400); // MTU for the first link
devices1.Get (1)->SetMtu (1400);
NetDeviceContainer devices2 = pointToPoint.Install (nodes.Get (1), nodes.Get (2));
devices2.Get (0)->SetMtu (1200); // MTU for the second link
devices2.Get (1)->SetMtu (1200);
// Install the internet stack
InternetStackHelper stack;
stack.Install (nodes);
// Assign IP addresses
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces1 = address.Assign (devices1);
address.SetBase (“10.1.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces2 = address.Assign (devices2);
// Set up the UDP echo server on Node 2
uint16_t port = 9; // well-known echo port number
UdpEchoServerHelper echoServer (port);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (2));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
// Set up the UDP echo client on Node 0
UdpEchoClientHelper echoClient (interfaces2.GetAddress (1), port);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (10));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0))); // 1 packet per second
echoClient.SetAttribute (“PacketSize”, UintegerValue (1100)); // Packet size smaller than smallest MTU
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
// Enable pcap tracing
pointToPoint.EnablePcapAll (“mtu-multi-hop-example”);
// Run the simulation
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Explanation
- Create Nodes and Links: Three nodes are created and connected with two point-to-point links with specified data rates and delays.
- Configure Different MTUs: The MTU is set to 1400 bytes for the first link and 1200 bytes for the second link.
- Install Internet Stack and Applications: The Internet stack is installed on the nodes, and a UDP echo server and client are set up to generate and receive traffic.
- Verify Effective MTU: The packet size is set to be smaller than the smallest MTU to avoid fragmentation. Pcap tracing is enabled to capture packets and verify the MTU settings.
In this, we had learned how to calculate and simulate the Maximum Transfer Unit in ns3 tool and then we provide the additional configuration and network simulation how MTU performs in Multi-hop network. Also we elaborate on how the MTU performs in other tools.