Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

TC1211/TCP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TCP

Custom TCP implementation

Group Members

  • Francesco Agosti (fra5)
  • Grace Chen (gsc9)
  • TC Dong (td84)
  • Michael Ren (mjr37)

File Layout

  • src/: Source files
    • 3a/: Part 3a source files
      • reliable.c: C source file for 3a implementation
      • rlib.c|h: C source and header files for 3a helper library
      • Makefile: Makefile to build 3a
      • reference: Reference implementation of 3a
      • stripsol: ???
      • tester: Tester binary
      • tester-src/: Tester source, in Haskell
    • 3b/: Part 3b source files
      • generator: Random file generator binary
      • relayer/: Relayer binary and config file
        • config.xml: Bundled relayer configuration (from zip of 3b)
        • config-standalone.xml: Configuration from project page
        • relayer: relayer binary
        • measure_bandwidth/: Relayer bandwidth measurement utility source files
          • readme: README
          • receiver.cpp: Receiver end of measurement utility
          • sender.cpp: Sender end of measurement utility
      • reliable/: Implementation of 3b
        • reliable.c: C source file for 3b implementation
        • rlib.c|h: C source and header files for 3b helper library
        • Makefile: Makefile to build 3b
        • stripsol: ???

NOTE: (rlib|reliable).(c|h) are not the same between 3a and 3b

Part A: Sliding Window Protocol

Implementation of helper file packet_list.c

Our packet_list object, defined in packet_list.c, basically holds a packet_t and pointers to next and prev packet_t objects, allowing us to create and maintain a list of packet_t objects. We use this object to create our send and receive buffers.

packet_list.c also holds several helper methods that aid the implementation of reliable.c. For example, there are various methods to handle the creation of a packet (new_packet), the deletion/insertion of a packet from a buffer (remove_head_packet, insert_packet_after_seqno, append_packet), obtaining certain information from a packet buffer (packet_list_size, packet_data_size), and the serialization of the data across multiple packets into a single character buffer for output (serialize_packet_data).

Implementation of reliable.c

rel_t object

Besides the given objects, rel_t cotains a send buffer (packet_list *), a receive buffer (packet_list *), unsigneds int next_seqno_to_send and next_seqno_expected, and a struct config_common object, defined in rlib.h.

rel_create

rel_create initializes an instance of a rel_t object and sets all of the data fields within the rel_t object accordingly. For example, the four eof flags (which we use to determine when to call rel_output) are set to 0, the send and receive buffers are set to NULL, and next_seqno_expected is set to 1.

rel_destroy

rel_destroy calls conn_destroy on the rel_t object passed in, and frees the send and receive buffers.

rel_recvpkt

rel_recvpkt does various checks on the incoming packet, including packet length, whether the reported length matches the actual length, validity of ackno, and checksum. This method calls send_ack, handle_ack, rel_read, rel_output, and insert_packet_in_order (from packet_list.c) when appropriate.

rel_read

rel_read reads in a given input and breaks the input into chunks that are at most the maximum data size for a packet, creates a packet and sets its values for each chunk of data, calls conn_sendpkt for each packet, and appends the packet to the send buffer using a function in packet_list.c.

rel_output

rel_output will call conn_bufspace to obtain the maximum amount of data that can be outputted, before comparing that maximum to the size of the data that is currently stored in receive_buffer. Whichever value is smaller is to be the amount of data copied from the receive_buffer. rel_output then calls serialize_packet_data from packet_list.c to have the correct amount of data copied into a character buffer, which is then passed to conn_output. rel_output then updates the head pointer of the receive_buffer; the data written to output no longer needs to be stored in the buffer.

rel_timer

rel_timer calls resend_packets (a helper function described below).

Helper Functions

enforce_destroy

enforce_destroy checks the eof flags; if all are set, it calls rel_destroy on the rel_t object passed in.

handle_ack

handle_ack checks the seqno of the ACK passed in, and sets the eof flag indicating that the other end has finished receiving if the seqno is larger than the final seqno. This function then removes all packets in the send buffer that have become ackowledged.

resend_packets

resend_packets iterates through the send buffer and calls conn_sendpkt on each packet.

send_ack, is_eof_packet

Pretty straightforward.

handle_eof_packet

Calls conn_output with a null pointer for the packet to be sent; sets the eof flag for having finished sending the file; and calls enforce_destroy to see if it is appropriate to destroy the connection.

Part B: Congestion Control

Implementation of reliable.c

rel_read

We added functionality to check whether the host is a receiver or sender. If receiver, we added functionality to send an eof packet (we also added a check to make sure that the eof is not sent multiple times).

Other Changes

We also changed all parts of the code where we construct packets to reflect the addition of the rwnd field to the packet struct in 3a. We also added more state to the rel_t struct. We changed constants.h in 3b to reflect this change. In resend_packets() we added code to detect when a timeout had occurred, which we do by checking whether the send buffer still has packets in it or not. We also added slow_start_check(), a method that checks whether slow start should be used and recomputes ssthresh and congestion window accordingly, and aimd(), which is called when slow start is not to be used, and which simply increments the congestion window by 1.

Resources Consulted

StackOverflow Professor Benson and Boyang Various classmates on Piazza