Queuing Models in NS2

Image
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…

Passing a Structure to a Function

  1. A function can accept a structure as a parameter and even it returns a parameter too.
  2. Either the individual structure elements can be passed or the entire structure can be passed.
Here is the example, for passing the entire structure to a function
#include <stdio.h>
#include <conio.h>
//Structure declaration
struct student
{
char name[10];
int no;
};
//Function prototypes
void read(struct student);
struct student display(struct student); //function which takes the entire structure as a parameter and it returns a structure also
int main()
{
    struct student s1,s;
     printf("Enter the details");
    scanf("%s %d",s1.name,&s1.no);
    s=display(s1);  //function call
printf("Name is %s and number is %d",s.name,s.no);
    getch();
}
//Function definition
struct student display(struct student s)
{
return s;
}
Nested Structures
A structure can be declared within another structure.
Example include: for a student structure maintaining the date of birth is tougher within the structure,
to avoid the complexity, dateofbirth can be a separate structure as defined below
struct dateofbirth
{
int date;
int month;
int year;
};
struct student
{
char name[50];
int no;
struct dateofbirth dob;
};
so the structure can be accessed using the following:
s.dob.date, s.dob.month, s.dob.year, and s.name, s.no
Example of Nested Structures

#include <stdio.h>
#include <conio.h>
//declare the structure dateofbirth which holds date,month and year
struct dateofbirth
{
int date;
int month;
int year;
};
//declare another structure student which also includes dateofbirth as a datatype
struct student
{
char name[50];
int no;
struct dateofbirth dob; //from another structure
};
int main()
{
struct student s;
printf("Enter the name number and date of birth (dd/mm/yyyy)");
scanf("%s %d %d/%d/%d",s.name,&s.no,&s.dob.date,&s.dob.month,&s.dob.year);
printf("%s %d %d/%d/%d",s.name,s.no,s.dob.date,s.dob.month,s.dob.year);
getch();
return 0;
}
It is always nice to include nested structures in applications as good readability is provided
for Example: building.concrete.cement.quality

 T S Pradeep Kumar

Popular posts from this blog

AWK Scripts for NS2 to process data from Trace Files

Xgraph

ns2 installation in Ubuntu 14.04