CS168 Project 3: TCP over IP over UDP 11:59 PM, Nov 25, 2014
Each year, students report this assignment is an order of magnitude harder than its predecessor
(seriously). But when you are done here, you will really understand TCP. We’ve given you a lot of
time for this assignment – use it wisely!
2 The Pieces
In this assignment you will use the library you wrote for IP as the underlying network.
Your TCP implementation will have four major pieces — the state machine that implements
connection setup and teardown, the sliding window protocol that determines what data you are
allowed to send and receive at any point, the API to your sockets layer, and a driver program that
will allow all of us to test your code.
2.1 State Machine
You have to implement a state machine that allows state transitions in your TCP. You can use this
diagram
1
to help orient yourself.
The state machine is not as complicated as it may seem, but you should be sure that your TCP
follows all state transitions properly, and doesn’t do anything otherwise. For example, you need to
send SYNs for connect, and FINs to close. You will be expected to follow RFC793
2
and RFC2525
3
precisely. You don’t have to handle the parts of the RFC that refer to urgent data, precedence, and
security.
You can start coding by just using the diagram and getting connections to set up and close under
ideal conditions. However, there are tons of less obvious cases that the diagram doesn’t cover – for
example, what happens when, after a call to
connect
, you’ve sent a SYN, but you receive a packet
that has an incorrect ACK in it? Once your basic state diagram is working, we recommend that
you look at the RFC for answers to questions such as these. In particular, pages 54 and on contain
info on exactly what you should do in such scenarios.
2.2 Sliding Window Protocol
You need to implement the sliding window protocol that is the heart of TCP. Make sure you
understand the algorithm before you start coding. Also keep in mind how sliding windows will
interact with the rest of TCP. For example, a call to CLOSE (
v_shutdown(s, 1)
in our API) only
closes data flow in one direction. Because data will still be flowing in the other direction, the closed
side will need to send acknowledgments and window updates until both sides have closed.
Be sure that you can accept out-of-order packets.
That is, a packet’s sequence number
doesn’t have to be exactly the sequence number of the start of the window. It can be fully contained
within the window, somewhere in the middle. The easiest way to handle such packets is to place
them on a queue of potentially valid packets, and then deal with them once the window has caught
up to the beginning of that segment’s sequence number.
1
http://ttcplinux.sourceforge.net/documents/one/tcpstate/tcpstate.html
2
http://www.faqs.org/rfcs/rfc793.html
3
http://www.faqs.org/rfcs/rfc2525.html
2