dcsctp: Calculate next_tsn

Before this CL, the next_tsn was stored as a variable, but that was
not needed as it can be calculated from the higest outstanding TSN. The
next TSN is simply the value after the highest outstanding TSN.

The highest outstanding TSN calculation could be simplified as well,
as the outstanding_data_ is contiguous list of TSNs counted from
last_cumulative_tsn_ack_.

Bug: None
Change-Id: Iafe188683427b5f2959d5ce2b19b5943d4760791
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/329421
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41303}
This commit is contained in:
Victor Boivie 2023-12-01 19:48:10 +01:00 committed by WebRTC LUCI CQ
parent 2ca1d0f809
commit 032805068c
4 changed files with 10 additions and 28 deletions

View File

@ -97,11 +97,6 @@ bool OutstandingData::IsConsistent() const {
}
}
if (outstanding_data_.empty() &&
next_tsn_ != last_cumulative_tsn_ack_.next_value()) {
return false;
}
return actual_outstanding_bytes == outstanding_bytes_ &&
actual_outstanding_items == outstanding_items_ &&
actual_combined_to_be_retransmitted == combined_to_be_retransmitted;
@ -275,12 +270,11 @@ void OutstandingData::AbandonAllFor(const Item& item) {
// skipped over). So create a new fragment, representing the end, that the
// received will never see as it is abandoned immediately and used as cum
// TSN in the sent FORWARD-TSN.
UnwrappedTSN tsn = next_tsn_;
next_tsn_.Increment();
Data message_end(item.data().stream_id, item.data().ssn, item.data().mid,
item.data().fsn, item.data().ppid, std::vector<uint8_t>(),
Data::IsBeginning(false), Data::IsEnd(true),
item.data().is_unordered);
UnwrappedTSN tsn = next_tsn();
Item& added_item =
outstanding_data_
.emplace(std::piecewise_construct, std::forward_as_tuple(tsn),
@ -394,8 +388,8 @@ void OutstandingData::ExpireOutstandingChunks(Timestamp now) {
}
UnwrappedTSN OutstandingData::highest_outstanding_tsn() const {
return outstanding_data_.empty() ? last_cumulative_tsn_ack_
: outstanding_data_.rbegin()->first;
return UnwrappedTSN::AddTo(last_cumulative_tsn_ack_,
outstanding_data_.size());
}
absl::optional<UnwrappedTSN> OutstandingData::Insert(
@ -405,13 +399,11 @@ absl::optional<UnwrappedTSN> OutstandingData::Insert(
MaxRetransmits max_retransmissions,
Timestamp expires_at,
LifecycleId lifecycle_id) {
UnwrappedTSN tsn = next_tsn_;
next_tsn_.Increment();
// All chunks are always padded to be even divisible by 4.
size_t chunk_size = GetSerializedChunkSize(data);
outstanding_bytes_ += chunk_size;
++outstanding_items_;
UnwrappedTSN tsn = next_tsn();
auto it = outstanding_data_
.emplace(std::piecewise_construct, std::forward_as_tuple(tsn),
std::forward_as_tuple(message_id, data.Clone(),
@ -542,16 +534,12 @@ IForwardTsnChunk OutstandingData::CreateIForwardTsn() const {
std::move(skipped_streams));
}
void OutstandingData::ResetSequenceNumbers(UnwrappedTSN next_tsn,
UnwrappedTSN last_cumulative_tsn) {
void OutstandingData::ResetSequenceNumbers(UnwrappedTSN last_cumulative_tsn) {
RTC_DCHECK(outstanding_data_.empty());
RTC_DCHECK(next_tsn_ == last_cumulative_tsn_ack_.next_value());
RTC_DCHECK(next_tsn == last_cumulative_tsn.next_value());
next_tsn_ = next_tsn;
last_cumulative_tsn_ack_ = last_cumulative_tsn;
}
void OutstandingData::BeginResetStreams() {
stream_reset_breakpoint_tsns_.insert(next_tsn_);
stream_reset_breakpoint_tsns_.insert(next_tsn());
}
} // namespace dcsctp

View File

@ -75,11 +75,9 @@ class OutstandingData {
OutstandingData(
size_t data_chunk_header_size,
UnwrappedTSN next_tsn,
UnwrappedTSN last_cumulative_tsn_ack,
std::function<bool(StreamID, OutgoingMessageId)> discard_from_send_queue)
: data_chunk_header_size_(data_chunk_header_size),
next_tsn_(next_tsn),
last_cumulative_tsn_ack_(last_cumulative_tsn_ack),
discard_from_send_queue_(std::move(discard_from_send_queue)) {}
@ -122,7 +120,9 @@ class OutstandingData {
return last_cumulative_tsn_ack_;
}
UnwrappedTSN next_tsn() const { return next_tsn_; }
UnwrappedTSN next_tsn() const {
return highest_outstanding_tsn().next_value();
}
UnwrappedTSN highest_outstanding_tsn() const;
@ -160,8 +160,7 @@ class OutstandingData {
bool ShouldSendForwardTsn() const;
// Sets the next TSN to be used. This is used in handover.
void ResetSequenceNumbers(UnwrappedTSN next_tsn,
UnwrappedTSN last_cumulative_tsn);
void ResetSequenceNumbers(UnwrappedTSN last_cumulative_tsn);
// Called when an outgoing stream reset is sent, marking the last assigned TSN
// as a breakpoint that a FORWARD-TSN shouldn't cross.
@ -342,8 +341,6 @@ class OutstandingData {
// The size of the data chunk (DATA/I-DATA) header that is used.
const size_t data_chunk_header_size_;
// Next TSN to used.
UnwrappedTSN next_tsn_;
// The last cumulative TSN ack number.
UnwrappedTSN last_cumulative_tsn_ack_;
// Callback when to discard items from the send queue.

View File

@ -48,7 +48,6 @@ class OutstandingDataTest : public testing::Test {
OutstandingDataTest()
: gen_(MID(42)),
buf_(DataChunk::kHeaderSize,
unwrapper_.Unwrap(TSN(10)),
unwrapper_.Unwrap(TSN(9)),
on_discard_.AsStdFunction()) {}

View File

@ -86,7 +86,6 @@ RetransmissionQueue::RetransmissionQueue(
send_queue_(send_queue),
outstanding_data_(
data_chunk_header_size_,
tsn_unwrapper_.Unwrap(my_initial_tsn),
tsn_unwrapper_.Unwrap(TSN(*my_initial_tsn - 1)),
[this](StreamID stream_id, OutgoingMessageId message_id) {
return send_queue_.Discard(stream_id, message_id);
@ -621,7 +620,6 @@ void RetransmissionQueue::RestoreFromState(
partial_bytes_acked_ = state.tx.partial_bytes_acked;
outstanding_data_.ResetSequenceNumbers(
tsn_unwrapper_.Unwrap(TSN(state.tx.next_tsn)),
tsn_unwrapper_.Unwrap(TSN(state.tx.next_tsn - 1)));
}
} // namespace dcsctp