To implement the Dual Ring topology in ns3, we want to generate the two interconnected ring networks while the each node is a part of both rings. This is usually used for redundancy and fault tolerance.
Here is the detailed guide on how to achieve this in ns3:
Step-by-Step Implementation
Step 1: Install ns3
- Make sure ns3 is installed in your computer.
Step 2: Create a New Simulation Script
- Create a new C++ script for your simulation.
Step 3: Include Necessary Headers
- In your script, include the necessary ns-3 headers:
#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”
#include “ns3/mobility-module.h”
Step 4: Set Up the Dual Ring Topology
We provide the reference to configure and setup the Dual Ring topology with four nodes:
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“DualRingTopology”);
int main (int argc, char *argv[])
{
// Configure command line parameters
CommandLine cmd;
cmd.Parse (argc, argv);
// Create nodes
NodeContainer nodes;
nodes.Create (4); // Create 4 nodes for the Dual Ring network
// Create point-to-point links to form two rings
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“1Gbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer devices1, devices2;
Ipv4AddressHelper address1, address2;
Ipv4InterfaceContainer interfaces1, interfaces2;
// First ring
for (uint32_t i = 0; i < nodes.GetN (); ++i)
{
NodeContainer pair (nodes.Get (i), nodes.Get ((i + 1) % nodes.GetN ()));
NetDeviceContainer devicePair = pointToPoint.Install (pair);
devices1.Add (devicePair);
std::ostringstream subnet;
subnet << “10.1.” << i << “.0”;
address1.SetBase (subnet.str ().c_str (), “255.255.255.0”);
interfaces1.Add (address1.Assign (devicePair));
}
// Second ring (in reverse order)
for (uint32_t i = 0; i < nodes.GetN (); ++i)
{
NodeContainer pair (nodes.Get (i), nodes.Get ((i + nodes.GetN () – 1) % nodes.GetN ()));
NetDeviceContainer devicePair = pointToPoint.Install (pair);
devices2.Add (devicePair);
std::ostringstream subnet;
subnet << “10.2.” << i << “.0”;
address2.SetBase (subnet.str ().c_str (), “255.255.255.0”);
interfaces2.Add (address2.Assign (devicePair));
}
// Install the internet stack
InternetStackHelper stack;
stack.Install (nodes);
// Set up mobility model (optional)
MobilityHelper mobility;
mobility.SetPositionAllocator (“ns3::GridPositionAllocator”,
“MinX”, DoubleValue (0.0),
“MinY”, DoubleValue (0.0),
“DeltaX”, DoubleValue (50.0),
“DeltaY”, DoubleValue (50.0),
“GridWidth”, UintegerValue (2),
“LayoutType”, StringValue (“RowFirst”));
mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);
mobility.Install (nodes);
// Set up applications (e.g., UDP echo server and client)
uint16_t port = 9; // Port number for applications
// Install UDP Echo Server on node 0
UdpEchoServerHelper echoServer (port);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
// Install UDP Echo Client on node 3 to communicate with node 0
UdpEchoClientHelper echoClient (interfaces1.GetAddress (0), port);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (3));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
// Run simulation
Simulator::Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Step 5: Build and Run the Simulation
- Save the script as dual-ring-topology.cc.
- Build the script using waf:
./waf configure –enable-examples
./waf build
Run the simulation:
./waf –run scratch/dual-ring-topology
Explanation of the Script
- Node Creation: Creates four nodes for the Dual Ring network.
- Point-to-Point Links: Configures point-to-point links to form two rings. The first ring connects nodes in a circular manner, while the second ring connects nodes in reverse order.
- Internet Stack: Installs the internet stack on all nodes.
- IP Addressing: Assigns IP addresses to both rings using different subnets.
- Mobility Model: (Optional) Sets the position of nodes in a grid layout using GridPositionAllocator and ConstantPositionMobilityModel.
- Applications: Sets up a UDP echo server on node 0 and a UDP echo client on node 3 to demonstrate communication between nodes.
So here we discussed and provide all kinds of information about the Dual Ring Topology in ns3 framework and additionally
We support any kinds of project implementation that relates Dual Ring Topology, drop with us the parameters for further exploration.