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

How to Implement Daisy Chain Topology in ns3

To implement the daisy chain topology in ns3 has generate the network where each node is connected to exactly two other nodes (except for the two end nodes, which are each connected to only one other node).

Here we provide the procedure on how to setup the daisy chain topology in ns3:

Steps to Implement a Daisy Chain Topology in ns3

  1. Set Up the ns3 Environment:
    • Make certain ns3 is installed and configured correctly in the computer.
  2. Create the Nodes:
    • Create a set of nodes to represent the devices in the daisy chain network.
  3. Set Up the Point-to-Point Channels:
    • Use point-to-point helpers to connect each node to its immediate neighbour, forming a chain.
  4. Install Network Stack:
    • Install the internet stack on all nodes.
  5. Assign IP Addresses:
    • Assign IP addresses to the nodes connected to the point-to-point links.
  6. Set Up Applications:
    • Install applications to generate traffic and demonstrate communication between nodes.

Example Code

The given below is the sample on how to setup the basic daisy chain topology 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;

NS_LOG_COMPONENT_DEFINE (“DaisyChainTopologyExample”);

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

{

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer nodes;

nodes.Create (5); // Create 5 nodes for the daisy chain

// Create point-to-point links

PointToPointHelper pointToPoint;

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

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

NetDeviceContainer devices;

InternetStackHelper stack;

stack.Install (nodes);

Ipv4AddressHelper address;

int subnet = 1;

// Connect each node to its neighbor to form a daisy chain

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

{

NetDeviceContainer link = pointToPoint.Install (NodeContainer (nodes.Get (i), nodes.Get (i + 1)));

devices.Add (link);

std::ostringstream subnetStream;

subnetStream << “10.1.” << subnet++ << “.0”;

address.SetBase (subnetStream.str ().c_str (), “255.255.255.0”);

address.Assign (link);

}

// Enable routing

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

// Create a UDP server on the last node

UdpServerHelper udpServer (9);

ApplicationContainer serverApp = udpServer.Install (nodes.Get (nodes.GetN () – 1));

serverApp.Start (Seconds (1.0));

serverApp.Stop (Seconds (10.0));

// Create a UDP client on the first node

UdpClientHelper udpClient (address.NewAddress (), 9); // IP of the last node

udpClient.SetAttribute (“MaxPackets”, UintegerValue (320));

udpClient.SetAttribute (“Interval”, TimeValue (MilliSeconds (50)));

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

ApplicationContainer clientApp = udpClient.Install (nodes.Get (0));

clientApp.Start (Seconds (2.0));

clientApp.Stop (Seconds (10.0));

// Enable packet capture

pointToPoint.EnablePcapAll (“daisy-chain-topology”);

// Enable logging

LogComponentEnable (“UdpClient”, LOG_LEVEL_INFO);

LogComponentEnable (“UdpServer”, LOG_LEVEL_INFO);

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Explanation

  1. Setup: The code sets up a daisy chain topology with five nodes connected by point-to-point links.
  2. Point-to-Point Links: Point-to-point links are created to connect each node to its immediate neighbor, forming a chain. The data rate and delay are configured for the links.
  3. Network Stack: The internet stack is installed on all nodes.
  4. IP Addresses: IP addresses are assigned to the nodes connected by the point-to-point links.
  5. Applications: A UDP server is installed on the last node in the chain, and a UDP client is installed on the first node to generate traffic and demonstrate communication.
  6. Packet Capture: Packet capture is enabled for the point-to-point links to observe network traffic.
  7. Logging: Logging is enabled for the UDP client and server applications to provide detailed output during the simulation.

Running the Simulation

Compile and run the simulation using the following commands in your ns3 environment:

./waf configure

./waf build

./waf –run daisy-chain-topology-example

Replace daisy-chain-topology-example with the actual name of your script file.

In the end, we had calculated and simulated the outcomes on implementing the daisy chain topology in ns3 by generating the nodes, assign the IP address and then download the application to generate e the traffic among nodes. We will give further insights about how the daisy chain topology will perform in other simulation tool.

Our team ensures best simulation result by implementing Daisy Chain Topology in ns3 for your project.