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

How to Implement Flat Topology in ns3

To implement a flat topology in ns3, we need to set up a network like a star topology in which all the nodes are directly connected to a single node or hub without break connections.

Below the instructions given to set up a simple flat topology in ns3.

Step-by-step to implement Flat Topology

Step 1: Install ns3

Make sure ns3 is installed on the system

Step 2: Create a New Simulation Script

Create a new C++ script for the simulation.

Step 3: Include Necessary Headers

In the script, include the necessary ns3 headers:

#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”

Step 4: Set Up the Flat Topology

Below an example given for setting up a flat topology with one central node and multiple peripheral nodes:

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“FlatTopology”);

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

{

// Configure command line parameters

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer centralNode;

centralNode.Create (1); // Create the central node

NodeContainer peripheralNodes;

peripheralNodes.Create (4); // Create 4 peripheral nodes

NodeContainer allNodes = NodeContainer (centralNode, peripheralNodes);

// Create point-to-point links between the central node and each peripheral node

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“1Gbps”));

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

NetDeviceContainer devices;

Ipv4AddressHelper address;

Ipv4InterfaceContainer interfaces;

for (uint32_t i = 0; i < peripheralNodes.GetN (); ++i)

{

NodeContainer pair (centralNode.Get (0), peripheralNodes.Get (i));

NetDeviceContainer devicePair = pointToPoint.Install (pair);

devices.Add (devicePair);

std::ostringstream subnet;

subnet << “10.1.” << i + 1 << “.0”;

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

interfaces.Add (address.Assign (devicePair));

}

// Install the internet stack

InternetStackHelper stack;

stack.Install (allNodes);

// Set up mobility model (optional)

MobilityHelper mobility;

Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();

positionAlloc->Add (Vector (50.0, 50.0, 0.0)); // Central node position

positionAlloc->Add (Vector (100.0, 50.0, 0.0));

positionAlloc->Add (Vector (50.0, 100.0, 0.0));

positionAlloc->Add (Vector (0.0, 50.0, 0.0));

positionAlloc->Add (Vector (50.0, 0.0, 0.0));

mobility.SetPositionAllocator (positionAlloc);

mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);

mobility.Install (allNodes);

// Set up applications (e.g., UDP echo server and client)

uint16_t port = 9; // Port number for applications

// Install UDP Echo Server on the central node

UdpEchoServerHelper echoServer (port);

ApplicationContainer serverApps = echoServer.Install (centralNode.Get (0));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

// Install UDP Echo Clients on peripheral nodes to communicate with the central node

for (uint32_t i = 0; i < peripheralNodes.GetN (); ++i)

{

UdpEchoClientHelper echoClient (interfaces.GetAddress (i), port);

echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));

echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));

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

ApplicationContainer clientApps = echoClient.Install (peripheralNodes.Get (i));

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));

}

// Run simulation

Simulator::Stop (Seconds (10.0));

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Step 5: Build and Run the Simulation

  1. Save the script as flat-topology.cc.
  2. Build the script using waf:

./waf configure –enable-examples

./waf build

  1. Run the simulation:

./waf –run scratch/flat-topology

Explanation of the Script

  • Node Creation: Creates one central node and four peripheral nodes.
  • Point-to-Point Links: Configures point-to-point links to connect the central node to each peripheral node.
  • Internet Stack: Installs the internet stack on all nodes.
  • IP Addressing: Assigns IP addresses to the network links using different subnets for each link.
  • Mobility Model: Sets the position of nodes in a specific layout using ListPositionAllocator and ConstantPositionMobilityModel.
  • Applications: Sets up a UDP echo server on the central node and UDP echo clients on the peripheral nodes to demonstrate communication between node

The given above example scripts and instruction elaborately explains about the implementation of Flat topology in ns3 which network connection is similar to the star topology.

If you could provide us with the details of your parameters, we would assist you with your networking performance analysis on Flat Topology.