CS 640 Introduction to Computer Networks


Programming Assignment 3: TCP


Instructions & FAQs


(1). Testing your program:

Once you have coded up a server program that meets all the specifications, you can test your program by  using the folowing troll binary
This is short manual and complete manual

Note: it is useful for testing the robustness of your server. However, you need to consider how to test your server during the development step such as how to force the receiver to drop the SYN ACK packet.
(1). Pack the data: We use a MTU to limit the size of packet. Here I show an example about how to pack data and do zero padding in the last packet.
Data: 101 bytes
MTU: 40 bytes
Header 24 bytes
I need 7 packets to finish the sending process
Packet 1: 40 bytes: 24 bytes header and 16 bytes of data, length = 16
Packet 2: 40 bytes: 24 bytes header and 16 bytes of data, length = 16
Packet 3: 40 bytes: 24 bytes header and 16 bytes of data, length = 16
Packet 4: 40 bytes: 24 bytes header and 16 bytes of data, length = 16
Packet 5: 40 bytes: 24 bytes header and 16 bytes of data, length = 16
Packet 6: 40 bytes: 24 bytes header and 16 bytes of data, length = 16
Packet 7: 29 bytes: 24 bytes header and 5 bytes of data with no zero-pad
(2). Write out the received data into file: I would like to see that your receiver can reconstruct the proper sending data in sequence-number order.
(3). Related to the flag of SFA The flag SFA occupy the least three signifcant bit of length field in the header i.e. the maximum length will be 2^27. Our host computer is little endian, the << operator will work in the little endian way. Thus, if we transform the data to network order and then left shift it. The data won't appear to be what we want. The following is the correct order

1. Compute the length of the data
2. length = length << 3;
3. nLength = htonl(length);
4. Put in the mask.
Here is conceptually what happen:

length = xxx||||| |||||||| |||||||| ||||||||

when we shit it left 3 bits it will become

length = ||||||| ||||||| |||||||| |||||000
We give an example of tranforming the length 127
length = 127 i.e. conceptually 0000000 00000000 00000000 01111111 host representation 01111111 00000000 00000000 0000000
length = length << 3 i.e. conceptually 00000000 00000000 00000011 11111000 host representation 11111000 00000011 00000000 0000000
nLength = htonl(length) i.e. network representation 00000000 0000000 00000011 11111000
we can see that the last three bits are empty
(4). Receiver behavior There is some confusing part in Receiver action because of typo. For each "Data" packet received from the sender, the receiver will send an ACK packet to the sender.

1. The "acknowledge" field in each ACK packet will be the next expected byte not "sequence number" field.
2. The "ACK" packet will copy the time stamp fields from "Data" packet received from the sender into the corrosponding field of ACK packet. In other word,

ACK->time stamp(sec) = Data-> time stamp(sec)
ACK->time stamp(msec) = Data-> time stamp(msec)

(5). Testing data

w   Submission Instructions:
    What to submit:


You will need to submit the source code along with a Makefile, located in a directory called p3/. Compact the directory into a single tar.gz file and name it p3.tar.gz. Do not submit object files, or compiled executables.


The Makefile should have two rules: clean and all.

clean : will delete previous .o files, executables, etc.

all : should produce a single executable called server.


The TA will run the following sequence of operations to execute and test your code:


tar xvfz p3.tar.gz

cd p3/

make clean

make all



Please test to make sure that these commands can execute in sequence without any intervention.

How to submit:


First add the following line to your .cshrc.local file (located in your home directory):

set path = ($path /s/handin/bin)


Then run the following command at the shell prompt:

source ~/.cshrc.local


Finally, to handin your files, enter the following command:

handin -c cs640-1 -a 3 -d <directory>

where <directory> is the path to the directory where all your files are located.


handin will go through the specified directory and hand in all the necessary files.