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

How to Implement Physical Topology in ns3

To implement a physical topology in ns3, we need to create a network with a specified layout of nodes and their connections. Below is a complete guide to implement physical topology in ns3.

Steps for implementation

Step 1: Install ns-3

Make sure that ns3 is installed in the computer. If not, install it.

Step 2: Create a New Simulation Script

For your simulation, create a new C++ script.

Step 3: Include Necessary Headers

include the necessary ns3 headers in your script.

#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 Physical Topology

Below is an example to set up a physical topology with point-to-point links.

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“PhysicalTopology”);

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

{

// Configure command line parameters

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer nodes;

nodes.Create (6); // Create 6 nodes

// Create point-to-point links

PointToPointHelper pointToPoint;

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

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

NetDeviceContainer devices;

std::vector<std::pair<uint32_t, uint32_t>> links = {

{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, // Linear topology

{0, 2}, {1, 3}, {2, 4}, {3, 5} // Additional connections

};

for (auto link : links)

{

NodeContainer pair (nodes.Get (link.first), nodes.Get (link.second));

NetDeviceContainer devicePair = pointToPoint.Install (pair);

devices.Add (devicePair);

}

// Install the internet stack

InternetStackHelper stack;

stack.Install (nodes);

// Assign IP addresses

Ipv4AddressHelper address;

Ipv4InterfaceContainer interfaces;

int subnetIndex = 1;

for (auto link : links)

{

std::ostringstream subnet;

subnet << “10.1.” << subnetIndex << “.0”;

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

interfaces.Add (address.Assign (devices.Get (subnetIndex – 1)));

subnetIndex++;

}

// Set up mobility

MobilityHelper mobility;

mobility.SetPositionAllocator (“ns3::GridPositionAllocator”,

“MinX”, DoubleValue (0.0),

“MinY”, DoubleValue (0.0),

“DeltaX”, DoubleValue (20.0),

“DeltaY”, DoubleValue (20.0),

“GridWidth”, UintegerValue (3),

“LayoutType”, StringValue (“RowFirst”));

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

mobility.Install (nodes);

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

uint16_t port = 9; // Port number for applications

// Install UDP Echo Server on node 0

UdpEchoServerHelper echoServer (port);

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

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

// Install UDP Echo Client on node 5 to communicate with node 0

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

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

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

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

ApplicationContainer clientApps = echoClient.Install (nodes.Get (5));

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

Save the script as physical-topology.cc and build the script using waf, then run the simulation.

./waf configure –enable-examples

./waf build

./waf –run scratch/physical-topology

Explanation of the script

  • Node Creation: For the physical network, creates six nodes.
  • Point-to-Point Links: With specified data rate and delay attributes, configured point-to-point links by creating both linear topology and additional connections to simulate a more complex network.
  • Internet Stack: On all nodes, installs the internet stack.
  • IP Addressing: To the network links, assigns IP addresses.
  • Mobility Model: using GridPositionAllocator and ConstantPositionMobilityModel, set the position of nodes in a grid layout.
  • Applications: On node 0, sets up a UDP echo server and a UDP echo client on overlay node 5 to demonstrate communication.

Overall, we had a implementation on physical topology by creating a virtual network with a specific layout of nodes and their connections. Also, we provide a detailed explanation on physical Topology.

Please provide us with the specifics of your parameters, and we will help you do a performance analysis of networking physical Topology in ns3.