Commit graph

43 commits

Author SHA1 Message Date
Victor Boivie
21509566b8 dcsctp: Add Transmission Control Block
This is merely a container of components that have their lifetime
bound to when the socket is connected. If the socket gets disconnected
or restarted, this object (and everything it holds) will be released.

Bug: webrtc:12614
Change-Id: Ibd75760b7bf7efe9c26c4eb7cee62de8bba5410c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214340
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33869}
2021-04-28 22:45:03 +00:00
Victor Boivie
5d3bda58fd dcsctp: Add timer safeguards and sanity checks
Ensuring that timer durations never go beyond a safe maximum duration
and that timer IDs are not re-used.

Bug: webrtc:12614
Change-Id: I227a2e9933da16669dc6ea0a39c570892010ba2c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215063
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33860}
2021-04-28 06:58:29 +00:00
Victor Boivie
322f911c10 dcsctp: Add Stream Reset Handler
The Stream Reset handler handles a limited subset of RFC6525, but all
the parts necessary to implement "Closing a Data Channel", which is done
by sending an Outgoing SSN Reset Request.

There can only be a single "Stream Reconfiguration Request" on the wire
at any time, so requests are queued and sent when a previous request -
if any - finishes. Resetting a stream is an asynchronous operation and
the receiver will not perform the stream resetting until it can be done,
which is when the currently partly received message has been fully
received. And the sender will not send a request until the currently
fragmented message (on that stream) is still sent.

There are numerous callbacks to make the client know what's really
happening as these callbacks will result in Data Channel events.

Bug: webrtc:12614
Change-Id: I9fd0a94713f0c1fc384d1189f3894e87687408b7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214131
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33856}
2021-04-27 21:08:56 +00:00
Victor Boivie
a866228db1 dcsctp: Use third_party/crc32c for integrity check
CRC32c is used in SCTP for integrity checking, and the
third_party/crc32c library (https://github.com/google/crc32c) which has
been optimized for SSE42 and arm64 and has a much faster fallback
implementation for other architectures.

Running ./out/Release/dcsctp_benchmark
Run on (12 X 4500 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x6)
  L1 Instruction 32 KiB (x6)
  L2 Unified 1024 KiB (x6)
  L3 Unified 8448 KiB (x1)
Load Average: 11.01, 17.53, 17.11
------------------------------------------------------------------------------
Benchmark                    Time             CPU   Iterations UserCounters...
------------------------------------------------------------------------------
BM_PumpData/1              676 ns          676 ns      1034087 bytes_per_second=1.41063M/s items_per_second=1.47916M/s
BM_PumpData/8              671 ns          671 ns      1041809 bytes_per_second=11.3643M/s items_per_second=1.48955M/s
BM_PumpData/128            725 ns          725 ns       967170 bytes_per_second=168.398M/s items_per_second=1.37952M/s
BM_PumpData/512            800 ns          800 ns       873854 bytes_per_second=610.125M/s items_per_second=1.24954M/s
BM_PumpData/1024           911 ns          911 ns       775785 bytes_per_second=1072.2M/s items_per_second=1097.93k/s
BM_PumpData/2048          1988 ns         1988 ns       352444 bytes_per_second=982.409M/s items_per_second=502.993k/s
BM_PumpData/4096          3893 ns         3893 ns       179999 bytes_per_second=1003.31M/s items_per_second=256.848k/s
BM_PumpData/8192          7477 ns         7477 ns        92790 bytes_per_second=1044.88M/s items_per_second=133.745k/s
BM_PumpData/65536        97156 ns        97153 ns         7089 bytes_per_second=643.318M/s items_per_second=10.2931k/s
BM_EchoServer/1            634 ns          634 ns      1130860 bytes_per_second=1.50512M/s items_per_second=1.57823M/s
BM_EchoServer/8            614 ns          614 ns      1136372 bytes_per_second=12.4286M/s items_per_second=1.62904M/s
BM_EchoServer/128          644 ns          644 ns      1073464 bytes_per_second=189.618M/s items_per_second=1.55335M/s
BM_EchoServer/512          734 ns          734 ns       949487 bytes_per_second=665.181M/s items_per_second=1.36229M/s
BM_EchoServer/1024         836 ns          836 ns       838010 bytes_per_second=1.14046G/s items_per_second=1.19586M/s
BM_EchoServer/2048        1939 ns         1939 ns       345067 bytes_per_second=1007.27M/s items_per_second=515.724k/s
BM_EchoServer/4096        3984 ns         3983 ns       176047 bytes_per_second=980.737M/s items_per_second=251.069k/s
BM_EchoServer/8192        7486 ns         7484 ns        95780 bytes_per_second=1043.85M/s items_per_second=133.613k/s
BM_EchoServer/65536      92360 ns        92346 ns         7821 bytes_per_second=676.805M/s items_per_second=10.8289k/s

No-Presubmit: True
Bug: webrtc:12614
Change-Id: Iff21035ee78b263ee0e4b0fe3d07eea24064b921
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215002
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33842}
2021-04-27 10:12:44 +00:00
Victor Boivie
03e912abaf dcsctp: Add Retransmission Queue
The Retransmission Queue contain all message fragments (DATA chunks)
that have once been sent, but not yet ACKed by the receiver. It will
process incoming SACK chunks, which informs it which chunks that the
receiver has seen (ACKed) and which that are lost (NACKed), and will
retransmit chunks when it's time.

If a message has been sent with partial reliability, e.g. to have a
limited number of retransmissions or a limited lifetime, the
Retransmission Queue may discard a partially sent and expired message
and will instruct the receiver that "don't expect this message - it's
expired" by sending a FORWARD-TSN chunk.

This currently also includes the congestion control algorithm as it's
tightly coupled with the state of the retransmission queue. This is
a fairly complicated piece of logic which decides how much data that
can be in-flight, depending on the available bandwidth. This is not done
by any bandwidth estimation, but similar to TCP, where data is sent
until it's lost, and then "we dial down a knob" and take it more
carefully from here on.

Future refactoring will try to separate the logic regarding fragment
retransmission and the congestion control algorithm.

Bug: webrtc:12614
Change-Id: I8678250abb766e567c3450634686919936ea077b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214046
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33833}
2021-04-26 14:58:21 +00:00
Victor Boivie
27e50ccf4c dcsctp: Add Retransmission Timeout
The socket can measure the round-trip-time (RTT) by two different
scenarios:
  * When a sent data is ACKed
  * When a HEARTBEAT has been sent, which as been ACKed.

The RTT will be used to calculate which timeout value that should be
used for e.g. the retransmission timer (T3-RTX). On connections with a
low RTT, the RTO value will be low, and on a connection with high RTT,
the RTO value will be high. And on a connection with a generally low
RTT value, but where it varies a lot, the RTO value will be calculated
to be fairly high, to not fire unnecessarily. So jitter is bad, and is
part of the calculation.

Bug: webrtc:12614
Change-Id: I64905ad566d5032d0428cd84143a9397355bbe9f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214045
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33832}
2021-04-26 13:48:41 +00:00
Victor Boivie
b9bdf64b92 dcsctp: Add Heartbeat Handler
It's responsible for answering incoming Heartbeat Requests, and to
send requests itself when a connection is idle. When it receives
a response, it will measure the RTT and if it doesn't receive a response
in time, that will result in a TX error, which will eventually close
the connection.

Bug: webrtc:12614
Change-Id: I08371d9072ff0461f60e0a2f7696c0fd7ccb57c5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214129
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33828}
2021-04-25 20:40:18 +00:00
Victor Boivie
f8476cc02c dcsctp: Add Retransmission Error Counter
This is just a simple SCTP variable, but wrapped in its own object
for convenience.

Bug: webrtc:12614
Change-Id: I0c45c356488d21b71c72a936e4ceeee5ed0ec96d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214047
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33827}
2021-04-25 18:28:31 +00:00
Victor Boivie
e1d60b0b58 dcsctp: Add Context
In the Socket module, there are a few (two, to be exact right now, but
the goal is to have even more) separate "handlers" that are responsible
for a feature set. These handlers must have an API to interact with
the rest of the socket - and this is the API.

Mocks are also added.

Bug: webrtc:12614
Change-Id: If19b43bf99a784bba3a42467d0ed3abdd8b4c62c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214128
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33826}
2021-04-25 17:43:08 +00:00
Victor Boivie
5ec1d0b25c dcsctp: Add missing test
This was missing in the build file, and caught in post-review at:
https://webrtc-review.googlesource.com/c/src/+/213347

Bug: webrtc:12614
Change-Id: I1870c1e305913b2195df801487b99549b02b2558
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215065
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33824}
2021-04-25 15:18:48 +00:00
Victor Boivie
762f21ce8d dcsctp: Add Send Queue
When the client asks for a message to be sent, it's put in the
SendQueue, which is available even when the socket is not yet connected.

When the socket is connected, those messages will be sent on the wire,
possibly fragmented if the message is large enough to not fit inside a
single packet. When the message has been fully sent, it's removed from
the send queue (but it will be in the RetransmissionQueue - which is
added in a follow-up change, until the message has been ACKed).

The Send Queue is a FIFO queue in this iteration, and in SCTP, that's
called a "First Come, First Served" queue, or FCFS. In follow-up work,
the queue and the actual scheduling algorithm which decides which
message that is sent, when there are messages in multiple streams, will
likely be decoupled. But in this iteration, they're in the same class.

Bug: webrtc:12614
Change-Id: Iec1183e625499a21e402e4f2a5ebcf989bc5c3ec
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214044
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33798}
2021-04-21 10:05:53 +00:00
Victor Boivie
49bec37d9b dcsctp: Log integers as unsigned
Bug: webrtc:12614
Change-Id: I08fa2d43671972a3115c09228a9cd089a53c5c89
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214341
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33790}
2021-04-20 14:04:50 +00:00
Victor Boivie
0e73602a9f dcsctp: Merge ReconfigResponseSN/ReconfigRequestSN
Adding strong types went a little too far as these two types represent
the same sequence number. A "request sequence number" is a number, that
- when responded to - will be used as "response sequence number".

Having them separate added confusion and just a lot of type-casting.

Bug: webrtc:12614
Change-Id: I4636ea8f2252023a2d5a9b7033763e1978b1812e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214130
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33789}
2021-04-20 13:48:37 +00:00
Victor Boivie
0b0afaa81a dcsctp: Add Chunk Validators
The SCTP RFCs aren't very strict in specifying when a chunk or parameter
is invalid, so most chunks and/or parameters must be accepted but they
may need some cleaning to avoid a lot of error handling deeper in the
chunk handling code.

Bug: webrtc:12614
Change-Id: I723f08cbdc26e1a1b78463b6137340e638089037
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214966
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33788}
2021-04-20 13:37:22 +00:00
Victor Boivie
59d6e2a19e dcsctp: Add test for StrongAlias<bool> as bool
This test verifies that a StrongAlias<bool> can be evaluated as
a boolean without dereferencing it. Note that this is not the case
for StrongAlias<int>, for example, as that wouldn't even compile. Which
is quite good.

Bug: webrtc:12614
Change-Id: I67329364721fe0354d78daac1233254035454c03
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215686
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33787}
2021-04-20 13:36:17 +00:00
Florent Castelli
b4ced39b93 dcsctp: Add OWNERS file
Bug: webrtc:12614
Change-Id: I4a2523f4923ebac59f01e3c7d0e7e9767294c1a6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215683
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Florent Castelli <orphis@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33783}
2021-04-20 10:42:58 +00:00
Victor Boivie
78aa5cd359 dcsctp: Ensure packet size doesn't exceed MTU
Due to a previous refactoring, the SCTP packet header is only added when
the first chunk is written. This wasn't reflected in the
`bytes_remaining`, which made it add more than could fit within the MTU.

Additionally, the maximum packet size must be even divisible by four as
padding will be added to chunks that are not even divisble by four (up
to three bytes of padding). So compensate for that.

Bug: webrtc:12614
Change-Id: I6b57dfbf88d1fcfcbf443038915dd180e796191a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215145
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33760}
2021-04-16 14:42:44 +00:00
Victor Boivie
9861f960c3 dcsctp: Add operators on TimeMs and DurationMs
To be able to use them type-safely, they should support native
operators (e.g. adding a time and a duration, or subtracting two time
values), as the alternative is to manage them as numbers.

Yes, this makes them behave a bit like absl::Time/absl::Duration.

Bug: webrtc:12614
Change-Id: I4dea12e33698a46e71fb549f44c06f2f381c9201
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215143
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33725}
2021-04-14 09:21:15 +00:00
Victor Boivie
c54f6722ce dcsctp: Fix post-review comments for DataTracker
These are some fixes that were added after submission of
https://webrtc-review.googlesource.com/c/src/+/213664

Mainly:

 * Don't accept TSNs that have a too large difference from expected
 * Renaming of member variable (to confirm to style guidelines)

Bug: webrtc:12614
Change-Id: I06e11ab2acf5d307b68c3cbc135fde2c038ee690
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215070
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33721}
2021-04-14 07:54:06 +00:00
Victor Boivie
250fbb3c48 dcsctp: Make Sequence Number API more consistent
* `AddTo` and `Difference` are made into static methods, as one may have
  believed that these modified the current object previously. The
  `Increment` method is kept, as it's obvious that it modifies the
  current object as it doesn't have a return value, and `next_value` is
  kept, as its naming (lower-case, snake) indicates that it's a simple
  accessor.
* Difference will return the absolute difference. This is actually the
  only reasonable choice, as the return value was unsigned and any
  negative value would just wrap.

Bug: webrtc:12614
Change-Id: If14a71636e67fc612d12759dc80a9c2518c85281
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215069
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33714}
2021-04-13 18:35:25 +00:00
Florent Castelli
1fded2f5ad dcsctp: Fix build dependencies
Adding fuzzers to the build made "gn gen --check" discover a lot
of dependency errors between various components of dcSCTP.

Bug: webrtc:12614
Change-Id: I0b2dd7321aec2624da417f413c727bd11b4743e5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215003
Commit-Queue: Florent Castelli <orphis@webrtc.org>
Reviewed-by: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33705}
2021-04-13 10:14:00 +00:00
Victor Boivie
606bd6d163 dcsctp: Use correct field width for PPID
When migrating to use StrongAlias types, the PPID was incorrectly
modeled as an uint16_t instead of a uint32_t, as it was prior to using
StrongAlias. Most likely a copy-paste error from StreamID.

As the Data Channel PPIDs are in the range of 51-57, it was never caught
in tests.

Bug: webrtc:12614
Change-Id: I2b61ef7935df1222068e7f4e70fc2aaa532dcf7b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214960
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33687}
2021-04-12 09:28:48 +00:00
Victor Boivie
9d60936048 dcsctp: Fix relative dependency paths in timer/
Bug: webrtc:12614
Change-Id: I50cd2e5beae516e4a1ba47626d835eb9c80dffcb
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214965
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33686}
2021-04-12 08:25:49 +00:00
Mirko Bonadei
55de2926a8 Use relative paths for //net/dcsctp/public:socket.
Quick fix for Chromium fuzzer builds, for example
https://ci.chromium.org/ui/p/chromium/builders/try/win-libfuzzer-asan-rel/b8850210174432806976/overview.

Bug: None
Change-Id: Id43269f58ccc976a694fbf1cef2721f654f95e62
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214962
Reviewed-by: Victor Boivie <boivie@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33682}
2021-04-12 07:14:33 +00:00
Victor Boivie
cb70aa7e05 dcsctp: Add Reassembly Queue
The Reassembly Queue receives fragmented messages (DATA or I-DATA
chunks) and - with help of stream reassemblers - will reassemble these
fragments into messages, which will be delivered to the client.

It also handle partial reliability (FORWARD-TSN) and stream resetting.

To avoid a DoS attack vector, where a sender can send fragments in a way
that the reassembly queue will never succeed to reassemble a message and
use all available memory, the ReassemblyQueue has a maximum size.

Bug: webrtc:12614
Change-Id: Ibb084fecd240d4c414e096579244f8f5ee46914e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214043
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33678}
2021-04-11 19:59:49 +00:00
Victor Boivie
8a13d2ca9f dcsctp: Add Traditional Reassembly Streams
This class handles the assembly of fragmented received messages (as DATA
chunks) and manage per-stream queues. This class only handles
non-interleaved messages as described in RFC4960, and is not used when
message interleaving is enabled on the association, as described in
RFC8260.

This is also only part of the reassembly - a follow-up change will add
the ReassemblyQueue that handle the other part as well. And an even
further follow-up change will add a "interleaved reassembly stream".

Bug: webrtc:12614
Change-Id: Iaf339fa215a2b14926f5cb74f15528392e273f99
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214042
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33677}
2021-04-11 19:20:58 +00:00
Victor Boivie
b2d539be6b dcsctp: Add Data Tracker
The Data Tracker's purpose is to keep track of all received DATA chunks
and to ACK/NACK that data, by generating SACK chunks reflecting its view
of what has been received and what has been lost.

It also contains logic for _when_ to send the SACKs, as that's different
depending on e.g. packet loss. Generally, SACKs are sent every second
packet on a connection with no packet loss, and can also be sent on a
delayed timer.

In case partial reliability is used, and the transmitter has decided
that some data shouldn't be retransmitted, it will send a FORWARD-TSN
chunk, which this class also handles, by "forgetting" about those
chunks.

Bug: webrtc:12614
Change-Id: Ifafb0c211f6a47872e81830165ab5fc43ee7f366
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213664
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33676}
2021-04-11 18:37:50 +00:00
Victor Boivie
5f4ac67c7b dcsctp: Add Data Generator
The Data Generator is a testonly library for generating
Data with correct sequence numbers.

Bug: webrtc:12614
Change-Id: Ifc04dfd14d858d905312ffed13e8905c23d59923
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214041
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33667}
2021-04-09 09:53:34 +00:00
Victor Boivie
6fa0cfa4dd dcsctp: Add Timer and TimerManager
Timer is a high-level timer (in contrast to the low-level `Timeout`
class). Timers are started and can be stopped or restarted. When a timer
expires, the provided callback will be triggered.

Timers can be configured to do e.g. exponential backoff when they expire
and how many times they should be automatically restarted.

Bug: webrtc:12614
Change-Id: Id5eddd58dd0af62184b10dd1f98e3e886e3f1d50
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213350
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33666}
2021-04-09 07:48:50 +00:00
Victor Boivie
10aaa3f1e7 dcsctp: Fixed parameter name typo
Late review comments from
https://webrtc-review.googlesource.com/c/src/+/213180

Bug: webrtc:12614
Change-Id: I61471902b50c6a08092a1fa9d3a03202c95177d0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214486
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33665}
2021-04-09 07:39:50 +00:00
Victor Boivie
58fa1bac03 dcsctp: Enforce variable length TLV minimum length
The length field was validated to not be too big, or to have too much
padding, but it could be smaller than the fixed size of the chunk, which
isn't correct. Now it's enforced to be at minimum the size of the fixed
size header.

Bug: webrtc:12614
Change-Id: I57089a5ba2854eeb63ab3b4e28cf5878087d06e8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214484
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33659}
2021-04-08 15:33:16 +00:00
Victor Boivie
ca7412d937 dcsctp: Avoid infinite loops on zero-length chunks
Every chunk should be at least 4 bytes to be valid - that's the size of
the chunk header. If the embedded length was zero (0), iterating over
the chunks would never complete. Fixed now.

Bug: webrtc:12614
Change-Id: I1cbd070ad34a51584f6b09c5364c3db1b2bcdc2e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214483
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33658}
2021-04-08 15:15:16 +00:00
Victor Boivie
83c726f3e5 dcsctp: UnwrappedSequenceNumber use StrongAlias
As this library will only use StrongAlias types for all its
sequence numbers, the UnwrappedSequenceNumber class should use those
types and not the primitive underlying types (e.g. uint32_t).

This makes e.g. Unwrap() return a strong type, which is preferred.

Bug: webrtc:12614
Change-Id: Icd0900c643a1988d1a3bbf49d87b4d4d1bbfbf1f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213663
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33651}
2021-04-08 09:44:14 +00:00
Victor Boivie
471fc8c329 dcsctp: Add SCTP packet
This represents the wire encoding/decoding of SCTP packets.

Bug: webrtc:12614
Change-Id: Id7a4e4654f29eea126ea3058333f5c625606446b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213349
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33650}
2021-04-08 09:25:44 +00:00
Victor Boivie
628d91cd0d dcsctp: Add public API
Clients will use this API for all their interactions with this library.
It's made into an interface (of which there will only be a single
implementation) simply for documentation purposes. But that also allows
clients to mock the library if wanted or to have a thread-safe wrapper,
as the library itself is not thread-safe, while keeping the same
interface.

Bug: webrtc:12614
Change-Id: I346af9916e26487da040c01825c2547aa7a5d0b7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213348
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33648}
2021-04-08 08:53:44 +00:00
Victor Boivie
b87746b155 dcsctp: Add parameters, error causes and chunks
Quite a large commit, but mostly trivial. It adds all the (in dcSCTP)
supported parameters, error causes and chunks as an object model, with
serializers and deserializers. They are verified with packet captures
where available, that have been captured with Wireshark against a
reference implementation.

This _could_ be split in parameter/ as one commit, error_cause/ in the
following, and chunk/ as the third, but as each chunk/parameter is
completely isolated from the other, reviewing it should be linear with
the number of chunks/parameters and having them in more commits wouldn't
change that, taken all those three commits into account.

Bug: webrtc:12614
Change-Id: Ie83c9a22cae6e3a39e35ef26fd532837a6387a08
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213347
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33625}
2021-04-06 10:28:18 +00:00
Victor Boivie
a865519e17 dcsctp: Add strong typed identifiers
There are numerous identifiers and sequences in SCTP, all of them being
unsigned 16 or 32-bit integers.

  * Stream identifiers
  * Payload Protocol Identifier (PPID)
  * Stream Sequence Numbers (SSN)
  * Message Identifiers (MID)
  * Fragment Sequence Numbers (FSN)
  * Transmission Sequence Numbers (TSN)

The first two of these are publicly exposed in the API, and the
remaining ones are never exposed to the client and are all part of SCTP
protocol.

Then there are some more not as common sequence numbers, and some
booleans. Not all will be in internal_types.h - it depends on if they
can be scoped to a specific component instead. And not all types will
likely become strong types.

The unwrapped sequence numbers have been renamed to not cause conflicts
and the current UnwrappedSequenceNumber class doesn't support wrapping
strongly typed integers as it can't reach into the type of the
underlying integer. That's something to explore later.

Bug: webrtc:12614
Change-Id: I4e0016be26d5d4826783d6e0962044f56cbfa97d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213422
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33620}
2021-04-02 21:38:13 +00:00
Victor Boivie
a4d5e24c11 dcsctp: Added common utilities
These are quite generic utilities that are used by multiple modules
within dcSCTP. Some would be good to have in rtc_base and are simple
replicas of utilities available in abseil.

Bug: webrtc:12614
Change-Id: I9914286ced7317a34628a71697da9149d6d19d38
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213190
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33609}
2021-04-01 05:45:34 +00:00
Victor Boivie
5457ec05b4 dcsctp: Add data container
Represents data that is either received and extracted from a
DATA/I-DATA chunk, or data that is supposed to be sent, and
wrapped in a DATA/I-DATA chunk (depending on peer capabilities).

Bug: webrtc:12614
Change-Id: Iea831fa7ca939783a438f178740508e484920312
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213346
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33608}
2021-03-31 18:25:38 +00:00
Victor Boivie
f53127af34 dcsctp: Adding testing macros
This is the first and last macro that will go into this project,
but it's really useful to verify that a call returns an optional
value (that is non-nullopt) and that extracts the underlying type.

Bug: webrtc:12614
Change-Id: I0a05bf22466a575dbcc9a8f7b88dde0f55ff54d9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213345
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33607}
2021-03-31 15:28:23 +00:00
Victor Boivie
fe6c819b31 dcsctp: Add CRC32C generator
Implemented from RFC4960 with test vectors from RFC3720.

Bug: webrtc:12614
Change-Id: If03a41d1ac4acecc3e5840c015878df271b14a1b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213344
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33606}
2021-03-31 15:02:02 +00:00
Victor Boivie
3dffa81541 dcsctp: Add TLV trait
Various entities in SCTP are padded data blocks, with a type and
length field at fixed offsets, all stored in a 4-byte header. This is
called the Type-Length-Value format, or TLV for short.

See e.g. https://tools.ietf.org/html/rfc4960#section-3.2 and
https://tools.ietf.org/html/rfc4960#section-3.2.1

This templated class, which is used as a trait[1], is configurable -
a struct passed in as template parameter.

[1] https://en.wikipedia.org/wiki/Trait_(computer_programming)

Bug: webrtc:12614
Change-Id: I52c2b5056931aba5fb23419406314136b5a4f650
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213180
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33602}
2021-03-31 12:52:38 +00:00
Victor Boivie
7d3c49a171 dcsctp: Add bounded byte reader and writer
Packets, chunks, parameters and error causes - the SCTP entities
that are sent on the wire - are buffers with fields that are stored
in big endian and that generally consist of a fixed header size, and
a variable sized part, that can e.g. be encoded sub-fields or
serialized strings.

The BoundedByteReader and BoundedByteWriter utilities make it easy
to read those fields with as much aid from the compiler as possible,
by having compile-time assertions that fields are not accessed
outside the buffer's span.

There are some byte reading functionality already in modules/rtp_rtcp,
but that module would be a bit unfortunate to depend on, and doesn't
have the compile time bounds checking that is the biggest feature of
this abstraction of an rtc::ArrayView.

Bug: webrtc:12614
Change-Id: I9fc641aff22221018dda9add4e2c44853c0f64f0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/212967
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33597}
2021-03-31 08:27:37 +00:00