In this assignment, we will understand the various mechanisms of TCP using simulations. You will run simulations of TCP transfers in the ns-3 network simulator. You will use the output of the simulations to answer various questions about TCP behavior.
We will work with the ns-3 network simulator. If you have not used a network simulator before, please take some time to familiarize yourself with the concept of a network simulator.
First, download and install a stable release of the simulator on your machine. We have tested the assignment scripts with the latest version 3.26 of ns-3. For the purpose of this assignment, it is enough if you follow the basic tutorial on the ns-3 documentation page.
We have provided you with the simulator script to use in this assignment: tcp-example.cc. Once you have downloaded and built the simulator, you can place this script in any location, say in the scratch folder or the examples folder, and then run the script as follows.
./waf --run scratch/tcp-example
The "tcp-example.cc" simulaton script is fairly straightforward, especially if you have looked at the examples in the ns-3 tutorial. It simulates a single link between two nodes (say, node0 and node1). Data is transferred over TCP on the link. If you look at the first few lines in the main function in the script, you will see the following few lines.
std::string bandwidth = "5Mbps"; std::string delay = "5ms"; double error_rate = 0.000001; int queuesize = 10; //packets int simulation_time = 10; //seconds
The above code configures the following parameters. You can change these values as needed in the exercises below.
We use the TCP NewReno variant but you can use anything else as well. Upon running successfully, the above script produces the following output files.
+ 1 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 6 offset (bytes) 0 flags [none] length: 40 10.1.1.1 > 10.1.1.2) ns3::TcpHeader (49153 > 8080 [ SYN ] Seq=0 Ack=0 Win=65535) - 1 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 6 offset (bytes) 0 flags [none] length: 40 10.1.1.1 > 10.1.1.2) ns3::TcpHeader (49153 > 8080 [ SYN ] Seq=0 Ack=0 Win=65535)
For your assignment, you will need to run simulations by varying the parameters above, and analyze the output files above to answer several questions about TCP. To understand what is happening with TCP in the simulation, it will be helpful to look at the following metrics.
Alternately, you can write a script to analyze the pcap file and calculate throughput. You can use "tshark -r" or "tcpdump -r" with several useful options to read the pcap files and process them. Please read up online about the tshark tool and its various options. For example, if you run tshark with the "-T fields" option, you can extract only a subset of fields from the pcap file to the terminal output, which you may then redirect to a smaller file that is easy to parse. For example, the following command will read the pcap file "tcp-example-0-0.pcap" and extract the timestamp, source and destination IP and port numbers, and sequence numbers.
$tshark -r tcp-example-0-0.pcap -T fields -e frame.time_epoch -e ip.src -e ip.dst -e tcp.port -e tcp.seq -e tcp.len -e tcp.ackYou can use several such simple tshark commands to easily extract only the information you care about from the pcap files. After you extract some information from the pcap file, you may use sed/awk/perl/python or even C++/Java to extract the various columns in the output, and perform any manipulations you want to do with them (e.g., add up the packet length received column and divide by total time to get throughput).
set term postscript eps color set output 'cwnd.eps' set ylabel 'cwnd' set xlabel 'time' plot 'tcp-example.cwnd' using 1:2Now, I store the 5 lines above in a file called "example.gp", and I store the cwnd trace file generated by ns-3 called "tcp-example.cwnd" also in the same folder. Then I run "gnuplot example.gp" at the commandline. Then the graph "cwnd.eps" will be created in the same folder showing the cwnd vs time plot.
In general, once you generate the output data to plot, a simple variant of a gnuplot script like this will let you generate any graph you want.
In addition to the metrics above, a little bit of extra work will get you access to the following metrics as well. (As a first cut, you can skip computing the two metrics below.)
Once you have figured out how to run simulations, and how to analyze the output from the simulations, let's proceed to answer some interesting questions about TCP behavior. Record your observations from each of these simulations in a report that you will turn in at the end of this programming assignment. Please be clear and concise in your answers. Include simulation data (graphs/numbers/tables) in your report as needed to substantiate your answers.
You must submit a tar gzipped file of your submission on Moodle. The name of the file must be your roll number. The submission tarball must contain a report (in PDF or text format), providing your answers to the exercises above. You must also submit any scripts/code you wrote to solve the assignment.
Your submission will be graded by reading your report, and by having you run simulations during a demo/viva. You will use your submitted files to run simulations and interpret your results during the viva.