To simulate the CGSR (Clusterhead Gateway Switch Routing) protocol is a hierarchical routing protocol for mobile ad hoc networks (MANETs). It splits the network into clusters, with each cluster having a clusterhead, which handles communication in the cluster and gateway nodes that manage the inter-cluster communication.
Inopportunely, NS3 does not natively support CGSR, however we can be replicated CGSR-such as behaviour by physically executing the clustering mechanism, describing clusterheads, and setting up routing rules in and among clusters. Below, we learn how to approach the simulation of CGSR in NS3:
Steps to Simulate CGSR-like Behavior in NS3
- Install NS3: Make certain that we have NS3 installed. We can download it from NS3’s official website.
- Define the Network Topology: Make a set of nodes which will form the mobile ad hoc network. Then we will combine these nodes into clusters, allocating the clusterheads and gateway nodes.
- Simulate Cluster Formation: Execute a mechanism to describe clusters. We can either predefine the clusters or we use a clustering algorithm to actively allocate clusterheads. Every single clusterhead will be performed as a local router, handling intra-cluster communication.
- Set up Routing: In each cluster, we describe routing rules which forward packets to the clusterhead. For inter-cluster communication, gateway nodes will be sent packets to other clusterheads.
- Implement Communication Using UDP/TCP: Utilise NS3 applications like UDP or TCP to make traffic among the nodes. We can be mimicked communication within and over the clusters to observe how packets are routed via clusterheads and gateways.
- Run the Simulation: After configuring the network and routing then we run the simulation and examine the performance of the CGSR-like behaviour.
Example Simulation of CGSR-like Behaviour in NS3
Below is a simple example of how we can replicate CGSR-like behavior in NS3 by describing the clusters and executing intra-cluster and inter-cluster communication.
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/mobility-module.h”
#include “ns3/wifi-module.h”
#include “ns3/applications-module.h”
using namespace ns3;
int main (int argc, char *argv[])
{
// Step 1: Create nodes
NodeContainer nodes;
nodes.Create (10); // Create 10 nodes for the MANET
// Step 2: Set up Wi-Fi network
WifiHelper wifi;
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
WifiMacHelper wifiMac;
wifi.SetRemoteStationManager (“ns3::AarfWifiManager”);
wifiMac.SetType (“ns3::AdhocWifiMac”);
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, nodes);
// Step 3: Set up mobility model
MobilityHelper mobility;
mobility.SetPositionAllocator (“ns3::GridPositionAllocator”,
“MinX”, DoubleValue (0.0),
“MinY”, DoubleValue (0.0),
“DeltaX”, DoubleValue (50.0),
“DeltaY”, DoubleValue (50.0),
“GridWidth”, UintegerValue (5),
“LayoutType”, StringValue (“RowFirst”));
mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);
mobility.Install (nodes);
// Step 4: Install the internet stack
InternetStackHelper internet;
internet.Install (nodes);
// Step 5: Clusterhead definition (for simplicity, we manually define clusterheads)
// Assign node 0 and node 5 as clusterheads for two clusters
Ptr<Node> clusterhead1 = nodes.Get(0);
Ptr<Node> clusterhead2 = nodes.Get(5);
// Step 6: Assign nodes to clusters (manual for simplicity)
// Cluster 1: Nodes 0, 1, 2, 3, 4
// Cluster 2: Nodes 5, 6, 7, 8, 9
// Step 7: Set up static routing to simulate intra-cluster routing
Ipv4AddressHelper ipv4;
ipv4.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer cluster1Interfaces = ipv4.Assign (devices.Get (0)); // Clusterhead 1
ipv4.SetBase (“10.1.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer cluster2Interfaces = ipv4.Assign (devices.Get (5)); // Clusterhead 2
// For intra-cluster communication, nodes send packets via clusterheads
Ipv4StaticRoutingHelper staticRouting;
Ptr<Ipv4StaticRouting> staticRoutingCluster1 = staticRouting.GetStaticRouting (nodes.Get (1)->GetObject<Ipv4> ());
staticRoutingCluster1->SetDefaultRoute (clusterhead1->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal (), 1);
Ptr<Ipv4StaticRouting> staticRoutingCluster2 = staticRouting.GetStaticRouting (nodes.Get (6)->GetObject<Ipv4> ());
staticRoutingCluster2->SetDefaultRoute (clusterhead2->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal (), 1);
// Step 8: Set up UDP communication
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (9)); // Server on a node in Cluster 2
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (cluster2Interfaces.GetAddress (1), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (1)); // Client on a node in Cluster 1
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
// Step 9: Run the simulation
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Explanation of the Code:
- Node Creation: We make 10 nodes, which signify mobile devices within the network.
- Wi-Fi Setup: Wi-Fi is utilised to mimic wireless communication in an ad hoc network. The nodes are set up to use the AdhocWifiMac to allow ad hoc networking.
- Mobility Model: A constant position mobility model is used for simplicity, placing the nodes in a grid layout.
- Clusterhead Definition: We physically describe node 0 as the clusterhead for the initial cluster and node 5 as the clusterhead for the second cluster. We can be executed a clustering algorithm for dynamic clusterhead selection.
- Routing Setup: Static routes are configure to mimic intra-cluster communication by forwarding packets to the clusterhead. Inter-cluster communication can be managed by gateway nodes, however in this basic example, clusterheads forward traffic among the clusters.
- UDP Application: A UDP Echo client-server application is configure to replicate traffic. The client node in Cluster 1 communicates with a server in Cluster 2 via the clusterheads.
- Simulation: The simulation runs for 10 seconds, in the course of which time packets are routed via the clusters, initial to the clusterheads and then among the clusters.
Performance Metrics to Analyze:
- Packet Delivery Ratio (PDR): Examine how many packets are effectively delivered to their destination.
- Routing Overhead: Observe the amount of control traffic (routing messages) exchanged among nodes to conserve the clusters.
- Latency: Estimate the end-to-end delay of packets as they travel via the network.
- Cluster Stability: If we execute the dynamic clustering then calculate the stability of clusters as nodes move and change their clusterhead associations.
Summary:
- Even though NS3 doesn’t natively support CGSR, we can replicate CGSR–like behavior by physically describing clusters, clusterheads, and routing mechanisms.
- By configuring the static routing in clusters and replicating inter-cluster communication via clusterheads, we can estimate the hierarchical structure of CGSR.
- This method permits to examine the performance of clustered networks and learn performance parameters such as packet delivery, latency, and routing overhead.
Over this explanation we understood the concepts regarding the CGSR Protocol that simulate and analyse within NS3 virtual environment utilising above given approach and sample coding. We can offer more insights relevant to this projects if you needed. To simulate the CGSR Protocol Projects using NS3, simply send us all your research details via email. We’ll respond promptly, ensuring you receive valuable insights and optimal results. Our team is here to assist you with comparative analysis for your projects.