Вы находитесь на странице: 1из 3

Simulation of a M/M/1 queue

In this exercise, you are going to develop a ns-2 model of the simple queue. You are going to learn How to generate Poisson traffic How to write self-scheduling functions How to analyze simulation results. The pieces of code provided in this exercise cover only the new issues. You are asked to develop the whole ns-2 model. Consider a simple network composed of only two nodes (n1 and n2), and one link connecting them. The link connecting the two nodes has a speed of 100kbps, a propagation delay of 1ms, and a DropTail buffer at its input of very large size. Define UDP connection between n1 and n2. #Specify link rate in kbps set linkRate 100 $ns duplex -link $n1 $n2 {$linkRate}kb 1ms DropTail $ns queue-limit $n1 $n2 10000 We run on node n1 a Poisson source of traffic. The destination of the packets is node n2. Let be the intensity of the Poisson traffic in terms of packets/s. Take = 30 packets/s. We are going to test the systems with various values of . Write the code for exponential service time distribution (see template below) Service time depends on the packet size. Generate packets with the exponentially distributed packet size and average service rate =/ packets/s. set lambda 30.0 # generate random interarrival times and packet sizes set InterArrivalTime [new RandomVariable/Exponential] $InterArrivalTime set avg_ [expr 1/$lambda] Use as a parameter. Put the following piece of code at the beginning of the model tclscript: foreach argument $argv { scan $argument Ro=%lf Ro }

Below is the procedure that sends the packets with exponential distributed inter-packet intervals. Variable src should be defined outside the procedure as source UDP agent attached to node n1. Note: The default maximum size of UDP packets is 1 kByte. The simulated packet will be truncated to this value thus the transmission times will be shorter that we intended them to be. To avoid it change the default maximum packet size adding the following immediately after setting the source UDP agent: $src set packetSize_ 100000 proc sendpacket {} { global ns src InterArrivalTime pktSize set time [$ns now] # Schedule next packet send event $ns at [expr $time + [$InterArrivalTime value]] "sendpacket" # Send pktSize bytes set bytes [expr round ([$pktSize value])] $src send $bytes }

To initiate transmitting process you should include in your code the following line $ns at 0.0001 "sendpacket" 1. Write the code of a simulation of this scenario, and then run the simulation for 1000 seconds. Include into the code selfscheduling function timeStats (interval) that produces the following output each interval seconds of the simulation time. Simulated time: <simulation time> s, real time: <real time> s Here real computer time is time from simulation start. Hints: Real time may be obtained as follows: set rt [clock seconds] Fix real time of the simulation start: set clockStart [clock seconds] before $ns run 2. Explain (in your works) the function "sendpacket": what it does and how it works. 3. Verify the load of the queue. You get the load from the simulation by computing the total number of packets that leave the queue, then by dividing it by the total number of packets that would leave the queue if the link were busy all time.

4. Write awk program to calculate average number of packets in the system. Using gnuplot plot theoretical and simulated average number of packets in the system N (queue size + the packet in the server) for various values of and compare results. Recall that the average number of customers in the M/M/1 system is equal to:

(1 ) Use trace file out.tr to figure out N at each packet arrival and then calculate the average. At each packet arriaval (+ in the first column of the trace file) N increases by one, at each packet departure (- in the first column of the trace file) N is decreases by one 5. Write in a file N (on two columns, the first one for time, the second one for N), and plot this queue size versus time using gnuplot. 6. Work report should contain the program, awk-scripts, graphical and numerical results. Keep your work report it constitutes the first part of the report Simulation of M/M/1 queue and output analysis practicum 7. Keep the model and awk scripts for further experiments.

N=

*) Piece of code for exponential service time distribution with link rate $linkRate set ro 0.95 # Calculate the time to serve the packet. Time to serve the packet is 1/mu set mu [expr $lambda/$ro] set pktSize [new RandomVariable/Exponential] # Calculate average packet size $pktSize set avg_ [expr $linkRate/(8*$mu)]

Вам также может понравиться