Queuing Models in NS2

M/M/1 is a system with poisson arrival time, servicing exponentially and a queue of unlimited capacity and type of FIFO Queue. This is the simplest queuing system.  NS2 supports various distributions like pareto, exponential, constant, unifrom, etc to handle the network dynamics and metrics. So it is very easy to test the given network link to monitor a given queue using any of these queuing models. The listing 3 and 4 are monitoring the link when DropTail queue is used with a capacity of finite and infinite. Listing 13.3 uses infinite capacity and Listing 13.4 uses Finite capacity The output screen shot is shown below the scripts for further understanding
Listing 3 – M/M/1 Queuing Model #new Simulator creation set ns [new Simulator] #trace file creation for capturing the UDP data set tf [open out.tr w] $ns trace-all $tf
#setting the exponential distribution param set lambda 30.0 set mu     33.0
#creation of nodes set n1 [$ns node] set n2 [$ns node] #The queue limit is 1Lakh as the capacity is infin…

IO Functions - printf and scanf

Printf() is a function to print strings to the display unit and
scanf() is to scan the input through the keyboard
the f in the printf and scanf are called as format. That is, printf() and scanf() will print and scan in some particular format, it is the duty of the developer to provide that formats.
For example
printf(“a=%d, b=%d”, a,b); //This function will print a=10, b=20 if the values of a and b are 10 and 20
scanf(“%f”, &a); //this will accept a float number as the specifier is %f which is for float, See the Ampersand symbol which to tell the compiler to store the variable into the address.
Here is the list of format codes or format specifiers
scanf() format codes
Code Meaning
%c read a single character
%d read a decimal integer
%f read a floating point value
%e read a floating point value (even in exponential format)
%g read a floating point value
%h read a decimal, heaxadecimal or octal integer
%o read an octal integer
%s read a string
%u read an unsigned integer
%x read a hexadecimal integer
h for short integers like %hd
l for long integers like "%ld
L for long double like %Lf
printf() format codes
Code Meaning
%c prints a single character
%d print a decimal integer
%e print a floating point value in exponential form
%f print a float point value
%g print a float point value either in f type or e type depending on the value
%i print a signed decimal integer
%o prints an octal integer
%s prints a string
%u print an unsigned integer
%x print a hexadecimal number

Backslash Character constants or Escape Characters
There are some characters inside the double quotes for printf() and scanf() which are escaped by the compiler and hence it will the next character after the escape characters
Character What it will do
\n go to the new line
\t horizontal tab
\a alert bell
\f form feed
\r carriage return
\” will print “
\’ will print ‘
\? will print ?
\\ will print \
\v vertical tab
\b backspace

 T S Pradeep Kumar

Popular posts from this blog

AWK Scripts for NS2 to process data from Trace Files


ns2 installation in Ubuntu 14.04