Project2 Spec CS118 2021Sv3
Project2 Spec CS118 2021Sv3
Project2 Spec CS118 2021Sv3
1 Overview
The purpose of this project is to implement a basic version of reliable data transfer protocol. You will design
a new customized reliable data transfer protocol, akin to TCP but using UDP in C/C++ programming
language. This project will deepen your understanding on how TCP protocol works and specifically how it
handles packet losses.
You will implement this protocol in context of server and client applications, where client transmits a
file as soon as the connection is established. We will provide skeleton code for connection management. The
following functions should be realized:
• Large file transmission with pipelining.
• Loss recovery with Go-Back-N (GBN) or Selective Repeat (SR). If you implement SR, you can get up
to 15% bonus. Implementation with GBN will not get the bonus.
We made several simplifications to the real TCP protocol, especially:
• You do not need to implement checksum computation and/or verification;
• You can assume there are no corruption, no reordering, and no duplication of the packets in transmit;
The only unreliability you will work on is packet loss;
• You do not need to estimate RTT, nor to update RTO using RTT estimation or using Karn’s algorithm
to double it; You will use a fixed retransmission timer value;
• You do not need to handle parallel connections; all connections are assumed sequential.
• You do not need to realize congestion control in your project.
We require you implement code in a Linux environment so we can test it with simulated packet loss.
All implementations need to be written in C/C++ using BSD sockets. You are not allowed to use any
third-party libraries (like Boost.Asio or similar) other than the standard libraries provided by C/C++. You
are allowed to use some high-level abstractions, including C++14 extensions, for parts that are not directly
related to networking, such as string parsing and multi-threading.
2 Instructions
The project contains two parts: a server and a client.
• The server opens UDP socket and implements incoming connection management from clients. For each
of the connection, the server saves all the received data from the client in a file.
• The client opens UDP socket, implements outgoing connection management, and connects to the server.
Once connection is established, it sends the content of a file to the server.
Both client and server must implement reliable data transfer using unreliable UDP transport, including
data sequencing, cumulative acknowledgments. We will give you the skeleton codes including header setup
and connection setup.
1
UCLA CS 118 Project 2, Spring 2021
• server.c implements a server that accepts connection setup and store received files.
• client.c implements a client that initiates connection setup and send a file to the server.
So you will find the skeleton codes covers all functions mentioned in this section. Please read through to
make sure your final implementation STILL conforms to the specification.
• The header length is exactly 12 bytes, while the design does not use up all 12 bytes, pad zeros to
make it so.
$ ./server <PORT>
The argument hPORTi is the port number on which server will “listen” on connections (expects UDP
packets to be received). You can assume that the specified port is always correct. The server must accept
connections coming from any network interface. For example, the command below should start the server
listening on port 5000 .
$ ./server 5000
• hFILENAMEi : name of the file to transfer to the server after the connection is established.
For example, the command below should result in connection to a server on the same machine listening
on port 5000 and transfer content of testfile :
2
UCLA CS 118 Project 2, Spring 2021
You can assume that the specified inputs are always correct.
The client open a UDP socket and initiate 3-way handshake to the specified hostname/IP and port. It
shall
• Send UDP packet with SYN flag set, Sequence Number initialized using a random number not
exceeding MaxSeqNum = 25600 , and Acknowledgment Number set to 0 .
• Expect response from server with SYN and ACK flags set.
After file is successfully transferred (all bytes acknowledged), the client gracefully terminate the connec-
tion following these steps:
• Expect a packet with ACK flag and another packet FIN flag.
• Respond to each incoming FIN with an ACK packet; drop any other non- FIN packet.
• After receive the FIN packet, wait for 2 seconds to close connection and terminate.
• Packet received:
RECV hSeqNumi hAckNumi [SYN] [FIN] [ACK]
• Packet sent:
SEND hSeqNumi hAckNumi [SYN] [FIN] [ACK] [DUP-ACK]
• Packet retransmition:
RESEND hSeqNumi hAckNumi [SYN] [FIN] [ACK] [DUP-ACK]
• Timeout:
TIMEOUT hSeqNumi
• After the TCP three-way handshake and before the TCP tear-down, since the ACK number
in packets sent by the client will always be the same (because the server does not send payload),
therefore, the ACKNum in SEND and RESEND can be replaced by 0 and there is no need to
append ACK (Check the sample output below).
• When a packet is being retransmitted, the client should print RESEND instead of SEND . Notice
that unless in the TCP tear-down stage, a server will never print RESEND because duplicate ACK
transmission is not considered to be retransmission.
• There is a white space between any two pieces of information in the output line.
• hyyi means that value of yy variable should appear on the output (in decimal). Undefined value
should be 0. For example, in the first SYN packet in TCP three-way handshake, the AckNum should
be 0.
3
UCLA CS 118 Project 2, Spring 2021
• [xx] means that xx string is optional. If the packet belongs to one or more of the following cases, the
host needs to follow the corresponding printout:
– Duplicate ACK packet: [DUP-ACK] . When [DUP-ACK] shows up, [ACK] must not show up
at the same time.
– If SYN flag is set: [SYN]
Please make sure the printout of your client and server matches the format. You will get no credit if the
format is not followed exactly and our parsing script cannot automatically parse it. You can use the parsing
script test format.py to check the format with the following steps.
First, start server at port number 5000, then start another terminal to run the client and collect output:
./client localhost 5000 file100 > output file
Finally, run the script to check the output with python3 test format.py output file
You are supposed to see output like:
Client ISN: 2254
Server ISN: 25157
Check result: True
• Introduce a large file transmission and pipe-lining. This means you must divide the file into multiple
packets and transmit the packets based on the specified window size.
• Introduce packet loss. Now you have to add a timer for last sent packet (Go-Back-N) or several timers
for each unacked packets (Selective repeat). If a timer times out, the corresponding (lost) packet should
be retransmitted for the successful file transmission.
The credit of your project is distributed among the required functions. If you only finish part of the
requirements, we still give you partial credit. Please implement the project incrementally.
• The maximum UDP packet size is 524 bytes including a header ( 512 bytes for the payload). You
should not construct a UDP packet smaller than 524 bytes while the client has more data to send.
• The maximum Sequence Number should be 25600 and be reset to 0 whenever it reaches the 25600
+ 1.
• Packet retransmission should be triggered when no data was acknowledged for more than RTO = 0.5 seconds .
It is a fixed retransmission timeout, so you do not need to maintain and update this timer using Karn’s
algorithm, nor to estimate RTT and update it.
• If the ACK flag is false, Acknowledgment Number should be set to 0 .
• SYN and FIN packets must not carry any payload. But these packets should take logically 1 byte
of the data stream (same as in TCP, see examples).
4
UCLA CS 118 Project 2, Spring 2021
• Client should send file in pipeling scheme with a fixed window size 5120 (10 packets in a window)
if packets are not retransmissions. For retransmissions, the client initiate retransmissions based on
Go-Back-N or Selective-Repeat.
• Client should support transfer of files that are up to 10 MB .
• When server is running, it should be able to accept multiple clients’ connection requests. It is guar-
anteed that a new client only initiates connection after the previous client closes its connection. In
other words, connections from clients are initiated sequentially, so you do not need to handle parallel
connections.
• The server must save all files transmitted over the established connection and name them following
the order of each established connection at current directory, as hCONNECTION ORDERi.file . For
example, 1.file , 2.file , etc. for the file received in the first connection, in the second connection, and
so on.
• The server should be able to accept and save files, where each file’s size could be up to 10 MB .
• Generally, Go-Back-N scheme keeps ONE timer for the least recent unacknowledged packet and re-
transmits all unacknowledged packets upon timeout. RTO=0.5 seconds . Duplicate ACKs should not
trigger retransmission. Procedures at the sender are as follows (see pseudo code in section 3.33 of
textbook):
– After the sender sends out a packet, the timer is started if not running.
– After the sender receives a new ACK (not duplicate), the timer is restarted if there is any
unacknowledged packet.
– Upon timeout, the sender transmits all unacknowledged packets in the window; The timer is
started for the same packet again.
5
UCLA CS 118 Project 2, Spring 2021
• The file transmission should be completed successfully, unless the packet loss rate is set to 100%.
• The timer on both the client and the server should work correctly to retransmit the lost packet(s).
1. To check the current parameters for a given network interface (e.g. lo0 for localhost; The interface
name of localhost may differ on your laptop, you can figure it out by command ifconfig ):
tc qdisc show dev lo0
2. If network emulation has not yet been setup or have been deleted, you can add a configuration called
root it to a given interface, with 10% loss without delay emulation for example:
tc qdisc add dev lo0 root netem loss 10%
3. To delete the network emulation:
tc qdisc del dev lo0 root
1. Start the server normally on a port. For example, suppose the server runs on port 5000.
2. Decide the port of the proxy (you need to pick a different one from the server) and the loss rate. For
example, if the proxy port is 9999 and the loss rate is 10%, you need to run:
python3 rdproxy.py 5000 9999 0.1
3. Launch the client. In order to emulate the packet loss, the client will communicate with the proxy
script (port 9999) instead of using port 5000 to directly communicate with the server.
6
UCLA CS 118 Project 2, Spring 2021
• Your source codes (e.g. server.c, client.c). The code of the server and the client can be several files.
• A Makefile. The TAs will only type make to compile your code.
• A README file which will contain following information
– Your name, email, and UCLA ID
– The high level design of your server and client (one paragraph)
– The problems you ran into and how you solved the problems (up to three paragraphs)
– List of any additional libraries used Acknowledgement of any online tutorials or code example
(except class website) you have been using.
7
UCLA CS 118 Project 2, Spring 2021
Client1 Server
(A 500-byte file to send)
| |
| seq=12345, ack=0, SYN |
| -------------------------------------> |
| seq=221, ack=12346, SYN, ACK |
| <------------------------------------- |
| |
| seq=12346, ack=222, ACK |
| -------------------------------------> |
| (if include 500-byte payload) |
| seq=222, ack=12846, ACK |
| <------------------------------------- |
| |
| |
| FIN procedures to close connection |
| <------------------------------------> |
| (saves file 1.file) |
| |
close |
connection | Client2
(A 1000-byte file to send)
| |
| seq=5345, ack=0, SYN |
| <---------------------------------- |
| seq=4321, ack=5346, SYN, ACK |
| ----------------------------------> |
| |
| seq=5346, ack=4322, ACK |
| <---------------------------------- |
| (if includes 512-byte payload) |
| |
| seq=5858, ack=0 |
| <---------------------------------- |
| (if includes 488-byte payload) |
| |
| seq=4322, ack=5858, ACK |
| ----------------------------------> |
| |
| seq=4322, ack=6346, ACK |
| ----------------------------------> |
| |
| |
| FIN procedures to close connection|
| <---------------------------------> |
| (saves file 2.file) |
| |
close
connection
8
UCLA CS 118 Project 2, Spring 2021
See below diagram for illustration for FIN procedures during connection teardown.
Client Server
(A 10000-byte file to send)
| |
... ...
| (10000 bytes transferred) |
| |
| seq=22346, ack=0, FIN |
| -------------------------------------> |
| (no payload in FIN) |
| |
| seq=4322, ack=22347, ACK |
| <------------------------------------- |
| |
| |
| seq=4322, ack=0, FIN |
+--> | <------------------------------------- |
2 | | seq=22347, ack=4323, ACK |
s | | -------------------------------------> |
e | | |
c | ... (if ACK is lost) ...
o | | |
n | | seq=4322, ack=0, FIN |
d | | <------------------------------------- |
s | | seq=22347, ack=4323, ACK |
| | -------------------------------------> |
w | | |
a | ... close
i | | connection
t | |
| |
+--> |
close
connection