ns-3 is a discrete event simulator that models all the layers of the TCP/IP stack (except physical layer, of course!). It is open-source and is used extensively by researchers. The TCP code base of ns-3 is structured similar to the actual kernel code. Therefore, it is a good platform to implement newer protocols before spending arduous effort with hacking the actual kernel. ns-3 is written entirely in C++ along some Python scripts. All our code must be written in C++. Although you might be able to get by with some Python, I won’t recommend it. Another nice thing about ns-3 is that it generates PCAP packet traces and is compatible with other tools like Tcpdump and Wireshark.
This homework is not an exhaustive ns-3 project. So, I suggest that you refer to ns-3 documentation on a need-to-know (on-demand) basis. However, I recommend spending some time reading the tutorial on the ns-3 website.
Primarily, there are three goals of this homework:
To get started, check out the ns-3 code base from the repository. DO NOT download the code from the ns-3 web page. I have customized the ns-3 code for this homework.
public/hw6
Prior to building the ns-3 simulator, your VM must be setup for development. If you have installed “build-essential” as part of homework #1, then you should be good to go.
cd hw6/ns-allinone-3.25/ns-3.25
./waf configure --enable-examples --enable-tests
./waf
Once the build succeeds, we are ready to simulate some TCP!
In class, we learned that TCP Reno uses duplicate acks to deal with transient congestion i.e., congestion episodes that last for a short amount of time. However, random losses induced by the medium (i.e., wi-fi) can confuse TCP’s congestion control.
I have provided a simulator code in ns-allinone-3.25/ns-3.25/scratch/homework6a_lossy.cc
. This code simulates FTP over TCP between a client and a server. It uses TCP NewReno protocol which is an advanced version of the TCP Reno protocol (TCP Tahoe + Fast re-transmit/recovery) that we studied in the class. In addition, it also simulates random packet losses such as a wireless medium. Assuming that you are in hw6/ns-allinone-3.25/ns-3.25/
directory, you can simulate this code using the command:
./waf --run "scratch/homework6a_lossy --duration=5"
This will simulate a FTP transfer for 5 seconds. At the end of simulation, you will find many homework6a_lossy-*
files. Among them, the file homework6a_lossy-cwnd.data
shows how TCP’s congestion window evolves over time (the first column is time in seconds and the second column is congestion window in bytes). You can plot this data using excel or gnuplot. If you are using gnuplot, then you can use the command gnuplot homework6a_lossy.plot
. The gnuplot script homework6a_lossy.plot
is given to you as well. Spend some time understanding how the simulator code works.
TO DO:
Congestion happens when the aggregate sending rate exceeds the network capacity. In the next example, we have multiple senders sending data to one receiver causing congestion. The provided simulator code ns-allinone-3.25/ns-3.25/scratch/homework6b_incast.cc
creates a scenario where 100 senders send to one common destination and the final link to the destination becomes congested. Assuming that you are in hw6/ns-allinone-3.25/ns-3.25/
directory, you can simulate this code using the command:
./waf --run "scratch/homework6b_incast --num_flows=100 --duration=300"
This will simulate 100 FTP transfers to the same destination for 300 seconds. At the end of simulation, you will find many homework6b_incast-*
files. Among them, the file homework6b_incast-cwnd.data
shows how TCP’s congestion window evolves over time (the first column is time in seconds and the second column is congestion window in bytes). You can plot this data using excel or gnuplot. If you are using gnuplot, then you can use the command gnuplot homework6b_incast.plot
. The gnuplot script homework6b_incast.plot
is given to you as well. Spend some time understanding how the simulator code works.
TO DO:
In simple terms, TCP Tahoe is TCP Reno without fast re-transmit and fast-recovery. Thus, implementing TCP Tahoe on top of TCP Reno code is easy, and, therefore, is going to be our last homework! In this last task, you will hack the TCP stack so that you don’t react to duplicate ACKs. If you recall, simply not reacting to duplicate ACKs will disable fast-retransmit and fast-recovery.
I understand ns-3 is a large codebase. But here is a little pointer to the core of the congestion control code ==> ns-allinone-3.25/ns-3.25/src/internet/model/tcp-socket-base.cc
. The code change would be less than 50 lines. Once you have made the changes in tcp-socket-base.cc
, run the simulation code from task(1) and task(2) with your modified code (TCP Tahoe). (Running the command line will automatically complile the code!).
TO DO:
report
in hw6/ns-allinone-3.25/ns-3.25/
. Commit the report to git.This homework is due on
The grading for this homework, will be done manually.