Overview
This project implements a reliable UDP transport layer so a sender and receiver can transfer a file correctly over an unreliable network. The network may drop, delay, or reorder packets, and your protocol must preserve data integrity and ordering while completing the transfer in a reasonable time.
To archieve reliability, two reliable protocols are used in this project: Go-Back-N (GBN) and Selective Repeat (SR).
What is implemented
The sender and receiver should provide file transfer, including:
- Segmentation and reassembly
- Split the input file into fixed-size packets and reconstruct the file in order.
- Sequencing and ACKs
- Design and handle sequence numbers and acknowledgments to recover from loss and reordering.
- Reliability
- Implement timeouts, retransmissions, and window sliding; handle duplicate packets and duplicate ACKs.
- Clean termination
- Complete the transfer with a reliable FIN/FINACK handshake.
Protocol requirements
- GBN (Go-Back-N)
- Receiver doesn’t buffer out-of-order data
- Sender uses cumulative ACKs and retransmits the entire window on timeout
- More details in Go-Back-N Implementation
- SR (Selective Repeat)
- Receiver buffers out-of-order data
- Senders manages per-packet timers and acknowledgments independently
- More details in Selective Repeat Implementation
Unreliable network emulator
The emulator sits between the sender and receiver and simulates an unreliable network. It can drop packets, delay them, or reorder them. This lets you test your reliability logic without needing a real lossy network.
The sender and receiver do not talk directly. They both use netif_*, which hides the emulator behind a UDP-like API. The emulator learns the endpoints and forwards packets between them, applying loss/delay/reordering along the way.
Running
Emulator
Running emulator:
./emulator.py --loss 0.05 --delay_ms 50 --reorder 0.05GBN
Running sender:
./sender_gbn --listen 10000 --peer_ip 127.0.0.1 --peer_port 10001 --in test.bin --win 20 --timeout 200Running receiver:
./receiver_gbn --listen 10001 --peer_ip 127.0.0.1 --peer_port 10000 --out recv.binSR
Running sender:
./sender_sr --listen 10000 --peer_ip 127.0.0.1 --peer_port 10001 --in test.bin --win 20 --timeout 200Running receiver (adds window size):
./receiver_sr --listen 10001 --peer_ip 127.0.0.1 --peer_port 10000 --out recv.bin --win 20