How to Simulate CGSR Protocol Projects Using NS2

To simulate Clusterhead Gateway Switch Routing (CGSR) using NS2, which is a hierarchical routing protocol utilized in mobile ad-hoc networks (MANETs). In CGSR protocol, nodes are systematised into clusters with one node performing as the clusterhead that coordinates routing in and among the clusters. The network simulator NS2 does not directly support CGSR, thus we require to execute it manually or implement a patch if obtainable.

Here’s a step-by-step instructions to replicate CGSR protocol projects using NS2:

Steps to Simulate CGSR Protocol Projects in NS2

  1. Install NS2

Make sure that NS2 is installed on the machine. Download it from the NS2 official page and follow the installation guidelines.

  1. Implement CGSR in NS2

Since CGSR is not obtainable by default, we can replicate CGSR by manually setting up hierarchical routing in which nodes are grouped into clusters and communicate through a clusterhead.

Option 1: Apply a CGSR Patch (If available)

If we discover a CGSR patch for NS2 then we follow these steps to implement it:

  1. Download the CGSR patch.
  2. Implement the patch:

cd ns-allinone-2.35/ns-2.35

patch -p1 < cgsr-patch.diff

  1. Rebuild NS2:

./configure

make clean

make

  1. Define a Cluster-Based Network Topology

In CGSR, nodes are grouped into clusters, and each cluster has a clusterhead. We can describe clusters and replicate communication among the nodes via their corresponding clusterheads.

Example TCL Script to Define a Network with Clusters:

# Create a new simulator instance

set ns [new Simulator]

# Define trace and nam files for logging and visualization

set tracefile [open cgsr_simulation.tr w]

$ns trace-all $tracefile

set namfile [open cgsr_simulation.nam w]

$ns namtrace-all $namfile

# Create nodes (representing mobile devices or routers in a network)

set n0 [$ns node]  ;# Node in Cluster 1

set n1 [$ns node]  ;# Node in Cluster 1

set n2 [$ns node]  ;# Clusterhead of Cluster 1

set n3 [$ns node]  ;# Node in Cluster 2

set n4 [$ns node]  ;# Clusterhead of Cluster 2

set n5 [$ns node]  ;# Gateway between clusters

# Define duplex links within clusters (Cluster 1 and Cluster 2)

$ns duplex-link $n0 $n1 1Mb 10ms DropTail   ;# Intra-cluster link (Cluster 1)

$ns duplex-link $n2 $n0 1Mb 10ms DropTail   ;# Link to clusterhead (Cluster 1)

$ns duplex-link $n3 $n4 1Mb 10ms DropTail   ;# Intra-cluster link (Cluster 2)

$ns duplex-link $n4 $n5 1Mb 20ms DropTail   ;# Link to gateway

# Define inter-cluster link through the gateway

$ns duplex-link $n2 $n5 512Kb 50ms DropTail   ;# Link from Clusterhead 1 to gateway

In this setup:

  • n0 and n1 are in Cluster 1 and communicate via Clusterhead n2.
  • n3 and n4 are in Cluster 2, with n4 performing as the clusterhead.
  • n5 is the gateway node, which permits communication among clusters.
  1. Set Up Cluster-Based Routing (Simulating CGSR)

To mimic CGSR, we can set up routing so as to traffic among clusters is routed through the clusterheads and gateway node.

Example of Manual Routing Through Clusterheads:

# Enable hierarchical routing

$ns rtproto Static

# Define routing paths (cluster-based routing)

$n0 add-route $n3 via $n2  ;# Route from n0 (Cluster 1) to n3 (Cluster 2) via Clusterhead n2

$n2 add-route $n3 via $n5  ;# Route from Clusterhead n2 to n3 via the gateway

$n5 add-route $n4 via $n4  ;# Gateway routes traffic to Clusterhead n4

  1. Set Up Traffic Between Nodes

Describe traffic among the nodes to check how the CGSR-like routing executes. We can replicate TCP or UDP traffic among nodes in diverse clusters.

Example for TCP Traffic:

# Set up TCP traffic between node 0 (Cluster 1) and node 3 (Cluster 2)

set tcp0 [new Agent/TCP]

set sink0 [new Agent/TCPSink]

$ns attach-agent $n0 $tcp0

$ns attach-agent $n3 $sink0

$ns connect $tcp0 $sink0

# Create FTP application over TCP

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ns at 2.0 “$ftp0 start”

$ns at 10.0 “$ftp0 stop”

Example for UDP Traffic:

# Set up UDP communication between node 1 (Cluster 1) and node 4 (Cluster 2)

set udp0 [new Agent/UDP]

set null0 [new Agent/Null]

$ns attach-agent $n1 $udp0

$ns attach-agent $n4 $null0

$ns connect $udp0 $null0

# Generate CBR traffic over UDP

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set rate_ 100kb

$cbr0 attach-agent $udp0

$ns at 2.5 “$cbr0 start”

$ns at 9.5 “$cbr0 stop”

  1. Run the Simulation

After describing the network and traffic then we save the TCL script (e.g., cgsr_simulation.tcl) and the execute it using NS2:

ns cgsr_simulation.tcl

It will make trace files (.tr) and NAM files (.nam), which we can investigate and envision utilizing Network Animator (NAM).

  1. Analyze Simulation Results

We can investigate the outcomes of the CGSR simulation by look over the trace files. Significant parameters to estimate that contain:

  • Packet Delivery Ratio (PDR): The percentage of packets effectively delivered.
  • End-to-End Delay: The time it takes for packets to travel from the origin to the destination.
  • Routing Overhead: The extra control packets made by clusterheads.

Example AWK Script for Packet Delivery Ratio:

BEGIN { sent = 0; received = 0; }

{

if ($1 == “s” && $4 == “AGT”) { sent++; }

if ($1 == “r” && $4 == “AGT”) { received++; }

}

END { print “Packet Delivery Ratio = “, received/sent*100, “%”; }

  1. Example Project Ideas for CGSR Simulation
  1. Performance Evaluation of CGSR in High Mobility Scenarios:
    • Replicate CGSR within a mobile ad-hoc network including high node mobility and examine how the protocol manages cluster maintenance and communication efficiency.
  2. Clusterhead Selection and Routing Overhead:
    • Execute distinct clusterhead selection mechanisms in CGSR and estimate their effect on routing overhead and energy efficiency.
  3. CGSR in Vehicular Ad-Hoc Networks (VANETs):
    • Mimic CGSR in a VANET scenario and investigate how the protocol executes such as packet delivery ratio and latency within highly dynamic environments.
  4. Comparison of CGSR with Other Routing Protocols:
    • Replicate CGSR and compare it with other routing protocols such as AODV and DSR that concentrating on parameters like packet delivery, routing overhead, and scalability.

Utilizing the network simulator NS2, we performed a comprehensive CGSR Protocol projects analysis through simulation steps and we are capable of extending it further if additional details are needed.

Get guidance on CGSR protocol from phdprime.com. We also provide step-by-step instructions to replicate CGSR protocol projects using NS2 tailored to your requirements.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2