Code Monkey home page Code Monkey logo

udpy's Introduction

Computer Networks

Reliable Data Transfer


Ahmed Lotfy Siam | 4129

Islam Nabil | 3680


Implementing a Reliable Data Transport Protocol with Python using different reliable data transfer techniques:

- Go-back-N.
- Stop and Wait.
- Selectiverepeat.

- Stop And Wait

Referred to as alternating bit protocol, is a method in telecommunications to send information between two connected devices. It ensures that information is not lost due to dropped packets and that packets are received in the correct order. It is the simplest automatic repeat-request (ARQ) mechanism. A stop-and-wait ARQ sender sends one frame at a time; it is a special case of the general sliding window protocol with transmit and receive window sizes equal to one and greater than one respectively. After sending each frame, the sender doesn't send any further frames until it receives an acknowledgement (ACK) signal. After receiving a valid frame, the receiver sends an ACK. If the ACK does not reach the sender before a certain time, known as the timeout, the sender sends the same frame again. The timeout countdown is reset after each frame transmission. The above behavior is a basic example of Stop-and-Wait.

  • Run
cd stop-and-wait/
python Server.py # To run the server
python Client.py # To run the client side
  • Scenario

    1. Client Requests file x from the server and blocks for response, if no response received, then it throws a timeout exception and resends the request
    2. Server receives request from client and reply with response
    3. Server sends a datagram and blocks for ack from client, or timeout
  • Packet Definition

class Packet:
    def __init__(self, pickled=None, seq_num=0,
                 data=b'', ack='', file='', status=''):

        if pickled is not None:
            self.packet = pickle.loads(pickled)
        else:
            self.packet = {
                "status": status,
                "file": file,
                "ack": ack,
                "seq_num": seq_num,
                "checksum": sha1(data).hexdigest() if data else '',
                "data": data
            }
  • Sample runs

    • Client Side Simulatin Corrupt Packets
    • Simulating Corrupt Packets
    • Server Side Handling timeouts and simulating packet drop

- Go-Back-N

  • Run
cd go-back-n/
python GBN_Server.py # To run the server
python GBN_Client.py # To run the client side
  • Scenario

    1. The Sender sents multiple data frames
    2. The receiver process keeps track of the sequence number of the next frame it expects to receive, and sends that number with every ACK it sends.
    3. The receiver will discard any frame that does not have the exact sequence number it expects (either a duplicate frame it already acknowledged, or an out-of-order frame it expects to receive later) and will resend an ACK for the last correct in-order frame.
    4. Once the sender has sent all of the frames in its window, it will detect that all of the frames since the first lost frame are outstanding, and will go back to the sequence number of the last ACK it received from the receiver process and fill its window starting with that frame and continue the process over again.
  • Packet Definition

class Packet:
    def __init__(self, res=None, seq_num=0, data=b'',
                 ack='', file='', status=''):
        self.keys = [
            "status",
            "file",
            "ack",  # 1 byte
            "seq_num",  # 8 bytes
            "checksum",  # 40 bytes
            "data"
        ]
        if res is not None:
            self.packet = self.__load__(res)
        else:
            self.packet = {
                "status": status.encode(),
                "file": file.encode(),
                "ack": ack.encode(),  # 1 byte
                "seq_num": int(seq_num).to_bytes(8, byteorder='little',
                                                 signed=True),  # 8 bytes
                "checksum": sha1(data).hexdigest().encode(),  # 40 bytes
                "data": data if data else b'',  # 1939 bytes
            }
        dummy_bytes = 2000
        for val in self.packet.values():
            dummy_bytes -= len(val)
        self.packet['dummy'] = b'x' * dummy_bytes
  • Sample Runs

    • Client receiving and simulating corrupt packets
    • Server Sending & Simulating NACK

- Selective Repeat

HOW TO RUN : Change the directory to SelecvtiveRepeat folder and run the server cd SelectiveRepaet

python ServerApp.py

open another terminal tab for client (Client Port = 8080)

   python ClientApp.py

Sample Runs SERVER Client

- Comparison

Comparing these techniques over [1, 2, 3, 4, 5, 10, 30] % PLP

udpy's People

Contributors

islamnabil avatar

Stargazers

Kittipod Lambangchang avatar Heron Ferrari avatar Yan Tavares avatar Milena Tanioka avatar Luis avatar  avatar  avatar

Watchers

 avatar Ahmed Siam avatar  avatar

udpy's Issues

There is no such file "input.txt"

Hi, I am so interested for your implement about ARQ.
However, when I run "stop-and-wait/Server.py", there is an error which shows that there is no such file "input.txt''.
Maybe you forget to upload this file.
Is it convenient for you to upload this ''input.txt'' again? Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.