How to Implement Network Traffic Control in NS2

To implement Network Traffic Control in NS2 has needs to handles the flow of data packets through the network to make sure effective use of resources, diminish congestion, and maintain quality of service (QoS). Traffic control usually involves approaches such as traffic shaping, rate limiting, congestion control, queue management, and priority scheduling. We handle Network Traffic Control using the NS2 tool, so feel free to reach out to us for timely results.

Here’s a step-by-step guide to implement Network Traffic Control in NS2:

Step-by-Step Guide to Implement Network Traffic Control in NS2

  1. Set Up the Basic Network Topology:
  • Initially, describe a basic network topology with source and destination nodes associated by intermediate links. This will act as the foundation for implementing traffic control mechanisms.

Example OTcl script to set up the basic network topology:

set ns [new Simulator]

set nf [open out.tr w]

$ns trace-all $nf

set namfile [open out.nam w]

$ns namtrace-all $namfile

# Create network nodes

set node0 [$ns node]   ;# Source node

set node1 [$ns node]   ;# Intermediate node

set node2 [$ns node]   ;# Destination node

# Create duplex links between the nodes

$ns duplex-link $node0 $node1 1Mb 10ms DropTail

$ns duplex-link $node1 $node2 1Mb 10ms DropTail

# Define UDP communication between node0 and node2

set udp [new Agent/UDP]

set null [new Agent/Null]

$ns attach-agent $node0 $udp

$ns attach-agent $node2 $null

$ns connect $udp $null

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set packetSize_ 512

$cbr set rate_ 1Mb

# Start traffic at 1.0 seconds and stop at 5.0 seconds

$ns at 1.0 “$cbr start”

$ns at 5.0 “$cbr stop”

# Run the simulation

$ns at 6.0 “finish”

proc finish {} {

global ns nf namfile

$ns flush-trace

close $nf

close $namfile

exec nam out.nam &

exit 0

}

$ns run

  • This setup describes a simple three-node topology (node0 -> node1 -> node2) in which UDP traffic is sent from node0 to node2 across node1.
  1. Implement Traffic Shaping (Rate Limiting):
  • Traffic shaping controls the traffic rate sent into the network by limiting the data rate on particular links or nodes. This can be performed by modifying the rate of the traffic generator (CBR in this case) or by implementing rate limiting on particular links.

Example OTcl script to limit the rate of traffic on a specific link:

# Limit the traffic rate between node0 and node1 to 500Kb/s

$ns queue-limit $node0 $node1 50    ;# Limit queue size (optional)

$ns duplex-link $node0 $node1 500Kb 10ms DropTail

  • This script minimizes the available bandwidth among node0 and node1 to 500 Kb/s that limits the rate of traffic flowing over that link.
  1. Implement Queue Management (DropTail, RED, etc.):
  • Queue management is a necessary part of traffic control, specifically for handling congestion. In NS2, we can select among different queue management mechanisms like DropTail (simple FIFO) or RED (Random Early Detection).

DropTail (FIFO) Queue:

# Use DropTail queue between node1 and node2

$ns queue-limit $node1 $node2 20  ;# Limit queue size to 20 packets (FIFO)

RED (Random Early Detection) Queue:

# Use RED queue between node1 and node2

set q [new Queue/RED]

$ns queue-limit $node1 $node2 20  ;# Limit queue size to 20 packets

$ns link $node1 $node2 queue $q

  • RED works by dropping packets probabilistically before the queue becomes full that supports to prevent congestion collapse by acquainting TCP senders to minimize their sending rate.
  1. Implement Traffic Policing (Packet Drops):
  • Traffic policing can be used to drop packets that overdo a particular rate or violate specific traffic conditions. This is useful for handling non-compliant traffic in the network.

Example OTcl script to implement traffic policing:

# Limit traffic rate and drop excess packets (policing)

set policer_rate 1Mb   ;# Set policing rate

proc police_traffic {pkt_rate} {

global policer_rate

if { $pkt_rate > $policer_rate } {

puts “Dropping packet: rate exceeded $policer_rate”

return 1   ;# Drop packet

} else {

return 0   ;# Accept packet

}

}

# Monitor traffic and apply policing at node1

$ns at 1.5 “police_traffic 2Mb”   ;# Example of policing traffic at 2Mb/s

  • This script mimics a traffic policer that drops packets when the traffic rate overdoes the permitted threshold (1Mb/s in this case).
  1. Implement Priority Scheduling (QoS):
  • Priority scheduling makes sure that higher-priority traffic is served first, minimizing latency for critical traffic. We can execute priority scheduling by describing multiple queues and allocating different traffic types to these queues.

Example OTcl script to implement priority scheduling:

# Define a high-priority queue for important traffic

set high_priority_queue [new Queue/DropTail]

$high_priority_queue setLimit_ 50   ;# Set queue limit to 50 packets

# Define a normal-priority queue for regular traffic

set normal_priority_queue [new Queue/DropTail]

$normal_priority_queue setLimit_ 100   ;# Set queue limit to 100 packets

# Assign high-priority traffic (e.g., VoIP) to high-priority queue

$ns attach-queue $node1 $high_priority_queue 1   ;# High-priority queue

# Assign regular traffic (e.g., file transfer) to normal-priority queue

$ns attach-queue $node1 $normal_priority_queue 2   ;# Normal-priority queue

  • This script configures two queues with different priorities, in which the higher-priority traffic gets served first.
  1. Implement Congestion Control (TCP):
  • Congestion control mitigates network congestion by adapting the sending rate of TCP traffic according to network feedback, like packet loss or latency. NS2 supports diverse TCP variants like TCP Tahoe, TCP Reno, and TCP Vegas, that executes congestion control.

Example OTcl script to execute congestion control using TCP:

# Set up TCP connection between node0 and node2 with congestion control

set tcp [new Agent/TCP]

set sink [new Agent/TCPSink]

$ns attach-agent $node0 $tcp

$ns attach-agent $node2 $sink

$ns connect $tcp $sink

# Start TCP traffic

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ns at 1.0 “$ftp start”

  • This sample uses TCP Reno’s congestion control algorithm that adapts the sending rate according to packet loss.
  1. Run the Simulation and Analyze Results:
  • After executing the traffic control mechanisms, execute the simulation to monitor on how they affect traffic flow, congestion, and performance.

To run the simulation:

ns your_script.tcl

  • The trace file (out.tr) will capture numerous events such as packet drops, queue lengths, and throughput that can be measured to learn the impacts of the executed traffic control mechanisms.
  1. Analyse Traffic Control Metrics:
  • Throughput: Evaluate how much data was successfully delivered.
  • Delay: Assess the time it takes for packets to travel from source to destination.
  • Packet loss: Count how many packets were dropped because of queue overflows or traffic policing.
  • Queue size: Track how the queue lengths vary over time.

Example AWK script to analyze packet loss:

awk ‘{if ($1 == “d” && $4 == “UDP”) drop_count++;}

END { print “Total dropped packets:”, drop_count }’ out.tr

  • This script counts the number of dropped UDP packets, enable them to measure the impacts of traffic control that evaluate like policing or congestion.
  1. Visualize Traffic Control in NAM:
  • Use NAM (Network Animator) to envision how traffic flows via the network and how traffic control mechanisms impacts the flow.

nam out.nam

  • NAM can demonstrate how packets are processed by diverse queues, how congestion impacts the network, and in which packets are dropped.

At the end of the simulation, we had seen the brief procedure of network traffic control and its replicating process by using ns2 tool. We will offer additional information regarding the network traffic control in upcoming manual.