You are on page 1of 6

Network Performance Metrics

(elicitation from trace using AWK)


In this exercise you will learn how to measure performance metrics. AWK is used to parse the traffic trace file and to measure packet loss rate, jitter, end-to-end delay You will practice your ns-2 skills learn to parse the output trace files in ns-2 practice in writing AWK scripts for metrics calculations .

1. Simulation Topology
node ftp traffic trace tcp sink s1 2Mbps, 10ms 1.7Mbps, 20ms r s2 udp cbr 2Mbps, 10ms null d link agent

cbr ftp sec 0.1 1.0 4.0 4.5

2. TCL script (hint: use code from example2.tcl as a template) #Create a simulator object set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red

#Open the NAM trace file set nf [open out.nam w] $ns namtrace-all $nf #Open the traffic trace file to record all events set nd [open out.tr w] $ns trace-all $nd

#Define a 'finish' procedure proc finish {} { global ns nf nd $ns flush-trace #Close the NAM trace file and trace-all file close $nf close $nd #Execute NAM on the trace file exec nam out.nam & exit 0 } #Create four nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] #Create links between the nodes $ns duplex-link $n0 $n2 2Mb 10ms DropTail $ns duplex-link $n1 $n2 2Mb 10ms DropTail $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail #Set Queue Size of link (n2-n3) to 10 $ns queue-limit $n2 $n3 10 #Give node position (for NAM) $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $n2 $n3 orient right #Monitor the queue for link (n2-n3). (for NAM) $ns duplex-link-op $n2 $n3 queuePos 0.5 #Setup a TCP connection set tcp [new Agent/TCP] $tcp set class_ 2

$ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n3 $sink $ns connect $tcp $sink $tcp set fid_ 1 #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP #Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n1 $udp set null [new Agent/Null] $ns attach-agent $n3 $null $ns connect $udp $null $udp set fid_ 2 #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR $cbr set packet_size_ 1000 $cbr set rate_ 1mb $cbr set random_ false #Schedule events for the CBR and FTP agents $ns at 0.1 "$cbr start" $ns at 1.0 "$ftp start" $ns at 4.0 "$ftp stop" $ns at 4.5 "$cbr stop" #Detach tcp and sink agents (not really necessary) $ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Print CBR packet size and interval puts "CBR packet size = [$cbr set packet_size_]" puts "CBR interval = [$cbr set interval_]" #Run the simulation $ns run

This is what you can see

Monitor

ACK

Dropped packet

3. Parsing the traffic trace file After simulation, you will get a traffic trace file out.tr. Use AWK to parse the out.tr file to get packet loss rate, jitter, and end-to-end delay 3.1. Packet Loss Rate Write the awk program for calculating the packet loss rate for CBR traffic File measure-loss.awk #This program is used to calculate the packet loss rate for CBR program BEGIN { # Initialization. Set two variables. fsDrops: packets drop. numFs: packets sent fsDrops = 0; numFs = 0; } { action = $1; time = $2; from = $3; to = $4; type = $5; pktsize = $6; flow_id = $8; src = $9;

dst = $10; seq_no = $11; packet_id = $12; if (from==1 && action == "+") numFs++; if (flow_id==2 && action == "d") fsDrops++; } END { printf("number of packets sent:%d lost:%d\n", numFs, fsDrops); } Usage: awk -f loss.awk out.tr Results: number of packets sent:550 lost:8 Description: From the results, we know that sender sent 550 packets, but 8 packets got lost. 3.2. End-to-End Delay Write the awk program that calculates the end-to-end delay of the CBR packets. To calculate delay you should obtain from the log for each CBR packet the time when the packet was created and the time when the packet was received. Hint: to obtain the time when the packet was created watch the time when you see the packet with the specific sequence number for the first time. The delay experienced by the packet i should be coupled with the time the packet was created. The output file of the awk program should have the following format Time = 0.100000 Delay = 0.038706 Time = 0.108000 Delay = 0.038706 Time = 0.116000 Delay = 0.038706 3.3 Jitter Write the awk program that calculates the jitter of the CBR traffic. Recall that jitter is calculated as the difference of the delay times of the adjacent packets. Jitter(i) =( (ReceiveTime(i)-SendTime(i)) - (ReceiveTime(j)-SendTime(j))/(i-j) ; j > 1. Here i,j sequence numbers of the packet.

We are used to calculate jitter for two sequential packets (case i-j=1) Formula above takes in account that packets may be dropped and two adjacent packets in the output trace file are not the packets with the sequential sequence numbers (j >i). The jitter experienced by the packet i should be coupled with the time the packet was created. The output file of the awk program should have the following format Time = 1.068000 jitter =0.002296 Time = 1.076000 jitter =0.001600 Time = 1.084000 jitter =-0.003294 Time = 1.092000 jitter =-0.000602 . 3.4 More complex model Add to the topology (in the tcl file) another node (s3) connected to 'r' node, and transmitting FTP/TCP. With different packet size (default size is 1000):

$tcp2 set packetSize_ 5000

Make sure the new FTP will start 0.5 seconds after the first one (both stop in the same time). Run the ns again (to create new trace file), and repeat the previous calculation (section 3.1-3.3) for the new topology. What was changed? Why? 4. Report Your report should contain: 4 graphs (jitter/time & delay/time X 2), loss rate obtained X 2, Ns-2 script (the last one) and awk program/s. Your NS-2 scripts and AWK programs should be readable. Please use self-explanatory names for variables (e.g. delay and not d) and comment your code. Not readable code will not be accepted. Plots should have titles; axes should be specified with dimensions. If there are several curves on one plot, the plot should have a legend. If there are important points at the graph (like maximum) explain it. Please keep your report. Close to the end of the course try to add explanations to the results of the simulation using your knowledge from the course Computer networks

The report should be defended at the end of the course.

You might also like