How to Start Fully Connected Topology Projects Using NS3
To start fully connected topology in NS3, these every node is linked directly to each other node. This topology is helpful for replications to have need of high redundancy or learning all-to-all interaction patterns like distributed systems or peer-to-peer networks.
Steps to Start Fully Connected Topology Project in NS3
Step 1: Set Up NS3
- Install NS3:
- Go to NS3 website to download NS3 on the computer.
- We adhere to the installation steps.
- Verify Installation: Make sure that NS3 is installed properly including a simple example:
./waf –run scratch/my_first
Step 2: Understand Fully Connected Topology
- Fully Connected Topology:
- Every single node is linked to each other node directly.
- It needs n× (n−1)/2n \times (n – 1) / 2n× (n−1)/2 links for nnn nodes.
- Makes sure that high redundancy however it can be expensive such as resources.
Step 3: Set Up the Fully Connected Topology
- Create Nodes: In the network, we need to describe the volume of nodes.
NodeContainer nodes;
uint32_t numNodes = 5; // Number of nodes
nodes.Create(numNodes);
- Set up Point-to-Point Links: Describe link properties to utilize PointToPointHelper.
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
- Connect Each Node to Every Other Node: Make a fully connected network via nested loops to link each node to other node.
NetDeviceContainer devices;
for (uint32_t i = 0; i < numNodes; ++i) {
for (uint32_t j = i + 1; j < numNodes; ++j) {
NetDeviceContainer link = p2p.Install(nodes.Get(i), nodes.Get(j));
devices.Add(link);
}
}
- Install Internet Stack: We can install the IP stack at every node in this topology.
InternetStackHelper stack;
stack.Install(nodes);
- Assign IP Addresses: In each link, allocate a distinct IP addresses.
Ipv4AddressHelper address;
uint32_t subnetIndex = 1;
for (uint32_t i = 0; i < numNodes; ++i) {
for (uint32_t j = i + 1; j < numNodes; ++j) {
std::ostringstream subnet;
subnet << “10.1.” << subnetIndex++ << “.0”;
address.SetBase(subnet.str().c_str(), “255.255.255.0”);
address.Assign(devices.Get(subnetIndex – 1));
}
}
Step 4: Set Up Applications
- Install Server Applications: We need to set a UDP echo server at each node or a subset of nodes.
for (uint32_t i = 0; i < numNodes; ++i) {
UdpEchoServerHelper echoServer(9); // Port 9
ApplicationContainer serverApp = echoServer.Install(nodes.Get(i));
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
}
- Install Client Applications: Configure UDP echo clients at every node interacting with all other node.
for (uint32_t i = 0; i < numNodes; ++i) {
for (uint32_t j = 0; j < numNodes; ++j) {
if (i != j) {
UdpEchoClientHelper echoClient(Ipv4Address(“10.1.1.1”), 9); // Replace with correct IP
echoClient.SetAttribute(“MaxPackets”, UintegerValue(10));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = echoClient.Install(nodes.Get(i));
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(10.0));
}
}
}
Step 5: Run and Analyze
- Run the Simulation: We should execute the simulation get through following commands.
Simulator::Run();
Simulator::Destroy();
- Enable Packet Capture: Allow packet to capture utilising .pcap files for traffic analysis.
p2p.EnablePcapAll(“fully_connected”);
- Trace Logs: Support logging for debugging.
export NS_LOG=”UdpEchoClientApplication=level_all|prefix_func”
./waf –run scratch/fully_connected_topology
Example: Minimal NS3 Script for Fully Connected 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[]) {
uint32_t numNodes = 5;
// Create nodes
NodeContainer nodes;
nodes.Create(numNodes);
// Set up Point-to-Point links
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
// Connect each node to every other node
NetDeviceContainer devices;
for (uint32_t i = 0; i < numNodes; ++i) {
for (uint32_t j = i + 1; j < numNodes; ++j) {
NetDeviceContainer link = p2p.Install(nodes.Get(i), nodes.Get(j));
devices.Add(link);
}
}
// Install Internet stack
InternetStackHelper stack;
stack.Install(nodes);
// Assign IP addresses
Ipv4AddressHelper address;
uint32_t subnetIndex = 1;
for (uint32_t i = 0; i < numNodes; ++i) {
for (uint32_t j = i + 1; j < numNodes; ++j) {
std::ostringstream subnet;
subnet << “10.1.” << subnetIndex++ << “.0”;
address.SetBase(subnet.str().c_str(), “255.255.255.0”);
address.Assign(devices.Get(subnetIndex – 1));
}
}
// Set up UDP echo server on every node
for (uint32_t i = 0; i < numNodes; ++i) {
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApp = echoServer.Install(nodes.Get(i));
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
}
// Set up UDP echo clients on every node
for (uint32_t i = 0; i < numNodes; ++i) {
for (uint32_t j = 0; j < numNodes; ++j) {
if (i != j) {
UdpEchoClientHelper echoClient(Ipv4Address(“10.1.1.1”), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(10));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = echoClient.Install(nodes.Get(i));
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(10.0));
}
}
}
// Enable packet capture
p2p.EnablePcapAll(“fully_connected”);
// Run the simulation
Simulator::Run();
Simulator::Destroy();
return 0;
}
Step 6: Compile and Run
- We can save the script in terms of fully_connected_topology.cc.
- Then, compile and execute it:
./waf –run fully_connected_topology
Step 7: Enhance the Simulation
- Experiment with Traffic Models:
- Make utilize of TCP, FTP, or HTTP traffic rather than UDP.
- Analyze Performance:
- Examine the performance indicators such as throughput, delay, and packet loss in fully connected topology.
- Simulate Failures:
- Inactivate links or nodes observing the influence over redundancy.
- Visualize:
- Envision the topology and traffic flow exploiting NetAnim tool in NS3.
Next Steps
- Extend the topology managing additional nodes.
- We equate the fully connected topology including other configurations such as mesh or star topology.
- We want to execute the custom routing protocols enhancing the interaction in compact networks.
Employing NS3 environment, we have developed a simulation framework to replicate and analyze Fully Connected Topology projects, with more information to be revealed in the upcoming manual.
We specialize in high redundancy and learning all-to-all interaction patterns, like those found in distributed systems or peer-to-peer networks. Just send us your project details for more help. To kick off your Fully Connected Topology Projects with NS3, we’ll run simulations tailored to your needs. We’re here to support you every step of the way to make sure your project is a success.