To implement a daisy chain topology using NS3 that has numerous steps, to associate several nodes within a linear sequence in which each node is associated to the next node through a Point-to-Point (P2P) link. This topology replicates a basic chain of connected devices.
Below is a series of steps to implement a Daisy Chain Topology in NS3:
Steps to Begin Implement Daisy Chain Topology in NS3
- Understand the Daisy Chain Topology
In a daisy chain topology:
- Nodes are linearly associated.
- Every single node except the first and last node that contains accurately two neighbors.
- Interactions among non-adjacent node have to traverse intermediate nodes.
- Set Up NS3
- Install NS3:
- We should download and install NS3 on the system.
- Confirm the installation:
./waf –run hello-simulator
- Install Wireshark (optional):
- Examine the .pcap files which are made by NS3 leveraging Wireshark.
- Define the Daisy Chain Topology
Make topology with many nodes and associate them to utilize Point-to-Point (P2P) links in a linear fashion.
Define the Nodes
NodeContainer nodes;
nodes.Create(5); // Create 5 nodes for the daisy chain topology
Set Up the P2P Links
In a chain, associate the nodes with the help of PointToPointHelper:
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices;
std::vector<NetDeviceContainer> p2pLinks; // Store P2P links for each segment
for (uint32_t i = 0; i < nodes.GetN() – 1; ++i) {
NetDeviceContainer link = p2p.Install(nodes.Get(i), nodes.Get(i + 1));
devices.Add(link);
p2pLinks.push_back(link); // Keep track of individual links
}
- Assign IP Addresses
We need to setup the Internet stack and allocate an IP addresses to each link:
InternetStackHelper stack;
stack.Install(nodes);
Ipv4AddressHelper address;
std::vector<Ipv4InterfaceContainer> interfaces;
for (uint32_t i = 0; i < p2pLinks.size(); ++i) {
std::ostringstream subnet;
subnet << “192.168.” << i + 1 << “.0”; // Each link gets a unique subnet
address.SetBase(subnet.str().c_str(), “255.255.255.0”);
Ipv4InterfaceContainer iface = address.Assign(p2pLinks[i]);
interfaces.push_back(iface);
}
- Simulate Communication
Configure interaction among the initial and the destination nodes within the chain:
- Node 0 acts as a client.
- Node 4 acts as a server.
Server Application
We can install a UDP echo server at the end node:
UdpEchoServerHelper echoServer(9); // Server listens on port 9
ApplicationContainer serverApps = echoServer.Install(nodes.Get(4)); // Node 4 is the server
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));
Client Application
At the initial node, install a UDP echo client:
UdpEchoClientHelper echoClient(Ipv4Address(“192.168.4.2”), 9); // Node 4’s IP
echoClient.SetAttribute(“MaxPackets”, UintegerValue(5));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0))); // 1-second intervals
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024)); // 1 KB packets
ApplicationContainer clientApps = echoClient.Install(nodes.Get(0)); // Node 0 is the client
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));
- Enable Packet Capture
Allow to seizure packets for detailed packet analysis:
p2p.EnablePcapAll(“daisy-chain-topology”);
- Run the Simulation
Build and then run the simulation:
./waf –run daisy-chain-topology
- Example Code Skeleton
Below is a sample NS3 script for implementing daisy chain topology:
#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;
int main(int argc, char *argv[]) {
// Create nodes
NodeContainer nodes;
nodes.Create(5); // Daisy chain with 5 nodes
// Configure Point-to-Point links
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices;
std::vector<NetDeviceContainer> p2pLinks;
for (uint32_t i = 0; i < nodes.GetN() – 1; ++i) {
NetDeviceContainer link = p2p.Install(nodes.Get(i), nodes.Get(i + 1));
devices.Add(link);
p2pLinks.push_back(link);
}
// Install Internet stack
InternetStackHelper stack;
stack.Install(nodes);
// Assign IP addresses
Ipv4AddressHelper address;
std::vector<Ipv4InterfaceContainer> interfaces;
for (uint32_t i = 0; i < p2pLinks.size(); ++i) {
std::ostringstream subnet;
subnet << “192.168.” << i + 1 << “.0”;
address.SetBase(subnet.str().c_str(), “255.255.255.0”);
Ipv4InterfaceContainer iface = address.Assign(p2pLinks[i]);
interfaces.push_back(iface);
}
// Set up server application
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApps = echoServer.Install(nodes.Get(4)); // Node 4 is the server
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));
// Set up client application
UdpEchoClientHelper echoClient(interfaces[3].GetAddress(1), 9); // Node 4’s IP
echoClient.SetAttribute(“MaxPackets”, UintegerValue(5));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApps = echoClient.Install(nodes.Get(0)); // Node 0 is the client
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));
// Enable packet capture
p2p.EnablePcapAll(“daisy-chain-topology”);
// Run simulation
Simulator::Run();
Simulator::Destroy();
return 0;
}
- Extend the Simulation
- Increase the Number of Nodes: Prolong the daisy chain by integrating additional nodes.
- Measure Performance: Examine the performance parameters like delay, throughput, and packet loss.
- Simulate Multiple Traffic Flows: Incorporate extra clients and servers for replicating the simultaneous interaction.
We had provided meticulous structure on how to start implementing and extending the Daisy Chain Topology using NS3 simulation tool with sample snippets. More information will be shared on this topic in forthcoming manual.
