Guus Sliepen [Sun, 15 Mar 2020 13:49:12 +0000 (14:49 +0100)]
Report initial ssthresh value as 0 while debugging.
The initial is actually UINT_MAX, but since this makes it hard to plot a
graph of it with autoscaling axes, show it as 0 instead. This removes the
hack where ssthresh is set to sndbuf.maxsize at the start of a connection,
which is wrong when the application overrides the send buffer size later.
Guus Sliepen [Sat, 14 Mar 2020 15:45:28 +0000 (16:45 +0100)]
Add better debugging output.
All messages from UTCP itself are now of the form:
timestamp srcport:dstport foo 123 bar 456 ...
The UNIX timestamp is wall clock time, to allow data from multiple
computers that are synchronised via NTP to be correlated.
Only part of the payload is now dumped by default to make the logs more
easily readable.
The test program now also adds the same format timestamp to its debug
messages.
Guus Sliepen [Sun, 8 Mar 2020 21:12:41 +0000 (22:12 +0100)]
Avoid sending packets smaller than the MTU if we don't need to.
If we have almost filled the congestion window but have more data in the
send buffer than we can send right now, wait until the congestion window
frees up to avoid sending small packets unnecessarily.
Guus Sliepen [Sun, 8 Mar 2020 20:52:23 +0000 (21:52 +0100)]
Always announce the receive window size as the size of the receive buffer.
Since UTCP requires the application to handle incoming in-sequence data
immediately, the start of the receive buffer is always right after the
last ACKed byte, so we can always announce the size of the receive buffer
as the maximum receive window size.
Guus Sliepen [Sun, 8 Mar 2020 20:09:25 +0000 (21:09 +0100)]
Add a benchmark script.
This script sets up two network namespaces connected via a veth tunnel with
the netem qdisc to simulate "realistic" network conditions.
It first uses socat to transmit data via regular TCP, then transmits the
same amount of data using the UTCP test program. It prints the time it took
for both methods, and stores a packet trace for both methods so it can be
analyzed.
Guus Sliepen [Sat, 8 Feb 2020 14:59:41 +0000 (15:59 +0100)]
Fix garbage being sent at start of UDP connection.
If utcp_send() was called right after utcp_connect_ex(..., UTCP_UDP),
and the handshake phase hadn't completed yet, we left some garbage in
the send buffer which wasn't cleared until two more calls to utcp_send()
were made.
Guus Sliepen [Mon, 14 Oct 2019 20:32:35 +0000 (22:32 +0200)]
Fix retransmission timeout calculation.
The RTO calculation was missing a factor 4 multiplication of the
RTT variance, which caused it to set the RTO to a much lower value than
specified by RFC 6298. This would result in more retranmissions and a
lower throughput.
Guus Sliepen [Thu, 10 Oct 2019 18:43:45 +0000 (20:43 +0200)]
Don't reset timers that were not set in utcp_reset_timers() and utcp_offline().
In utcp_reset_timers(), we were actually setting the connection timer even
if it was not set before, therefore causing spurious channel closures on
channels that did not have any unACKed data.
In utcp_offline(), we were setting the retransmission timer even if there
was nothing to retransmit.
Guus Sliepen [Sat, 5 Oct 2019 12:29:16 +0000 (14:29 +0200)]
Always send an ACK back when we receive data from the peer.
A previous ACK could get lost, causing the peer to resend data. If the
retransmission doesn't contain any new data, we would consider this data
to be outside our receive window, and then not resend our ACK.
- Drop data sent before the connection is established.
- Relax checks on incoming ACK seqnos
- Always consider all data ACKed
- Disregard hdr.seq when a FIN packet is received
- Don't ACK pure data packets
Add a function to manually start the connection timeout timers.
If the application knows the peer is offline, it can call utcp_offline().
This will start the connection timers on all connections to that peer.
This can be undone by marking the peer online again. This will also reset
the retransmission timers.
Guus Sliepen [Sun, 17 Mar 2019 19:57:43 +0000 (20:57 +0100)]
Check for astyle version 3 before formatting the code.
Unfortunately, code formatters change their behaviour between versions.
The code currently requires astyle version 3.x, so check this before
running astyle. If the wrong version is installed, print an error.
Guus Sliepen [Sun, 17 Mar 2019 19:54:19 +0000 (20:54 +0100)]
Add functions to get the amount of bytes in the send and receive buffers.
utcp_get_sendq() returns the amount of bytes in the send buffer, which
corresponds to the amount of bytes not yet ACKed by the peer.
utcp_get_recvq() returns the amount of bytes in the receive buffer,
which may or may not have been acked already, but have not been read by
the application.
Guus Sliepen [Mon, 25 Feb 2019 08:57:57 +0000 (09:57 +0100)]
Small fixes for utcp_abort_all_connections().
- Make utcp_reset_connection() a private function.
- Ensure we don't repeat any action when aborting a connection twice.
- Call the receive callback after resetting the connection, so the callback
function can safely call utcp_close().
SS Roop [Fri, 15 Feb 2019 05:27:32 +0000 (10:57 +0530)]
Add utcp_abort_all_connections function.
This adds a function to abort all open connections without invalidating
the utcp_connection_t handles. Its main purposes is when the application
knows communication with the peer is definitely not possible/desired anymore.
A RST packet will be sent to each connection's remote end, and the
receive callback will be invoked to indicate an error on each
connection.
Allow utcp_send() before a connection has been fully established.
This will put the data in the send buffer, and it will be sent when possible.
This also allows the socket to be shut down for writing before it has
reached the ESTABLISHED state.
Guus Sliepen [Mon, 2 Oct 2017 20:40:47 +0000 (22:40 +0200)]
Convert sizeof foo to sizeof(foo).
While technically sizeof is an operator and doesn't need the parentheses
around expressions it operates on, except if they are type names, code
formatters don't seem to handle this very well.
Guus Sliepen [Sun, 13 Aug 2017 15:43:48 +0000 (17:43 +0200)]
Allow timers to be reset.
The function utcp_reset_timers() will reset the retransmit timers of all
connections to zero, so they will fire immediately. The connection timeout will
be reset to the user timeout value, and if the RTO is larger than the
starting RTO, it will be set to the starting RTO.
Basically, never retransmit, and whatever we get we immediately pass up to
the application. The only thing we do handle the TCP way is the FIN packet.
This also introduces the use of the aux entry in the header. We know that
older versions of UTCP ignore this field, and also ignore any extra data
in SYN packets, so we can add anything here in a backwards-compatible way.
This takes an extra argument "flags", which can be used to change the type
of connection to create. Possible flags are UTCP_INORDER, UTCP_RELIABLE and
UTCP_FRAMED, which can be bitwise-or'd together, or UTCP_TCP or UTCP_UDP as
shortcuts for what is assumed will be common combinations of those flags.
Guus Sliepen [Thu, 17 Dec 2015 17:07:19 +0000 (18:07 +0100)]
Fix buffer resizing logic in buffer_put_at().
When growing the buffer when it's not big enough for new data, the
current size is doubled repeatedly until it is big enough for the new
data. The required new size is stored in the variable "required",
however the doubling loop exited when the new size was at least
buf->used + len, which might be much smaller than "required" if an
out-of-order packet is received.
Guus Sliepen [Mon, 19 Oct 2015 20:03:21 +0000 (22:03 +0200)]
Fix bug in retransmit().
The logic to check whether we actually have something to retransmit was
wrong, causing retransmit() to bail out early without setting or resetting
the timer. This also caused utcp_timeout() to return a negative value.
Guus Sliepen [Sun, 18 Oct 2015 18:30:48 +0000 (20:30 +0200)]
Fix the logic for determining whether a packets has an acceptable ack seqno.
snd.last accurately tracks the last possible seqno that can be acked, so
use it. This fixes a case where retransmitted ACKs of a FIN were not handled
correctly.
Guus Sliepen [Sun, 18 Oct 2015 18:24:50 +0000 (20:24 +0200)]
Measure RTT and calculate RTO.
Opportunistically measure RTT using only a single timer, without requiring
timestamps to be added to packets. Use the method described in RFC 6298 to
smoothly update the value of RTO.
Guus Sliepen [Sun, 18 Oct 2015 18:18:49 +0000 (20:18 +0200)]
Minor changes in the test program.
- Add one to the timeout in milliseconds, to prevent roundoff errors from
causing us to busy-loop unnecessarily.
- Log what we are polling for and what the timeout is.
Guus Sliepen [Sun, 18 Oct 2015 11:53:20 +0000 (13:53 +0200)]
Add a receive buffer.
The receive buffer kicks in the moment we get a packet which is out of order.
We store the packet in the buffer, and keep track of up to 4 ranges of bytes
of received data. When retransmission fills the first gap, we send all the
buffered data (up to the second gap if applicable) to the application.
4 byte ranges seems to be a good value for up to moderate (20%) packet loss.
This algorithm greatly reduces the amount of useless packets being sent.
A future improvement is sending the SACK information in the ACK packets,
so the congestion window can be kept large while avoiding packets being
resent unnecessarily.
Guus Sliepen [Sun, 11 Oct 2015 21:39:23 +0000 (23:39 +0200)]
Reset the snd.nxt pointer when starting packet retransmission.
When a packet was lost, and the send buffer contains more than two packets,
this only retransmitted the first packet from the send buffer, then when it
got acked it would continue with the tail of the buffer. Then it would have
to wait for another timeout to send the next packet from the start of the
send buffer. If the application is continuously sending data, then the send
buffer would never become empty and the problem would persist.
Guus Sliepen [Sun, 11 Oct 2015 15:02:37 +0000 (17:02 +0200)]
Handle direction argument of utcp_shutdown().
For TCP, only shutting down the send direction makes sense, however to
be compatible to the BSD sockets API, keep the direction argument, and
when someone tries to shut down the receive direction, just disable the
receive callback.
Note that on most operating systems, SHUT_RD actually doesn't do
anything at all, it won't prevent reads from returning data.
Also be a bit more strict, return EINVAL or ENOTCONN when appropriate.