Project 4: A TCP State Transition Program

Version 1.0
DUE DATE: 11/27/2016 at 11:59:59pm

Useful Files:


The Transmission Control Protocol (TCP) is a protocol used on top of IP to help guarantee a reliable stream of data from the sender to the receiver. The purpose of this assignment is to get you familiar with how TCP works.

A State Transition Diagram

The figure below shows a state transition diagram for TCP. States are shown in boxes, and arrows show transitions. The appl: or recv: fields shows input received to cause the transition. The send: field shows output generated during the transition.

Writing a Program

Please write a program in C, C++, Ada, Python2, Python3, or Java to model the state transition diagram shown above. (If you want to choose a different programming language, you must approve it with me at least 5 days before the assignment is due so I can get it on the classs Linux servers.) For information on how to compile and run different programs on the Linux class servers, click here.

First, begin your programs in the CLOSED state.

  1. Print the current state
  2. Prompt for input to the transition (for example, recv: or appl: above).
  3. Print what you received
  4. If what you received is invalid, print "Invalid" and stay in current state. Go to step 1.
  5. Else if what you received is valid, print what is then sent in the transition (for example, send: from above)
  6. Print the new current state
  7. Go to step 2

Here is an example run traversing the left side of the diagram with a spelling error and invalid state:

Make your code output look exactly like the run above for full points! For clarification, use the following valid input strings:"passive open", "active open", "close", "SYN", "SYN,ACK", "ACK", "FIN". Print the states exactly as they are in the diagram (capital letters plus underscore). If any trasition is not visible in the diagram, just assume it is invalid. NOTE: The state TIME_WAIT takes no input. If you transition to this state, print it, and immediately move to closed (see example above).

Testing your code

You can test your code on the Linux server using input redirection and piping. First, read how the <, >, and | operators work using the following resources:

Next, take a look at my sample testin.txt file. Notice it contains input to your program.

Using the 'cat' program to read from your input file, run your program using the following command:

$> cat testin.txt | ./stateTCP > out.txt

(Note: You can replace './stateTCP' with your method of executing your program, like 'python3'.) Instead of printing to the screen, this will create an output file called 'out.txt'.

To see if your output file exactly matches my output file, download my output file called testout.txt. You can compare the two files using the diff command:

$> diff out.txt testout.txt

If they are the same, diff will not display any output. For more information about the diff command, issue 'man diff'.

I highly encourage you to write more test cases using input files that you create. I will be using a full suite of input and output files to test all paths of your program.

Create a README.txt file

The README.txt file should contain the following:

  • Your name
  • A listing of all the files in your submission and a brief descriptions of each file
  • Instructions for compiling your programs
  • Instructions for running your program
  • Any challenges you encountered along the way
  • An explanation of what the < , > , | operators do in Linux
  • An explanation of what the diff command does in Linux

Turning it in

You will be turning in your README.txt file and your program code in two separate locations (no zip file this time.) Navigate to eLearning and click on the Project 4 folder. Submit your program file and README.txt file in the designated areas. Make sure your program is named stateTCP (with the appropriate extension), you have your name at the top of the program source, and you have at least three useful comments within your code.

Note: This is your last programming project of the class.