PURE TCP/UDP Tasks/Server - PURE Protocol

This document describes the protocol used by the PURE TCP/UDP server and tasks.

TCP Protocol

The provided TCP tasks as well as the TCP Server use a simple protocol called ?PURE-TCP?. The protocol is modelled to be able simulate common TCP based protocols (such as FTP, SMTP, etc).

The messages (both request and responses) consist of one text line and an optional payload that simply consists of a number of bytes.

BNF notation

The following describes the PURE-TCP requests and responses in Augmented Backus?Naur Form:

request = cmd SPACE len CRLF [ payload ] cmd = "SEND" / "RETR" / "CLOSE" response = resp-code SPACE len CRLF [ payload ] resp-code = 1*DIGIT len = 1*DIGIT payload = len*OCTET

Requests

The request commands are:

Responses

The responses always includes a response code and an a length. If length is not 0, an payload is included with the specified length.

A response code of 0 indicates success any other response codes are error codes.

Examples

Client request: SEND 3 0x010 0x02 0x03 (ie 3 bytes) Server response: 0 0 Client request: RETR 5 Server response: 0 5 0x010 x02 0x03 0x54 oxA0 (ie 5 bytes) Client request:? CLOSE 0 Server response: 0 0

UDP Protocol

The provided UDP tasks as well as the UDP Server use a simple protocol called ?PURE-UDP?. The protocol is modelled to be able simulate common UDP based protocols.

Compared to the PURE-TCP protocol, the PURE-UDP protocol is somewhat more complicated. This due to the nature of UDP, being a non-reliable protocol, so to use it we must have reliability features at the application level to handle dropped packages as well as being able to count packages delivered out of order.

UDP Datagram

A UDP message is contained within a UDP datagram and has the following layout:

Message Types:

Control Messages

The Payload for CTRL messages include control messages similar as the PURE-TCP protocol. I.e

request = cmd SPACE len SPACE no-of-packages cmd = "SEND" / "RETR" / "CLOSE" response = resp-code SPACE len SPACE no-of-packages resp-code = 1*DIGIT len = 1*DIGIT no-of-packages = 1*DIGIT

The command (cmd) is basically the same as for PURE-TCP. The main difference is that we specify number of expected packages to be transmitted. This allows the receiver to calculate package loss.

Acknowledged messages

In order to know if CTRL message has arrived to its destination, it must be acknowledged by the receiver. The sender is storing the message in its memory as long as it is waiting for acknowledge. Once it gets acknowledged, the message can be discarded. In case the message is not acknowledged during some period of time, it can (optionally) be retransmitted.

Non-acknowledged messages

DATA_NOACK messages are transferred without being acknowledged by the receiver. The receiver will only record received DATA_NOACK messages and count number of missing packages. This is based on that a CTRL message has previously been used to inform the receiver about the number of expected DATA_NOACK messages.

Examples

Send simple UDP message, with a 256 byte payload:

Client send: CTRL Payload: "SEND 256 1" Server response: ACK Client send: DATA_NOACK Payload: <256 bytes>

An example where multiple packages is used to transfer 4096 bytes, using 4 packages:

Client send: CTRL Payload: "SEND 4096 4" Server response: ACK Payload: "0 0 0" Client send: DATA_NOACK Payload: <1024 bytes> DATA_NOACK Payload: <1024 bytes> DATA_NOACK Payload: <1024 bytes> DATA_NOACK Payload: <1024 bytes>

Similar, but retrieving data:

Client send: CTRL Payload: "RETR 4096 0" Server response: ACK Payload: "0 4096 4" Server send: DATA_NOACK Payload: <1024 bytes> DATA_NOACK Payload: <1024 bytes> DATA_NOACK Payload: <1024 bytes> DATA_NOACK Payload: <1024 bytes>