To implement the circular topology in ns3 has also known as ring topology that encompasses to generate the network where each node is connected approximately with two other nodes that forms a closed loop.
Here, we provide the detailed procedures to setup the circular topology in ns3:
Steps to Implement a Circular Topology in ns3
- Set Up the ns3 Environment:
- Make sure ns3 is installed and configured correctly.
- Create the Nodes:
- Create a set of nodes to represent the devices in the circular network.
- Set Up the Point-to-Point Channels:
- Use point-to-point helpers to connect each node to its immediate neighbour, forming a closed loop.
- Install Network Stack:
- Install the internet stack on all nodes.
- Assign IP Addresses:
- Assign IP addresses to the nodes connected by the point-to-point links.
- Set Up Applications:
- Install applications to generate traffic and demonstrate communication between nodes.
Example Code
The given below is the sample on how to set up the simple circular 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 (“CircularTopologyExample”);
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
// Create nodes
NodeContainer nodes;
nodes.Create (5); // Create 5 nodes for the circular topology
// Create point-to-point links
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
int subnet = 1;
// Connect each node to its neighbor to form a circular topology
for (uint32_t i = 0; i < nodes.GetN (); ++i)
{
NetDeviceContainer link;
if (i == nodes.GetN () – 1)
{
// Connect the last node to the first node to complete the circle
link = pointToPoint.Install (NodeContainer (nodes.Get (i), nodes.Get (0)));
}
else
{
// Connect the current node to the next node
link = pointToPoint.Install (NodeContainer (nodes.Get (i), nodes.Get (i + 1)));
}
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 one of the nodes
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 another node
UdpClientHelper udpClient (Ipv4Address (“10.1.1.2”), 9); // IP of the server 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 (“circular-topology”);
// Enable logging
LogComponentEnable (“UdpClient”, LOG_LEVEL_INFO);
LogComponentEnable (“UdpServer”, LOG_LEVEL_INFO);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Explanation
- Setup: The code sets up a circular topology with five nodes connected by point-to-point links.
- Point-to-Point Links: Point-to-point links are created to connect each node to its immediate neighbor, forming a closed loop. The data rate and delay are configured for the links.
- Network Stack: The internet stack is installed on all nodes.
- IP Addresses: IP addresses are assigned to the nodes connected by the point-to-point links.
- Applications: A UDP server is installed on one of the nodes, and a UDP client is installed on another node to generate traffic and demonstrate communication.
- Packet Capture: Packet capture is enabled for the point-to-point links to observe network traffic.
- 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 NS-3 environment:
./waf configure
./waf build
./waf –run circular-topology-example
Replace circular-topology-example with the actual name of your script file.
Here, we had successfully implemented the basic network with Circular Topology in ns3 by creating applications that generate traffic among the nodes. We will explain the techniques employed in executing the circular topology across multiple simulations.
The implementation of Circular Topology in ns3 to generate the network with the best programming results is guaranteed by our team of developers for your project.