This is a non-trivial task. There are many questions that you've left unanswered to help us help you.
As an assignment, is this part of some larger context system you must fit into? For instance, is there an API for communicating with your upper and lower layers? Are you using a Linux-based stack? Windows?
What version of TCP do you wish to implement? Will this be stripped (with fixed options) or will you implement all options?
The TCP version(s) used by Linux are actually pretty modular. If you are looking to use that model have you been given a design? Will you simplify and only implement a single version not intended to fit a particular model? If so, this loops to my first question.
In addition to all of that; what is you experience level? What have you tried so far?
L7Sqr
Practically a Master Poster
657 posts since Feb 2011
Reputation Points: 201
Solved Threads: 124
TCP generally works by maintaining a window of sent bytes in the stream and adjusts that window based on ACK/NACK from the remote end. The timeout can be implemented several ways each with trade-offs but really depends on the system you are developing to. In general, though, the timeout works by setting a timeout on each chunk of data you send, as each of those chunks get ACKed you drop the timer. This way, if some chunk is not acked in a particular amount of time the timer will fire and a retransmission will occur. There really is a wide arena for implementation here. There are variations on just about every aspect of the TCP algorithm for one reason or another.
My suggestion is that you start with a fixed timeout (instead of basing it in RTT) and have a single timer for each chunk of data you send. If you've got the communication between layers working (which it sounds like you do) then this will be the shortest path to a working TCP. You can extend as necessary once you have that.
I wouldn't even worry about the back-off mechanism until you have all of the previous pieces in place and tested.
L7Sqr
Practically a Master Poster
657 posts since Feb 2011
Reputation Points: 201
Solved Threads: 124