Skip to content

anticlam/tcp-vs-udp-performance-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CENG435 Network Programming Project

Overview

This project implements and analyzes two different file transfer protocols for reliable data transmission:

  1. TCP-based file transfer - Using the reliable TCP protocol
  2. UDP-based Selective Repeat ARQ - Custom implementation of a reliable data transfer protocol over UDP with interleaving

The project is designed to compare the performance of these protocols under various network conditions including delay, packet loss, corruption, duplication, and reordering.

Project Structure

ceng435/
├── README.md                           # This file
├── docker-compose.yaml                 # Docker Compose configuration
├── Dockerfile                          # Container environment setup
├── generateobjects.sh                  # Script to generate test files
├── authors.txt                         # Project authors
├── Network Report.pdf                  # Performance analysis report
├── code/                               # Main implementation directory
│   ├── README.md                       # Code directory documentation
│   ├── obj/                            # Test objects directory
│   │   ├── small-*.obj                 # Small test files (~10KB each)
│   │   └── large-*.obj                 # Large test files (~10MB each)
│   ├── checksums/                      # MD5 checksums for verification
│   │   ├── small-*.obj.md5             # Checksums for small files
│   │   └── large-*.obj.md5             # Checksums for large files
│   ├── tcp/                            # TCP implementation
│   │   ├── tcpserver.py                # TCP server implementation
│   │   ├── tcpclient.py                # TCP client implementation
│   │   └── received_files/             # Directory for received files
│   └── selectiveRepeat/                # UDP Selective Repeat implementation
│       ├── server.py                   # UDP server with Selective Repeat ARQ
│       ├── client.py                   # UDP client with Selective Repeat ARQ
│       ├── mychecksums.py              # Checksum verification module
│       └── received_files/             # Directory for received files
└── examples/                           # Example implementations
    ├── tcp/                            # Basic TCP examples
    └── udp/                            # Basic UDP examples

Protocol Implementations

TCP-based File Transfer

The TCP implementation (code/tcp/) provides a simple and reliable file transfer mechanism:

Features:

  • Reliable transmission using TCP's built-in error correction
  • Sequential file transmission
  • Automatic retransmission and flow control
  • File integrity verification using MD5 checksums
  • Performance timing and logging

Server (tcpserver.py):

  • Listens on port 65432
  • Sends all files from the obj/ directory sequentially
  • Uses 1KB chunks for transmission
  • Sends filename before each file's data
  • Uses special markers for end-of-file and end-of-transmission

Client (tcpclient.py):

  • Connects to server and receives all files
  • Reconstructs files from received chunks
  • Verifies file integrity using predefined checksums
  • Logs reception time for each file

UDP-based Selective Repeat ARQ

The UDP implementation (code/selectiveRepeat/) implements a sophisticated reliable data transfer protocol:

Features:

  • Selective Repeat ARQ for reliability
  • Adaptive window size (10-100 packets)
  • Interleaving of chunks from multiple files
  • Dynamic chunk sizing based on file size
  • Timeout-based retransmission (250ms default)
  • Congestion control with window size adjustment

Server (server.py):

  • Implements sliding window protocol
  • Interleaves chunks from multiple files for balanced transmission
  • Uses different chunk sizes for small (1KB) and large (10KB) files
  • Maintains timers for each unacknowledged packet
  • Implements congestion control by adjusting window size

Client (client.py):

  • Sends acknowledgments for received packets
  • Handles out-of-order packet delivery
  • Requests missing chunks at the end of transmission
  • Reconstructs files from received chunks
  • Verifies file integrity using checksums

Network Environment Setup

Prerequisites

  • Docker (with Compose V2 plugin recommended)
  • VSCode (recommended for development)
  • Git

Installation

  1. Clone the repository:

    git clone https://github.com/cengwins/ceng435.git
    cd ceng435
  2. Build the Docker image:

    docker build -t ceng435 .

Running with Docker Compose (Recommended)

  1. Start the containers:

    docker compose up -d
  2. Access the server container:

    docker exec -it server bash
  3. Access the client container (in another terminal):

    docker exec -it client bash
  4. Stop the containers:

    docker compose down

Running Containers Directly

Server container:

docker run -t -i --rm --privileged --cap-add=NET_ADMIN --name ceng435server -v ./code:/app:rw ceng435:latest bash

Client container:

docker run -t -i --rm --privileged --cap-add=NET_ADMIN --name ceng435client -v ./code:/app:rw ceng435:latest bash

Usage Instructions

1. Generate Test Files

In the server container, navigate to the objects directory and generate test files:

cd /app/obj
../generateobjects.sh

This creates:

  • 10 small files (~10KB each): small-0.obj to small-9.obj
  • 10 large files (~10MB each): large-0.obj to large-9.obj
  • Corresponding MD5 checksum files

2. Network Condition Simulation

Use Linux Traffic Control (tc) to simulate various network conditions:

Add delay:

tc qdisc add dev eth0 root netem delay 100ms

Add packet loss:

tc qdisc add dev eth0 root netem loss 5%

Add corruption:

tc qdisc add dev eth0 root netem corrupt 1%

Add duplication:

tc qdisc add dev eth0 root netem duplicate 2%

Add reordering:

tc qdisc add dev eth0 root netem delay 10ms reorder 25% 50%

Remove all rules:

tc qdisc del dev eth0 root

3. Running TCP File Transfer

Server (in server container):

cd /app/tcp
python3 tcpserver.py

Client (in client container):

cd /app/tcp
python3 tcpclient.py

4. Running UDP Selective Repeat Transfer

Server (in server container):

cd /app/selectiveRepeat
python3 server.py

Client (in client container):

cd /app/selectiveRepeat
python3 client.py

Performance Analysis

The project includes comprehensive performance analysis capabilities:

Metrics Collected

  • Total transfer time for all 20 files
  • Individual file transfer times
  • Throughput (bytes/second)
  • Packet loss and retransmission statistics
  • File integrity verification

Network Parameters Tested

  • Delay: 0ms, 25ms, 50ms, 100ms, 200ms
  • Packet Loss: 0%, 1%, 2%, 5%, 10%
  • Corruption: 0%, 0.1%, 0.5%, 1%
  • Duplication: 0%, 1%, 2%, 5%
  • Reordering: 0%, 5%, 10%, 25%

Expected Results

  • TCP performs better under normal conditions due to optimized implementation
  • UDP Selective Repeat shows better performance under high packet loss
  • Interleaving in UDP implementation provides more balanced file completion times
  • Both protocols maintain data integrity under all tested conditions

Key Features

TCP Implementation

  • Simplicity: Leverages TCP's built-in reliability
  • Sequential Transfer: Files sent one after another
  • Automatic Flow Control: TCP handles congestion control
  • Error Recovery: Automatic retransmission by TCP stack

UDP Selective Repeat Implementation

  • Custom Reliability: Implements ARQ protocol from scratch
  • Parallel Transfer: Multiple files transferred simultaneously
  • Adaptive Window: Dynamic window size based on network conditions
  • Interleaving: Chunks from different files interleaved for balanced completion
  • Congestion Control: Custom implementation with window size adjustment

File Integrity Verification

Both implementations include robust file integrity verification:

  • MD5 Checksums: Pre-computed checksums for all test files
  • Automatic Verification: Clients verify received files against expected checksums
  • Mismatch Detection: Reports any corrupted or missing files
  • Complete Transfer Confirmation: Ensures all 20 files are received correctly

Development and Debugging

Container Environment

  • Ubuntu 22.04 base image
  • Python 3 for implementation
  • Network tools: tc, ping, netstat, ss
  • Development tools: vim, git, curl

Volume Mounting

  • Local code/ directory mounted to /app/ in containers
  • Local examples/ directory mounted to /examples/ in containers
  • Changes made locally are immediately available in containers
  • Persistent storage for development work

Logging and Monitoring

  • Transfer times logged to ten.txt
  • Console output for real-time monitoring
  • Checksum verification results
  • Network condition impact analysis

Troubleshooting

Common Issues

  1. Connection Refused: Ensure server is running before starting client
  2. Permission Denied: Check that containers have proper network privileges
  3. File Not Found: Verify test files are generated in /app/obj/
  4. Checksum Mismatch: May indicate network corruption or implementation bug

Network Configuration

  • Server IP: Use 172.17.0.2 (default Docker bridge) or container hostname
  • Port: 65432 (configurable in source code)
  • Firewall: Docker handles port forwarding automatically

Performance Optimization

  • Chunk Size: Adjustable in source code for different network conditions
  • Window Size: Configurable for UDP implementation
  • Timeout Values: Tunable based on network latency
  • Buffer Sizes: Can be adjusted for memory/performance trade-offs

Contributing

When modifying the code:

  1. Test both TCP and UDP implementations
  2. Verify file integrity after transfers
  3. Test under various network conditions
  4. Update documentation for any protocol changes
  5. Ensure compatibility with existing test infrastructure

References


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published