Commit graph

18 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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