To simulate a Circular Topology (also known as a Ring Topology) using OMNeT++ has requires to encompass making a network in which each node is connected to accurately two other nodes, forming a closed loop. In this topology, data travels in a circular fashion, and each node performs as a repeater by sending data to its next neighbour until it attains its destination. Here’s how we can simulate a Circular Topology in OMNeT++ step-by-step:
Steps to Simulate Circular Topology Projects in OMNeT++
- Define the Circular Topology Network Structure (NED File)
In the NED file, we will describe numerous nodes, each connected to its next neighbour in a circular fashion, including the last node connecting back to the initial node.
Sample NED File (CircularTopology.ned)
network CircularTopology
{
submodules:
// Define nodes (e.g., 6 nodes in the ring)
node[6]: Node {
@display(“p=100,100; p=200,100; p=300,100; p=400,100; p=500,100; p=600,100”);
}
connections allowunconnected:
// Connect each node to the next node to form a ring
node[0].out++ –> node[1].in++;
node[1].out++ –> node[2].in++;
node[2].out++ –> node[3].in++;
node[3].out++ –> node[4].in++;
node[4].out++ –> node[5].in++;
node[5].out++ –> node[0].in++; // Complete the ring
}
This NED file describes a basic circular topology in which each node is connected to two neighbouring nodes: one preceding and one succeeding it, forming a closed loop.
- Define the Node Module (Node.ned)
For each node in the ring will have an input and an output gate to transmit and receive messages from its neighbours. Here’s the delineation for the node structure.
Sample Node Module (Node.ned)
simple Node
{
parameters:
@display(“i=device/laptop”); // Use an icon to represent the node
gates:
input in[]; // Input gate for receiving messages
output out[]; // Output gate for sending messages
}
- Implement Node Behavior (Node.cc)
To each node will forward messages to the next node in the ring, and optionally, it may process the message if it is meant for that node. Here’s how we can execute this behaviour in C++:
Sample Node Behavior (Node.cc)
#include <omnetpp.h>
using namespace omnetpp;
class Node : public cSimpleModule
{
private:
int nodeId; // Identifier for each node
int numNodes; // Total number of nodes in the circular topology
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
void forwardMessage(cMessage *msg); // Function to forward the message to the next node
};
Define_Module(Node);
void Node::initialize()
{
nodeId = getIndex();
numNodes = getParentModule()->par(“numNodes”);
// Node 0 initiates the message sending after 1 second
if (nodeId == 0) {
cMessage *msg = new cMessage(“Message from Node 0”);
scheduleAt(simTime() + 1.0, msg);
}
}
void Node::handleMessage(cMessage *msg)
{
EV << “Node ” << nodeId << ” received message: ” << msg->getName() << “\n”;
// Forward the message to the next node
forwardMessage(msg);
}
void Node::forwardMessage(cMessage *msg)
{
EV << “Node ” << nodeId << ” forwarding message to the next node.\n”;
send(msg, “out”, 0); // Send the message to the next node in the ring
}
In this example:
- Node 0 initiates the message transmission by transmitting a message to the next node.
- Each node obtains the message, processes it, and forwards it to the next node until the message has circulated around the ring.
- Run the Simulation
To run the simulation, we require an omnetpp.ini file, which identifies the simulation configuration and the amount of nodes in the network.
Sample OMNeT++ Configuration (omnetpp.ini)
[General]
network = CircularTopology
sim-time-limit = 10s
# Number of nodes in the circular topology
*.numNodes = 6
*.node[*].numGates = 1 # Each node has 1 input and 1 output gate
- Visualize and Analyze
- Message Flow: We will monitor messages flowing in a circular fashion, initiation from Node 0, passing through each node, and returning to Node 0.
- Performance Metrics: We can calculate the delay, throughput, and other performance parameters as the message circulates around the ring.
- Enhance the Simulation
Here are some ways to improve the circular topology simulation:
- Bidirectional Communication
We can make a bidirectional ring topology in which messages can flow in both directions by connecting each node to both its preceding and succeeding neighbours. Change the connections within the NED file to support this.
Bidirectional Connections in the NED File:
network CircularTopology
{
submodules:
node[6]: Node {
@display(“p=100,100; p=200,100; p=300,100; p=400,100; p=500,100; p=600,100”);
}
connections allowunconnected:
// Bidirectional connections between nodes
node[0].out++ –> node[1].in++;
node[1].out++ –> node[0].in++;
node[1].out++ –> node[2].in++;
node[2].out++ –> node[1].in++;
node[2].out++ –> node[3].in++;
node[3].out++ –> node[2].in++;
node[3].out++ –> node[4].in++;
node[4].out++ –> node[3].in++;
node[4].out++ –> node[5].in++;
node[5].out++ –> node[4].in++;
node[5].out++ –> node[0].in++;
node[0].out++ –> node[5].in++; // Complete bidirectional ring
}
In the C++ implementation, we can change the forwardMessage function to choose a random direction (clockwise or counter-clockwise) when forwarding the message.
- Fault Tolerance
We can be replicated a scenario in which one or more nodes are fail to forward messages. For example, we could launch a failure condition in which nodes randomly fail to process or forward messages.
void Node::handleMessage(cMessage *msg)
{
if (uniform(0, 1) < 0.2) { // 20% chance of failure
EV << “Node ” << nodeId << ” failed to forward message.\n”;
delete msg; // Message is dropped
} else {
forwardMessage(msg); // Normal operation
}
}
- Multi-message Flow
We can permit several nodes to initiate communication, replicating numerous messages circulating via the network concurrently.
void Node::initialize()
{
nodeId = getIndex();
numNodes = getParentModule()->par(“numNodes”);
if (uniform(0, 1) < 0.3) { // 30% chance for any node to start sending
cMessage *msg = new cMessage(“Message from Node”);
scheduleAt(simTime() + uniform(1, 5), msg); // Random start time
}
}
- Traffic Load Simulation
To replicate distinct traffic loads, we can have nodes periodically generate new messages and monitor how the ring manages the high traffic scenarios.
void Node::initialize()
{
cMessage *msg = new cMessage(“Periodic Message”);
scheduleAt(simTime() + uniform(1, 5), msg); // Schedule periodic message generation
}
void Node::handleMessage(cMessage *msg)
{
forwardMessage(msg);
scheduleAt(simTime() + uniform(1, 5), msg); // Schedule the next message
}
- Use Case Example: Token Ring Network
This circular topology can be utilized to replicate a token ring network, in which a token is passed around the ring, and only the node holding the token can send data. To execute this:
- Make a special “token” message.
- Permit nodes to transmit data only if they hold the token.
- Pass the token around the ring after a node finishes sending.
We had expounded the basic simulation approach using the example coding for Circular Topology projects that were replicated and visualized through OMNeT++ simulator, with further insights relevant to this projects into the future.
phdprime.com will be your reliable partner, providing expert guidance for optimal simulation and network evaluation outcomes. For Circular Topology Projects utilizing OMNeT++, we will offer comprehensive support to ensure you achieve the best results. If needed, we will provide additional insights tailored to your specific area, complete with simulation results. Our developers are available to assist you in working with nodes effectively.