To simulate a Token Ring Topology in OMNeT++ has needs to generate a network in which the nodes are organized in a circular or ring-like structure, and a special message known as a “token” circulates around the ring. Only the node that holds the token is permitted to conduct data. This kind of topology safeguards controlled access to the network and evades collisions.
Here’s how you can simulate a Token Ring Topology project in OMNeT++ step-by-step:
Steps to Simulate Token Ring Topology Projects in OMNeT++
- Define the Token Ring Network Structure (NED File)
The physical and logical layout of the token ring topology contains numerous nodes organized in a ring, in which each node is associated to its next and previous neighbours. This NED file describes the network topology in which the nodes are assiociated in a circular manner.
Sample NED File (TokenRingTopology.ned)
network TokenRingTopology
{
submodules:
// Define multiple nodes for the token ring (e.g., 6 nodes)
node[6]: Node {
@display(“p=100,100; p=200,200; p=300,100; p=400,200; p=500,100; p=600,200”);
}
connections allowunconnected:
// Create the ring by connecting nodes in a circular manner
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++; // Close the ring
}
- Define the Node Behaviour for Token Passing
In the token ring topology, a token socializes around the ring. Each node delays for the token to arrive. When a node holds the token, it can weather transmit data or pass the token to the next node. If the node has no data to transmit, it immediately distributes the token to the next node in the ring.
Sample Node Module (Node.ned)
Each node will have an input gate to receive messages (data or tokens) and an output gate to transmit messages to the next node.
simple Node
{
parameters:
@display(“i=device/laptop”); // Represent the node as a laptop or any device icon
gates:
input in[];
output out[];
}
- Implement the Token Ring Behavior (Node.cc)
Now, let’s execute the features in which the token circulates in the ring, and nodes can send the data when they hold the token.
Sample Node Behavior (Node.cc)
#include <omnetpp.h>
using namespace omnetpp;
class Node : public cSimpleModule
{
private:
int nodeId; // Unique ID for each node
bool hasToken; // Whether the node currently holds the token
int totalNodes; // Total number of nodes in the ring
cMessage *token; // The token message that circulates around the ring
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
void passToken(); // Function to pass the token to the next node
void sendData(); // Function to send data when the node has the token
};
Define_Module(Node);
void Node::initialize()
{
nodeId = getIndex(); // Assign the node’s ID based on its index in the ring
totalNodes = getParentModule()->par(“numNodes”); // Get the total number of nodes
// Only the first node starts with the token
if (nodeId == 0) {
hasToken = true;
token = new cMessage(“Token”); // Create the token
scheduleAt(simTime() + 1.0, token); // Start the token circulation
} else {
hasToken = false;
token = nullptr;
}
}
void Node::handleMessage(cMessage *msg)
{
if (msg == token) {
// Node has received the token
EV << “Node ” << nodeId << ” received the token.\n”;
hasToken = true;
// Decide whether to send data or pass the token
if (uniform(0, 1) < 0.5) { // 50% chance to send data
sendData();
} else {
passToken();
}
} else {
// Node received a data message
EV << “Node ” << nodeId << ” received data: ” << msg->getName() << “\n”;
delete msg; // Process and delete the data message
}
}
void Node::sendData()
{
EV << “Node ” << nodeId << ” is sending data.\n”;
cMessage *dataMsg = new cMessage(“Data from Node”);
// Send the data message to the next node
send(dataMsg, “out”, 0);
// After sending data, pass the token
passToken();
}
void Node::passToken()
{
EV << “Node ” << nodeId << ” is passing the token to the next node.\n”;
hasToken = false;
// Pass the token to the next node in the ring
send(token, “out”, 0);
}
In this implementation:
- Token Initialization: Node 0 starts with the token.
- Token Handling: When a node receives the token, it can weather transmit data or pass the token to the next node.
- Data Transmission: When a node sends data, it passes the message to the next node in the ring.
- Token Passing: The token is distributed to the next node after the current node has transmitted data or decides not to send data.
- Run the Simulation
We will essential to describe the simulation configuration in the omnetpp.ini file. Here, we specify the number of nodes, the simulation time limit, and other network performance metrics.
Sample OMNeT++ Configuration (omnetpp.ini)
network = TokenRingTopology
sim-time-limit = 100s # Run the simulation for 100 seconds
# Define the number of nodes in the ring
*.numNodes = 6
# Each node has 1 input and 1 output gate to form the token ring
*.node[*].numGates = 1
- Visualize and Analyse the Simulation
After running the simulation, we need to monitor:
- Token Circulation: The token will move from one node to the next in the ring. The token make sure that only one node can send data at a time, avoiding collisions.
- Data Transmission: When a node holds the token, it either transmits data or passes the token to the next node.
- Performance Metrics: we need to track the transmission delay, token handoff time, and overall network performance based on how frequently each node gets the opportunity to send.
- Enhance the Simulation
Here are several ways to improve the token ring simulation:
- Variable Data Generation
We need to establish more realistic data traffic by having nodes generate data at random intervals or according to specific triggers.
void Node::generateRandomData()
{
if (uniform(0, 1) < 0.2) { // 20% chance of generating data
sendData();
} else {
passToken();
}
}
- Failure Simulation
We need to replicate node or token failures by randomly stopping a node from passing the token or replicating token loss.
void Node::handleMessage(cMessage *msg)
{
if (uniform(0, 1) < 0.1) { // 10% chance of failure
EV << “Node ” << nodeId << ” failed to pass the token.\n”;
delete token; // Simulate token loss
} else {
// Normal token handling
if (msg == token) {
EV << “Node ” << nodeId << ” received the token.\n”;
…
}
}
}
- Prioritized Token Handling
We need to execute a priority system in which nodes with higher priority get to send more often, or only high-priority nodes can transmit data at specific times.
if (hasHighPriority()) {
sendData(); // High-priority node sends data more frequently
} else {
passToken(); // Lower-priority nodes pass the token more often
}
- Variable Token Holding Time
Rather than immediately passing the token, each node can hold the token for a particular time before passing it, replicating different token-holding periods.
void Node::handleMessage(cMessage *msg)
{
if (msg == token) {
EV << “Node ” << nodeId << ” is holding the token for a short period.\n”;
scheduleAt(simTime() + 0.5, token); // Hold the token for 0.5 seconds before passing
}
}
- Example Use Case: Token Ring in LAN
The token ring topology was historically utilized in Local Area Networks (LANs) such as IEEE 802.5 Token Ring networks. This simulation could design on how data would be routed in such networks, making sure controlled and collision-free communication.
In this setup we had clearly gather information on how to setup the simulation and how to replicate the Token Ring Topology using OMNeT++ tool. We will offer insights into the implementation of the Token Ring Topology in diverse simulation scenarios.
We work on all sorts of topology secures restricted access to the network and evades collisions, connected to your projects, so receive the best results from phdprime.com to conduct out simulation in Token Ring Topology Projects. Using the OMNeT++ program, we will walk you through the process in detail and provide the best results. We will provide further information on this issue in your requested location, along with simulation results, if necessary.