CS164 Lab Assignment 6


Assignment: Write a simulation script, analyze trace files and plot a graph


Build a simple network that consists of 4 nodes connected in a linear topology. The detailed specifications of the network are: The simulation will run for 5 seconds. At time 0.1 seconds a Poisson traffic generator will begin generating packets in Node0 with destination Node3. At time 4 it stops. The Transport protocol that will be used for the communication of Node0 - Node3 is UDP. The Poisson will generate packets with a rate of 10000k and packet size 2000bytes (Tip: Set the Burst time equal to zero and the idle time to 10ms)(You can reuse the script of the example simulation last lab).

Compute the real-time length of queue in Node1 and Node2 right at the end of 1st second, using the trace-all trace file. (Hint: use awk to parse the trace-all trace file).

Plot the average length of the queue in Node1 and Node2 as a function of time with interval 0.1sec, using the monitor-queue trace file. (Hint: use awk to parse the queue-monitor trace file, then use xgraph to plot).

Analysis of a Trace-all Trace file

This section shows a trace analysis example. Trace_Example is the same OTcl script as the one in the "Simple Simulation Example" section with a few lines added to open a trace file and write traces to it. For the network topology it generates the simulation scenario, refer to last weeks figure. To run this script download "ns-simple-trace.tcl" and type "ns ns-simple-trace.tcl" at your shell prompt.

Trace_Example. Trace Enabled Simple NS Simulation Script (modified from Example ns-simple.tcl)

Running the above script generates a NAM trace file that is going to be used as an input to NAM and a trace file called "out.tr" that will be used for our simulation analysis. Following figure shows the trace format and example trace data from "out.tr".

Trace Format Example

Each trace line starts with an event (+, -, d, r) descriptor followed by the simulation time (in seconds) of that event, and from and to node, which identify the link on which the event occurred. The next information in the line before flags (appeared as "------" since no flag is set) is packet type and size (in Bytes). Currently, NS implements only the Explicit Congestion Notification (ECN) bit, and the remaining bits are not used. The next field is flow id (fid) of IPv6 that a user can set for each flow at the input OTcl script. Even though fid field may not used in a simulation, users can use this field for analysis purposes. The fid field is also used when specifying stream color for the NAM display. The next two fields are source and destination address in forms of "node.port". The next field shows the network layer protocol's packet sequence number. Note that even though UDP implementations do not use sequence number, NS keeps track of UDP packet sequence number for analysis purposes. The last field shows the unique id of the packet.

Having simulation trace data at hand, all one has to do is to transform a subset of the data of interest into a comprehensible information and analyze it.

The analysis on a queue-monitor trace file is similar to that on the trace-all trace file.



Appendix

                The focus of this tutorial is to provide you with one-line, clear statements to do what is necessary to extract relevant information for analysis from the trace file dumps generated by NS2. We proceed in a manner in unison with what needs to be achieved in this lab, mainly parsing through the trace file to extract information about the queue status.

Assuming the above trace file example, is stored in a file called nstrace, we would first need to extract those lines which correspond to events describing packet arrivals and departures to and from node 2 (Say). To extract all such lines you would need to type in awk '{if(($9>=2.0)&&($9<3.0)) elsif(($10>=2.0)&&($10<3.0))) print $0 }' nstrace > temp

What this statement does is check the 9th column of every line to see if the value is between 2.0 and 3.0 or not, the same for the 10th column, if this so, we select that line for further analysis.

To calculate the number of packets in the buffer in a time frame we must be able to "count" the number of packets be queued and dequeued, and get the difference. Say we want to measure the number of packets in the queue of node 2 every 1 second. We need to write awk 'BEGIN{count=0} /+/{if($2<1) count+=1} END{print count}' nstrace      to count the number of packets coming into the node in the first second.

The BEGIN defines the initialization of a var called count, and /+/ means we want awk to search thru the file for all lines that have a + in them.

Similarly, to compute number of packets leaving/ being dequeued from node 2 we write   awk 'BEGIN{count=0} /-/{if($2<1) count+=1} END{print count}' nstrace  Now that you have the number of packets coming in, and going out in 1 second you can compute the number of packets inside the queue of node 2  by taking the difference as follows.

        in=(`awk 'BEGIN{count=0} /+/{if($2<1) count+=1} END{print count}' nstrace`)

        out=(`awk 'BEGIN{count=0} /-/{if($2<1) count+=1} END{print count}' nstrace`)

        queue=$in-$out

        echo $queue

Remember, this is skeleton code, you will need to write a complete shell script. Have a look at http://www.freeos.com/guides/lsst/ for basic shell scripting. For awk you may refer to, http://www.vectorsite.net/tsawk.html