Skip to content

darkquasar07/Reliable-UDP-Transport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Reliable UDP Transport Protocol

A C implementation of a reliable transport layer built on top of UDP.

This project implements transport-layer reliability mechanisms such as acknowledgements, retransmissions, checksums, ordered delivery, EOF handling, sliding windows, and server-side connection demultiplexing.

Overview

UDP does not guarantee reliable delivery, packet ordering, or protection from packet drops/corruption. This project adds a reliability layer over UDP by implementing:

  • Packet sequence numbers
  • Cumulative acknowledgements
  • Checksum-based corruption detection
  • Timeout-based retransmission
  • Ordered stream delivery
  • EOF/connection teardown handling
  • Stop-and-wait reliability
  • Sliding-window reliability
  • Out-of-order packet buffering
  • Multiple connection demultiplexing in server mode

Project Structure

.
├── README.md
├── .gitignore
├── stop-and-wait/
│   ├── Makefile
│   ├── reliable.c
│   ├── rlib.c
│   ├── rlib.h
│   └── uc.c
└── sliding-window/
    ├── Makefile
    ├── reliable.c
    ├── rlib.c
    ├── rlib.h
    └── uc.c

Implemented Parts

1. Stop-and-Wait Reliable Transport

Folder:

stop-and-wait/

This version supports a single reliable connection between two UDP ports.

Only one data packet is kept outstanding at a time. The sender transmits a packet and waits for its acknowledgement before sending the next packet.

Implemented features:

  • Single direct UDP-to-UDP connection
  • One outstanding packet at a time
  • Packet checksum validation
  • Cumulative ACK handling
  • Timeout-based retransmission
  • EOF packet handling
  • In-order stream output

2. Sliding-Window Reliable Transport

Folder:

sliding-window/

This version extends the stop-and-wait implementation with a configurable sliding window and server-side connection demultiplexing.

Implemented features:

  • Multiple outstanding packets
  • Configurable sender/receiver window size using -w
  • Receiver-side buffering for out-of-order packets
  • Cumulative acknowledgements
  • Timeout-based retransmission of unacknowledged packets
  • Multiple client connections in server mode
  • TCP-to-reliable-UDP relay mode using the provided uc utility

Build Instructions

This project is intended to be built on a Unix/Linux environment.

Install build tools:

sudo apt update
sudo apt install build-essential

Build the stop-and-wait version:

cd stop-and-wait
make

Build the sliding-window version:

cd sliding-window
make

The build creates the following executables:

reliable
uc

reliable is the reliable UDP transport program.

uc is a small TCP/Unix socket utility used for testing client/server mode.

Note for Modern GCC/Clang

Some older course framework files may trigger warnings on newer compilers.

If stop-and-wait fails because warnings are treated as errors, build it using:

cd stop-and-wait
make clean
make CFLAGS="-g -Wall"

This removes -Werror for the local build.

Running Stop-and-Wait Mode

Open two terminals.

Terminal 1:

cd stop-and-wait
./reliable 6666 localhost:5555

Terminal 2:

cd stop-and-wait
./reliable 5555 localhost:6666

Now type text in either terminal. It should be delivered to the other terminal through the reliable UDP layer.

To enable debug packet logs:

./reliable -d 6666 localhost:5555

Running Sliding-Window Mode

Open two terminals.

Terminal 1:

cd sliding-window
./reliable -w 5 6666 localhost:5555

Terminal 2:

cd sliding-window
./reliable -w 5 5555 localhost:6666

Here, the sender can keep up to 5 packets outstanding before waiting for acknowledgements.

You can try different window sizes:

./reliable -w 1 6666 localhost:5555
./reliable -w 10 6666 localhost:5555

A window size of 1 behaves like stop-and-wait.

Running Sliding-Window Client/Server Mode

The sliding-window version also supports client/server mode.

In this mode:

  • uc listens on a TCP port.
  • The reliable server receives reliable UDP packets and forwards data to a TCP endpoint.
  • The reliable client accepts TCP input and relays it through reliable UDP to the server.

Use four terminals.

Terminal 1: start a TCP listener.

cd sliding-window
./uc -l 2222

Terminal 2: start the reliable UDP server.

cd sliding-window
./reliable -s -w 5 1111 localhost:2222

Terminal 3: start the reliable UDP client.

cd sliding-window
./reliable -c -w 5 3333 localhost:1111

Terminal 4: connect to the client using uc.

cd sliding-window
./uc localhost 3333

Now type into Terminal 4. The data flows through:

uc client
  -> reliable client
  -> reliable UDP transport
  -> reliable server
  -> uc listener

Important Files

reliable.c

Contains the main reliable transport implementation.

rlib.c / rlib.h

Provided framework/library code for packet handling, sockets, timers, and connection abstraction.

uc.c

Utility program used to connect/listen on TCP or Unix-domain sockets for testing.

Concepts Demonstrated

  • Transport-layer protocol design
  • Reliable communication over unreliable UDP
  • Stop-and-wait protocol
  • Sliding-window protocol
  • Flow control
  • Packet retransmission
  • Cumulative acknowledgements
  • Packet corruption detection
  • Out-of-order packet buffering
  • Connection demultiplexing
  • Socket programming in C
  • Systems programming

Attribution

This project is inspired by Stanford CS144's publicly available Reliable Transport lab.

This repository is not affiliated with, endorsed by, or maintained by Stanford University.

The reliable transport implementation was completed as a personal systems/networking project for learning purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors