How to Simulate Voice over IP Projects Using NS2

To simulate Voice over IP (VoIP) using NS2 that includes design the transmission of real-time VoIP networks utilizing protocols like RTP (Real-Time Transport Protocol), which usually runs over UDP to reduce latency. VoIP simulations also encompass making real-time traffic, which denotes voice communication among the clients, designing network conditions, and examining performance parameters like latency, packet loss, jitter, and throughput to measure the quality of the VoIP calls.

In this manual, we will replicate a VoIP call using UDP for the RTP voice stream that simulates the real-time delivery of voice packets among a sender and a receiver.

Steps to Simulate VoIP Projects Using NS2

  1. Install NS2

Make sure that we have NS2 installed on the machine. We can download NS2 from here.

  1. Understanding VoIP
  • RTP (Real-Time Transport Protocol) is the protocol generally utilized for distributing VoIP data packets over the internet.
  • UDP (User Datagram Protocol) is frequently utilized as the transport layer for RTP since it is quicker and more efficient for real-time communication, while it does not offer guaranteed delivery (no retransmissions for lost packets).
  1. TCL Script for VoIP Simulation

Here is an instance TCL script to mimic a VoIP call utilizing RTP over UDP among two nodes. The script configures two nodes to perform as the sender and receiver of the voice traffic, including real-time voice data being sent over UDP.

Example TCL Script for VoIP Simulation

# Create a simulator object

set ns [new Simulator]

# Open files for tracing and NAM visualization

set tracefile [open voip_simulation.tr w]

$ns trace-all $tracefile

set namfile [open voip_simulation.nam w]

$ns namtrace-all $namfile

# Define network topology

set topo [new Topography]

$topo load_flatgrid 500 50

# Create two nodes: one as the VoIP sender and the other as the VoIP receiver

set voip_sender [$ns node]

set voip_receiver [$ns node]

# Define link parameters: bandwidth, delay, and queue type

set bw 10Mb

set delay 10ms

set queue DropTail

# Create a duplex link between the VoIP sender and receiver

$ns duplex-link $voip_sender $voip_receiver $bw $delay $queue

# Attach a UDP agent to the VoIP sender node (to represent RTP stream for VoIP)

set udp_sender [new Agent/UDP]

$ns attach-agent $voip_sender $udp_sender

# Attach a UDP Sink agent to the VoIP receiver node

set udp_receiver [new Agent/UDP]

$ns attach-agent $voip_receiver $udp_receiver

# Connect the VoIP sender (UDP) and receiver (UDP)

$ns connect $udp_sender $udp_receiver

# Create an Application/Traffic/CBR to simulate VoIP traffic (voice packets using RTP)

set voip_traffic [new Application/Traffic/CBR]

$voip_traffic set packetSize_ 160         ;# Size of typical voice packet (160 bytes for 20ms G.711 codec)

$voip_traffic set rate_ 64Kb              ;# Voice traffic rate (64kbps for G.711)

$voip_traffic attach-agent $udp_sender    ;# Attach to UDP agent

# Start VoIP traffic at 1.0 second and stop at 6.0 seconds

$ns at 1.0 “$voip_traffic start”

$ns at 6.0 “$voip_traffic stop”

# End simulation after 10 seconds

$ns at 10.0 “finish”

# Define the finish procedure to close trace and NAM files

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam voip_simulation.nam &

exit 0

}

# Run the simulation

$ns run

  1. Explanation of the Script
  • Simulator Setup: The simulator object is made, and trace files (voip_simulation.tr) and NAM files (voip_simulation.nam) are opened to record events and envision the simulation.
  • Node Creation: Two nodes are made: one denotes the VoIP sender like the person making the call, and the other signifies the VoIP receiver such as the person receiving the call.
  • UDP Connection: A UDP agent is connected to both the sender and receiver that replicating the real-time, low-latency nature of VoIP traffic, which uses UDP to prevent delays triggered by retransmissions.
  • Traffic Generation: A CBR (Constant Bit Rate) traffic generator is utilized to replicate the real-time VoIP stream. The packet size is set to 160 bytes (representing a typical 20ms voice frame using the G.711 codec) and the data rate is set to 64 kbps (standard for G.711 VoIP).
  • Simulation End: The simulation runs for 10 seconds including VoIP traffic flowing from 1.0 second to 6.0 seconds.
  1. Running the Simulation

We can save the TCL script as voip_simulation.tcl, and then run it using NS2 with the below command:

ns voip_simulation.tcl

It will make a trace file (voip_simulation.tr) and a NAM file (voip_simulation.nam).

  1. Analyzing the Results
  • NAM Visualization: To envision the network and monitor the VoIP traffic among the sender and receiver, open the NAM (Network Animator) tool with the below command:

nam voip_simulation.nam

NAM will indicate the network topology, packet transmissions, and real-time VoIP traffic among the sender and receiver.

  • Trace File Analysis: The .tr file records the events of the simulation, like packet transmission, reception, and any packet drops. We can investigate this file using AWK or Python scripts to compute performance parameters like:
    • Throughput
    • Packet Loss
    • End-to-End Delay
    • Jitter

Example AWK Script for Calculating Throughput for VoIP Traffic:

BEGIN { received_bytes = 0; start_time = 1; end_time = 6 }

{

if ($1 == “r” && $4 == “udp”) {

received_bytes += $5

}

}

END {

duration = end_time – start_time

throughput = (received_bytes * 8) / (duration * 1000000)  # Convert to Mbps

print “VoIP Throughput: “, throughput, “Mbps”

}

We can run this AWK script using the below command:

awk -f throughput.awk voip_simulation.tr

  1. Extending the Simulation

7.1. Multiple VoIP Calls

We can replicate several VoIP calls by inserting more client-server pairs and generating traffic for each pair:

# Add more VoIP clients and servers

set voip_sender2 [$ns node]

set voip_receiver2 [$ns node]

$ns duplex-link $voip_sender2 $voip_receiver2 $bw $delay $queue

# Attach UDP agents and connect them

set udp_sender2 [new Agent/UDP]

$ns attach-agent $voip_sender2 $udp_sender2

set udp_receiver2 [new Agent/UDP]

$ns attach-agent $voip_receiver2 $udp_receiver2

$ns connect $udp_sender2 $udp_receiver2

# Create VoIP traffic for the second call

set voip_traffic2 [new Application/Traffic/CBR]

$voip_traffic2 set packetSize_ 160

$voip_traffic2 set rate_ 64Kb

$voip_traffic2 attach-agent $udp_sender2

# Start and stop the second VoIP call

$ns at 2.0 “$voip_traffic2 start”

$ns at 7.0 “$voip_traffic2 stop”

7.2. Simulating Network Congestion and Packet Loss

We can launch packet loss or network congestion to monitor how it influences the quality of the VoIP calls:

# Add packet loss to simulate network congestion or failures

$ns lossmodel [new ErrorModel/Uniform] 0.02 $voip_sender $voip_receiver

7.3. Varying Network Conditions

Change the network bandwidth, delay, or queue type to replicate diverse network conditions and monitor their effect on VoIP performance:

# Change link parameters (e.g., reduce bandwidth to 512kbps and increase delay to 50ms)

$ns duplex-link $voip_sender $voip_receiver 512Kb 50ms DropTail

We showed extensive simulation steps using NS2 to simulate and analyse the Voice over IP projects and we’re equipped to provide further insights as needed.

To simulate Voice over IP (VoIP) using NS2 tool  send all your project details to us we grant you with on time help and best outcome.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2