Skip to main content

VLAN implementation using NS2

Queuing in NS2 | NS2 Tutorial 5

Queuing in NS2 (RED Queue and SFQ)

HARDWARE / SOFTWARE REQUIRED:

  • Network Simulator-2
  • Operating System – LINUX (UBUNTU)


THEORY:

Queue Management is defined as the algorithm that manages the length of the packet queues by dropping packets when necessary. From the point of packet dropping, Queue management can be classified into 2 types

  1. Passive Queue Management: In Passive Queue Management the packet drop occurs only when the buffer gets full. Ex: Drop Tail.
  2. Active Queue Management: Active Queue Management employs preventive packet drops. It provides an implicit feedback mechanism to notify senders of the onset of congestion. Arriving packets are randomly dropped. Ex: RED.

Drop Tail: In this packets are dropped from the tail of the queue. Once the buffer gets full, all arriving packets are discarded. Packets already in the queue are not affected.

Figure 2.1: Drop Tail mechanism

As shown in figure 2.1, the arriving packet gets dropped from the tail when the queue is filled.

Random Early Detection: RED accepts all packets until the queue reaches minth, after which it drops a packet with a linear probability distribution function. When the queue length reaches maxth all packets are dropped with probability of one.

Figure 2.2: Random Early Detection:

Weighted random early detection (WRED) 

It is a queuing discipline for a network scheduler suited for congestion avoidance. It is an extension to random early detection (RED) where a single queue may have several different sets of queue thresholds. Each threshold set is associated with a particular traffic class.

For example, a queue may have lower thresholds for lower-priority packets. A queue buildup will cause the lower-priority packets to be dropped, hence protecting the higher-priority packets in the same queue. In this way, quality of service prioritization is made possible for important packets from a pool of packets using the same buffer.

It is more likely that standard traffic will be dropped instead of higher prioritized traffic.

WRED proceeds in this order when a packet arrives:

  • Calculation of the average queue size.
  • The arriving packet is queued immediately if the average queue size is below the minimum queue threshold.
  • Depending on the packet drop probability the packet is either dropped or queued if the average queue size is between the minimum and maximum queue threshold.
  • The packet is automatically dropped if the average queue size is greater than the maximum threshold.

Adaptive RED Queue Discipline:

The motivation for Adaptive RED is the same as self-configuring RED. Self-configuring RED tries to keep the average queue size with minimum and maximum threshold values. But Sally Floyd says that why don’t keep the average queue size in a tight range just in the center of minimum and maximum threshold values. Also, Adaptive RED removes the kns and automatically sets them. Maximum drop probability is adapted based on the network availability, it is no longer a knob just like previous versions of RED. 

Main contributions to Adaptive RED

  • Automatic setting of minimum threshold (minth). It is set as a function of the link capacity (C) and target queue delay.
  • Automatic setting of maximum threshold (maxth). It is set depending on the value of minth.
  • Automatic setting of wq. It is set as a function of the link capacity (C).
  • The adaptive setting of maxp. It is adapted according to the current average queue length.

ALGORITHM:
1. Create a simulator object

2. Define different colors for different data flows

3. Open a nam and trace file (output files)

4. Create 8 nodes that form a network numbered from 0 to 7 for the RED queue mechanism and 6       nodes that form a network numbered from 0 to 5 for the Drop tail mechanism.

5. Create duplex links between the nodes with a bandwidth of 100 Mbps.

6. Create duplex links between n3 and n4 with a bandwidth of 2Mbps for the RED queue mechanism and create duplex links between n2 and n3 with a bandwidth of 1Mbps for the Drop tail.

7. Set up TCP Connection between n0 and n5 and also set up UDP connection between n1 and n4        in case of Drop tail. In the case of the RED queue mechanism, set the TCP connection between n0 and n5 , the TCP connection between n2 and n7, and also set up the UDP connection between n1 and n6

8. Apply CBR Traffic over UDP, and FTP Traffic over TCP.

9. Define the finish procedure then close the trace file, and execute the nam file.

10. Schedule events and run the program

PROGRAM:
(a) RED queue mechanism.


#===================================

#     Simulation parameters setup

#===================================

set val(stop)   10.0                         ;# time of simulation end

#===================================

#        Initialization        

#===================================

#Create a ns simulator

set ns [new Simulator]

#Open the NS trace file

set tracefile [open queue_red.tr w]

$ns trace-all $tracefile

#Open the NAM trace file

set namfile [open queue_red.nam w]

$ns namtrace-all $namfile

#===================================

#        Nodes Definition        

#===================================

#Create 7 nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]

set n6 [$ns node]

#===================================

#        Links Definition        

#===================================

# Create links between nodes

$ns duplex-link $n0 $n3 100.0Mb 10ms RED

$ns queue-limit $n0 $n3 50

$ns duplex-link $n4 $n1 100.0Mb 10ms RED

$ns queue-limit $n4 $n1 50

$ns duplex-link $n6 $n5 100.0Mb 10ms RED

$ns queue-limit $n6 $n5 50

$ns duplex-link $n4 $n6 100.0Mb 10ms RED

$ns queue-limit $n4 $n6 50

$ns duplex-link $n5 $n2 100.0Mb 10ms RED

$ns queue-limit $n5 $n2 50

$ns duplex-link $n0 $n2 100.0Mb 10ms RED

$ns queue-limit $n0 $n2 50

$ns duplex-link $n2 $n1 100.0Mb 10ms RED

$ns queue-limit $n2 $n1 50

$ns duplex-link $n1 $n5 100.0Mb 10ms RED

$ns queue-limit $n1 $n5 50

$ns duplex-link $n3 $n4 100.0Mb 10ms RED

$ns queue-limit $n3 $n4 50

$ns duplex-link $n3 $n1 100.0Mb 10ms RED

$ns queue-limit $n3 $n1 50

#Give node position (for NAM)

$ns duplex-link-op $n0 $n3 orient right-up

$ns duplex-link-op $n4 $n1 orient left-down

$ns duplex-link-op $n6 $n5 orient left-down

$ns duplex-link-op $n4 $n6 orient right-down

$ns duplex-link-op $n5 $n2 orient left

$ns duplex-link-op $n0 $n2 orient right-down

$ns duplex-link-op $n2 $n1 orient right-up

$ns duplex-link-op $n1 $n5 orient right-down

$ns duplex-link-op $n3 $n4 orient right

$ns duplex-link-op $n3 $n1 orient right-down

#===================================

#        Agents Definition        

#===================================

#Setup a TCP connection

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set sink2 [new Agent/TCPSink]

$ns attach-agent $n4 $sink2

$ns connect $tcp0 $sink2

$tcp0 set packetSize_ 1500

#Setup a TCP/FullTcp/Tahoe connection

set tcp1 [new Agent/TCP]

$ns attach-agent $n2 $tcp1

set sink3 [new Agent/TCPSink]

$ns attach-agent $n6 $sink3

$ns connect $tcp1 $sink3

$tcp1 set packetSize_ 1500

#===================================

#        Applications Definition        

#===================================

#Setup a FTP Application over TCP connection

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ns at 1.0 "$ftp0 start"

$ns at 10.0 "$ftp0 stop"

#Setup a FTP Application over TCP/FullTcp/Tahoe connection

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ns at 1.0 "$ftp1 start"

$ns at 10.0 "$ftp1 stop"

#===================================

#        Termination        

#===================================

#Define a 'finish' procedure

proc finish {} {

    global ns tracefile namfile

    $ns flush-trace

    close $tracefile

    close $namfile

    exec nam queue_red.nam &

    exit 0

}

$ns at $val(stop) "$ns nam-end-wireless $val(stop)"

$ns at $val(stop) "finish"

$ns at $val(stop) "puts \"done\" ; $ns halt"

$ns run

OUTPUT

Queue

RED Queue in ns2

SF queue mechanism

#===================================

# This script is created by NSG2 beta1

# <http://wushoupong.googlepages.com/nsg>

#===================================

#     Simulation parameters setup

#===================================

setval(stop)   10.5                         ;# time of simulation end

#===================================

#        Initialization        

#===================================

#Create a ns simulator

set ns [new Simulator]

#Open the NS trace file

set tracefile [open sfq.tr w]

$ns trace-all $tracefile

#Open the NAM trace file

set namfile [open sfq.nam w]

$ns namtrace-all $namfile

#===================================

#        Nodes Definition        

#===================================

#Create 6 nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]

#===================================

#        Links Definition        

#===================================

#Createlinks between nodes

$ns duplex-link $n0 $n2 100.0Mb 10ms SFQ

$ns queue-limit $n0 $n2 50

$ns duplex-link $n3 $n2 100.0Mb 10ms SFQ

$ns queue-limit $n3 $n2 50

$ns duplex-link $n1 $n2 100.0Mb 10ms SFQ

$ns queue-limit $n1 $n2 50

$ns duplex-link $n3 $n4 100.0Mb 10ms SFQ

$ns queue-limit $n3 $n4 50

$ns duplex-link $n3 $n5 100.0Mb 10ms SFQ

$ns queue-limit $n3 $n5 50

#Give node position (for NAM)

$ns duplex-link-op $n0 $n2 orient right-down

$ns duplex-link-op $n3 $n2 orient left

$ns duplex-link-op $n1 $n2 orient right-up

$ns duplex-link-op $n3 $n4 orient right-up

$ns duplex-link-op $n3 $n5 orient right-down

#===================================

#        Agents Definition        

#===================================

#Setup a TCP connection

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set sink3 [new Agent/TCPSink]

$ns attach-agent $n5 $sink3

$ns connect $tcp0 $sink3

$tcp0 set packetSize_ 1500

#Setup a TCP connection

set tcp1 [new Agent/TCP]

$ns attach-agent $n4 $tcp1

set sink2 [new Agent/TCPSink]

$ns attach-agent $n1 $sink2

$ns connect $tcp1 $sink2

$tcp1 set packetSize_ 1500

#===================================

#        Applications Definition        

#===================================

#Setup an FTP Application over a TCP connection

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ns at 1.0 "$ftp0 start"

$ns at 10.0 "$ftp0 stop"

#Setup an FTP Application over a TCP connection

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ns at 1.0 "$ftp1 start"

$ns at 10.0 "$ftp1 stop"

#===================================

#        Termination        

#===================================

#Define a 'finish' procedure

proc finish {} {

global ns tracefilenamfile

    $ns flush-trace

close $tracefile

close $namfile

exec nam sfq.nam &

exit 0

}

$ns at $val(stop) "$ns nam-end-wireless $val(stop)"

$ns at $val(stop) "finish"

$ns at $val(stop) "puts \"done\" ; $ns halt"

$ns run

NAM OUTPUT

nam

AWK OUTPUT

Nam and AWK output files


Comments

Popular posts from this blog

Installing ns3 in Ubuntu 22.04 | Complete Instructions

In this post, we are going to see how to install ns-3.36.1 in Ubuntu 22.04. You can follow the video for complete details Tools used in this simulation: NS3 version ns-3.36.1  OS Used: Ubuntu 22.04 LTS Installation of NS3 (ns-3.36.1) There are some changes in the ns3 installation procedure and the dependencies. So open a terminal and issue the following commands Step 1:  Prerequisites $ sudo apt update In the following packages, all the required dependencies are taken care and you can install all these packages for the complete use of ns3. $ sudo apt install g++ python3 python3-dev pkg-config sqlite3 cmake python3-setuptools git qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar gsl-bin libgsl-dev libgslcblas0 wireshark tcpdump sqlite sqlite3 libsqlite3-dev  libxml2 libxml2-dev libc6-dev libc6-dev-i386 libclang-dev llvm-

Installation of NS2 in Ubuntu 22.04 | NS2 Tutorial 2

NS-2.35 installation in Ubuntu 22.04 This post shows how to install ns-2.35 in Ubuntu 22.04 Operating System Since ns-2.35 is too old, it needs the following packages gcc-4.8 g++-4.8 gawk and some more libraries Follow the video for more instructions So, here are the steps to install this software: To download and extract the ns2 software Download the software from the following link http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz/download Extract it to home folder and in my case its /home/pradeepkumar (I recommend to install it under your home folder) $ tar zxvf ns-allinone-2.35.tar.gz or Right click over the file and click extract here and select the home folder. $ sudo apt update $ sudo apt install build-essential autoconf automake libxmu-dev gawk To install gcc-4.8 and g++-4.8 $ sudo gedit /etc/apt/sources.list make an entry in the above file deb http://in.archive.ubuntu.com/ubuntu/ bionic main universe $ sudo apt update Since, it&#

Installation of NS2 (ns-2.35) in Ubuntu 20.04

Installation of NS2 (ns-2.35) in Ubuntu 20.04 LTS Step 1: Install the basic libraries like      $] sudo apt install build-essential autoconf automake libxmu-dev Step 2: install gcc-4.8 and g++-4.8 open the file using sudo mode $] sudo nano /etc/apt/sources.list Include the following line deb http://in.archive.ubuntu.com/ubuntu bionic main universe $] sudo apt update $] sudo apt install gcc-4.8 g++-4.8 Step 3:  Unzip the ns2 packages to home folder $] tar zxvf ns-allinone-2.35.tar.gz $] cd ns-allinone-2.35/ns-2.35 Modify the following make files. ~ns-2.35/Makefile.in Change @CC@ to gcc-4.8 change @CXX@ to g++-4.8 ~nam-1.15/Makefile.in ~xgraph-12.2/Makefile.in ~otcl-1.14/Makefile.in Change in all places  @CC@ to gcc-4.8 @CPP@ or @CXX@ to g++-4.8 open the file: ~ns-2.35/linkstate/ls.h Change at the Line no 137  void eraseAll() { erase(baseMap::begin(), baseMap::end()); } to This void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); } All changes made Step 4: Open a new termi