You are on page 1of 8

INDEX

S.No Name of the practical Page no. Signature

1.

a b. c. d. e. f g h i j k

Programming inMATLAB:Introduction ,Branching statements, loops, functions, additional data types, plots, arrays. WAP for multiplication of 2 matrices WAP to find the area of circle if r=1/3-1 WAP for addition of 2 matrices Evaluate sin(/6)+cos(/3). Evaluate e3 and e. WAP to plot a circle WAP to plot a cycloid Plot a simple sine cusine y=sin(x),0x2 taking 100 linearly spaced points. Use the relational operators in MATLAB Plot a 3D circular Helix Write a script file or function file for Y={15(4x) +10, for x9 10x+10 ,for 0x<9, 10 ,for x<0} Practical implementation of single server queue simulation in C++. Introduction to Network Simulators

2-19

20 21 21 22 22 23 23 24 25 26 27

2 3.

2.Single Server Queue Simulation in C++


#include "stdafx.h" #include<iostream> using namespace std; int main() { //////////// initilization variables ////////////////// int n=0,n1=0; // no. of jobs int maxLength=0; // max length queue. float t=0 ; //clock or time float eventTime=0,totalTime=0,totalBusytime=0,totalArea=0; char eventType; //event type : Arraival or Departure float X=0,U=0,R=0,N=0; // Performence mesures int nCompletion=0; // how many jobs are completed or departure . int nRejection=0 ; // how many jobs or custemers are rejected . int nArrival=0; float PreEventTime=0; float ratioRtoA=0; // Ratio between rejected job & arrival jobs. int Eventlist=0; int i=0; // counter ////////////Input & Processing Stage //////////////////// cout<<"Enter the Total Time or Stop Simulation Time : \n"; cin>>totalTime; cout<<"Enter the No. of Event list : \n"; cin>>Eventlist; cout<<"Enter the No. of jobs or custemers : \n"; cin>>n1; cout<<"Enter the maximume no. of custemers : \n"; cin>>maxLength; while(i<Eventlist) // while the event list is not empty { cout<<"Enter the event type A for 'Arraival' or D 'for 'Departure' \n"; cin>>eventType; cout<<"Enter the event time \n"; cin>>eventTime; PreEventTime=t; // time advanced algorithm t=eventTime; if(n>0) // server status is busy { totalBusytime=totalBusytime+(t-PreEventTime); totalArea=totalArea+(t-PreEventTime)*n ; cout<<"busy time "<<totalBusytime<<" Area="<<totalArea<<endl; } else { cout<< " the server is Idle \n"; } if(eventType=='A' || eventType=='a'){ if(n<maxLength) { n++; nArrival++; }

else { cout<<"Alert ! the job is rejected \n"; nRejection++ ; } } else if(eventType=='D' || eventType=='d'){ n--; nCompletion++; cout<<"No. of completion=" <<nCompletion<<endl; } else { cout<<"Please Re Enter Event Time (A or D ) \n " ;} i++; //loop end } ///////////////////// RESULTS ////////////////////////////// X=nCompletion/totalTime; // throughput N=totalArea/totalTime; // average length queue R=N/X; // response time U=totalBusytime/totalTime; // utilization ratioRtoA=(nRejection/nArrival)*100 ; cout<<"TotalBusytime = " <<totalBusytime<<endl; cout<<"Throughput = " <<X<<endl; cout<<"Average length queue = "<<N<<endl; cout<<"Response Time = " <<R<<endl; cout<<"Utilization = " <<U<<endl; cout<<"Ratio between Rejection jobs and Arrival % = " <<ratioRtoA<<endl; cout<<"Total time = "<<totalTime<<endl; cout<<"t="<<t<<endl; cout<<"Total Area="<<totalArea<<endl; system("PAUSE"); return 0;
}

3. Introduction to Network Simulators


The network simulator is discrete event packet level simulator. The network simulator covers a very large number of applications of different kind of protocols of different network types consisting of different network elements and traffic models. Network simulator is a package of tools that simulates behaviour of networks such as creating network topologies, log events that happen under any load, analyze the events and understand the network. Platform required running network simulator

Windows 95/98/NT/2000/XP Backend Environment of Network Simulator Network Simulator is mainly based on two languages .They are C++ and OTcl. OTcl is the object oriented version of Tool Command language .The network simulator is a bank of of different network and protocol objects. C++ helps in the following way:

processing time. Otcl helps in the following way:

helps us t

Basics of Tcl Programming with respect to ns2 Before we get into the program we should consider the following things:

Initialization To start a new simulator we write Set ns [new Simulator] From the above command we get that a variable ns is being initialized by using the set command. Here the code [new Simulator] is a instantiation of the class Simulator which uses the reserved word 'new'. So we can call all the methods present inside the class simulator by using the variable ns. Creating the output files #To create the trace files we write set tracefile1 [open out.tr w] $ns trace-all $tracefile1 #To create the nam files we write set namfile1 [open out.nam w] $ns namtrace-all $namfile In the above we create a output trace file out.tr and a nam visualization file out.nam. But in the Tcl script they are not called by their names declared ,while they are called by the pointers initialized for them such as tracefile1 and namfile1 respectively .The line which starts with '#' are commented .The next line opens the file 'out.tr' which is used for writing is declared 'w'. The next line uses a simulator method trace-all by which we will trace all the events in a particular format. The termination program is done by using a 'finish' procedure # Defining the 'finish' procedure' proc finish {} { global ns tracefile1 namfile1 $ns flush-trace close $tracefile close $namfile exec namout.nam& exit 0 } In the above the word 'proc' is used to declare a procedure called 'finish'. The word 'global' is used to tell what variables are being used outside the procedure.

flush-trace' is a simulator method that dumps the traces on the respective files. The command 'close' is used to close the trace files and the command 'exec' is used to execute the name visualization. The command 'exit' closes the application and returns 0 as zero(0) is default for clean exit. In ns we end the program by calling the 'finish' procedure #end the program $ns at 125.0 "finish" Thus the entire operation ends at 125 seconds. To begin the simulation we will use the command #start the the simulation process $ns run Defining nodes Way to create a node: view source print? 1 set n0 [ns node] In the above we created a node that is pointed by a variable n0.While referring the node in the script we use $n0. NETWORK ANIMATOR (NAM) Nam is a Tcl/TK based animation tool for viewing network simulation traces and real world packet traces. It supports topology layout, packet level animation, and various data inspection tools. Simulation results Two main types of simulation results NAM files A text file for the nam software The visual output of simulation Is useful for demonstration Trace files A text file with specific format The raw data of simulation and event record Nam: Network animator Packet level animation NS records all needed info for nam $ns namtrace-all $namFilenam reads the file and visualizes it namnamfile.nam

Trace objects For each single packet writes to trace file: Time of arrival, sending, dropping For links or queues Tracing of all links to one file is easy: $ns trace-all $tf Not for bigger simulations! Different trace objects Trace/Enque: packet arrival (at a queue) Trace/Deque packet departure (at a queue) Trace/Drop packet drop (packet delivered to drop-target) Trace/Recv packet receive event at the destination node of a link $ns createtrace {type file srcdst} Example trace file - 0.84824 2 3 tcp 1040 ------- 0 0.0 3.0 29 46 r 0.85408 2 3 tcp 1040 ------- 0 0.0 3.0 28 44 + 0.85656 2 3 tcp 1040 ------0 0.0 3.0 30 47 - 0.85656 2 3 tcp 1040 ------- 0 0.0 3.0 30 47 r 0.8624 2 3 tcp 1040 ------- 0 0.0 3.0 29 46 + 0.86488 2 3 tcp 1040 ------- 0 0.0 3.0 31 49 0.86488 2 3 tcp 1040 ------- 0 0.0 3.0 31 49 r 0.87072 2 3 tcp 1040 ------- 0 0.0 3.0 30 47 + 0.8732 2 3 tcp 1040 ------- 0 0.0 3.0 32 50 - 0.8732 2 3 tcp 1040 ------ 0 0.0 3.0 32 50 r 0.87904 2 3 tcp 1040 ------- 0 0.0 3.0 31 49 + 0.88152 2 3 tcp 1040 ------- 0 0.0 3.0 33 52 - 0.88152 2 3 tcp 1040 ------- 0 0.0 3.0 33 52 r 0.88736 2 3 tcp 1040 ------- 0 0.0 3.0 32 50 + 0.88984 2 3 tcp 1040 ------- 0 0.0 3.0 34 53

You might also like