How to start Token Ring Topology projects using ns3

To stimulate the Token Ring Topology is a network configuration in which nodes are arranged in a circular (ring) layout and a token circulates between the nodes we control their permits to the shared medium. Only the node has holding the token can forwarding the data and assuring the collision-free communication.

The NS-3 does not have native support for token-passing mechanisms. However, we can execute the behaviour for used in the custom application of logic and the basic ring topology characteristics.

Steps to start Token Ring Topology projects using ns3

Step 1: Set Up NS-3

  1. Install NS-3:
    • Download NS-3.
    • Follow the installation steps.
  2. Verify Installation: Process the basic script of assure the NS-3 is correctly set up:

./waf –run scratch/my_first

Step 2: Understand Token Ring Topology

  • Token Ring Characteristics:
    • The nodes are connected in a unidirectional ring.
    • A token ring circulates the grant transmission of permission.
    • It only one node transmits at a time.

Step 3: Plan the Topology

  1. Define the number of nodes:
    • For Sample, Ring topology has contained the six nodes.
  2. Set simulation goals:
    • Establish the token circulation.
    • Replicate the data transmission through the node holding the token.
  3. Model the token-passing mechanism:
    • Replicate the token’s movement and its effect of data transmission.

Step 4: Set Up the Physical Ring Topology

  1. Create Nodes: State the ring topology nodes are the token ring.

NodeContainer nodes;

uint32_t numNodes = 6;

nodes.Create(numNodes);

  1. Set Up Point-to-Point Links: Connect nodes point-to-point connections in a unidirectional ring used in the PointToPointHelper.

PointToPointHelper p2p;

p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));

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

NetDeviceContainer devices;

for (uint32_t i = 0; i < numNodes; ++i) {

NetDeviceContainer link = p2p.Install(nodes.Get(i), nodes.Get((i + 1) % numNodes)); // Ring connection

devices.Add(link);

}

  1. Install Internet Stack: Improve the Internet stack to overall nodes.

InternetStackHelper stack;

stack.Install(nodes);

Ipv4AddressHelper address;

address.SetBase(“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign(devices);

Step 5: Implement Token-Passing Logic

  1. Define the Token: Characterize the token as a shared variable.

uint32_t tokenHolder = 0; // Initially, node 0 holds the token

  1. Simulate Token Circulation: Utilized their token circulation we replicate the timer to circulate the token between nodes.

void PassToken(uint32_t currentNode, uint32_t numNodes) {

tokenHolder = (currentNode + 1) % numNodes;

Simulator::Schedule(Seconds(1.0), &PassToken, tokenHolder, numNodes);

NS_LOG_UNCOND(“Token passed to Node ” << tokenHolder);

}

  1. Control Transmission: Allocate their only one token holder we sends the data.

void TransmitData(uint32_t nodeId) {

if (nodeId == tokenHolder) {

NS_LOG_UNCOND(“Node ” << nodeId << ” is transmitting data.”);

// Simulate data transmission logic here

}

}

  1. Set Up Initial Token Passing: Start the set up initial token passing the circulation at the beginning of the replication.

Simulator::Schedule(Seconds(1.0), &PassToken, tokenHolder, numNodes);

Step 6: Set Up Applications

  1. Install Applications: Utilized their setup application approach for UDP echo or custom applications we replicate the communication.

UdpEchoServerHelper echoServer(9); // Port 9

ApplicationContainer serverApp = echoServer.Install(nodes.Get(0)); // Server on Node 0

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(10.0));

UdpEchoClientHelper echoClient(Ipv4Address(“10.1.1.1”), 9); // Server’s IP

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

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

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

ApplicationContainer clientApp = echoClient.Install(nodes.Get(3)); // Client on Node 3

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(10.0));

Step 7: Run and Analyze

  1. Run the Simulation:

Simulator::Run();

Simulator::Destroy();

  1. Enable Packet Capture: Save .pcap files for analysis.

p2p.EnablePcapAll(“token_ring_topology”);

  1. Trace Logs: Ensure the trace logging we monitor the token circulation and data transmission:

export NS_LOG=”UdpEchoClientApplication=level_all|prefix_func”

./waf –run scratch/token_ring_topology

Example: Minimal NS-3 Script for Token Ring 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;

uint32_t tokenHolder = 0; // Initially, Node 0 holds the token

void PassToken(uint32_t currentNode, uint32_t numNodes) {

tokenHolder = (currentNode + 1) % numNodes;

Simulator::Schedule(Seconds(1.0), &PassToken, tokenHolder, numNodes);

NS_LOG_UNCOND(“Token passed to Node ” << tokenHolder);

}

void TransmitData(uint32_t nodeId) {

if (nodeId == tokenHolder) {

NS_LOG_UNCOND(“Node ” << nodeId << ” is transmitting data.”);

// Add data transmission logic here

}

}

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

uint32_t numNodes = 6;

// Create nodes

NodeContainer nodes;

nodes.Create(numNodes);

// Set up Point-to-Point links for the ring

PointToPointHelper p2p;

p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));

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

NetDeviceContainer devices;

for (uint32_t i = 0; i < numNodes; ++i) {

NetDeviceContainer link = p2p.Install(nodes.Get(i), nodes.Get((i + 1) % numNodes));

devices.Add(link);

}

// Install Internet stack

InternetStackHelper stack;

stack.Install(nodes);

// Assign IP addresses

Ipv4AddressHelper address;

address.SetBase(“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign(devices);

// Set up UDP echo server

UdpEchoServerHelper echoServer(9);

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

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(10.0));

// Set up UDP echo client

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

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

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

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

ApplicationContainer clientApp = echoClient.Install(nodes.Get(3));

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(10.0));

 

// Start token circulation

Simulator::Schedule(Seconds(1.0), &PassToken, tokenHolder, numNodes);

// Enable packet capture

p2p.EnablePcapAll(“token_ring_topology”);

// Run simulation

Simulator::Run();

Simulator::Destroy();

return 0;

}

Step 8: Enhance the Simulation

  • Dynamic Token Behaviour:
    • Replicate the behaviour scenarios in which the token is lost or regenerated.
  • Analyze Performance:
    • Calculate the performance metrices throughput, delay, and packet loss.
  • Visualize:
    • Utilized their visualize approach in NetAnim we follow the token circulation and data flow.
  • Implement Fault Tolerance:
    • Replicate the bypassing the fault tolerance for failed nodes.

We comprehensively guided you to implement the Token Ring topology and made we learn about its simulation with characteristics and examples using NS3 tool. You can also consider the future enhancement features to accomplish it as per your requirements.

Be sure to include all important information regarding your Token Ring Topology projects with ns3 when you submit to phdprojects.org, and we guarantee to achieve the best outcomes for you. If you require additional details, we can offer a separate manual. Don’t hesitate to contact us regarding your simulation and project performance results.