#include "common.hpp"
#include "MediaSoupErrors.hpp"
#include "RTC/SCTP/packet/Chunk.hpp"
#include "RTC/SCTP/packet/chunks/AnyForwardTsnChunk.hpp"
#include "RTC/SCTP/packet/chunks/ForwardTsnChunk.hpp"
#include "test/include/RTC/SCTP/sctpCommon.hpp"
#include <catch2/catch_test_macros.hpp>
#include <cstring>
#include <vector>
SCENARIO("Forward Cumulative TSN Chunk (192)", "[serializable][sctp][chunk]")
{
sctpCommon::ResetBuffers();
SECTION("ForwardTsnChunk::Parse() succeeds")
{
alignas(4) uint8_t buffer[] =
{
0xC0, 0b00000000, 0x00, 0x10,
0x11, 0x22, 0x33, 0x44,
0x12, 0x34, 0x43, 0x21,
0x56, 0x78, 0x87, 0x65,
0xAA, 0xBB, 0xCC, 0xDD,
0xAA, 0xBB, 0xCC
};
auto* chunk = RTC::SCTP::ForwardTsnChunk::Parse(buffer, sizeof(buffer));
CHECK_SCTP_CHUNK(
chunk,
buffer,
sizeof(buffer),
16,
RTC::SCTP::Chunk::ChunkType::FORWARD_TSN,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::SKIP_AND_REPORT,
0b00000000,
false,
0,
false,
0);
REQUIRE(chunk->GetNewCumulativeTsn() == 287454020);
REQUIRE(chunk->GetNumberOfSkippedStreams() == 2);
REQUIRE(
chunk->GetSkippedStreams() == std::vector<RTC::SCTP::AnyForwardTsnChunk::SkippedStream>{
{ 4660, 17185 },
{ 22136, 34661 }
});
chunk->Serialize(sctpCommon::SerializeBuffer, sizeof(sctpCommon::SerializeBuffer));
std::memset(buffer, 0x00, sizeof(buffer));
CHECK_SCTP_CHUNK(
chunk,
sctpCommon::SerializeBuffer,
sizeof(sctpCommon::SerializeBuffer),
16,
RTC::SCTP::Chunk::ChunkType::FORWARD_TSN,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::SKIP_AND_REPORT,
0b00000000,
false,
0,
false,
0);
REQUIRE(chunk->GetNewCumulativeTsn() == 287454020);
REQUIRE(chunk->GetNumberOfSkippedStreams() == 2);
REQUIRE(
chunk->GetSkippedStreams() == std::vector<RTC::SCTP::AnyForwardTsnChunk::SkippedStream>{
{ 4660, 17185 },
{ 22136, 34661 }
});
auto* clonedChunk = chunk->Clone(sctpCommon::CloneBuffer, sizeof(sctpCommon::CloneBuffer));
std::memset(sctpCommon::SerializeBuffer, 0x00, sizeof(sctpCommon::SerializeBuffer));
delete chunk;
CHECK_SCTP_CHUNK(
clonedChunk,
sctpCommon::CloneBuffer,
sizeof(sctpCommon::CloneBuffer),
16,
RTC::SCTP::Chunk::ChunkType::FORWARD_TSN,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::SKIP_AND_REPORT,
0b00000000,
false,
0,
false,
0);
REQUIRE(clonedChunk->GetNewCumulativeTsn() == 287454020);
REQUIRE(clonedChunk->GetNumberOfSkippedStreams() == 2);
REQUIRE(
clonedChunk->GetSkippedStreams() == std::vector<RTC::SCTP::AnyForwardTsnChunk::SkippedStream>{
{ 4660, 17185 },
{ 22136, 34661 }
});
delete clonedChunk;
}
SECTION("ForwardTsnChunk::Parse() fails")
{
alignas(4) uint8_t buffer1[] =
{
0xC0, 0b00000000, 0x00, 0x0E,
0x11, 0x22, 0x33, 0x44,
0x12, 0x34, 0x43, 0x21,
0x56, 0x78, 0x87, 0x65,
};
REQUIRE(!RTC::SCTP::ForwardTsnChunk::Parse(buffer1, sizeof(buffer1)));
}
SECTION("ForwardTsnChunk::Factory() succeeds")
{
auto* chunk = RTC::SCTP::ForwardTsnChunk::Factory(
sctpCommon::FactoryBuffer, sizeof(sctpCommon::FactoryBuffer));
CHECK_SCTP_CHUNK(
chunk,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
8,
RTC::SCTP::Chunk::ChunkType::FORWARD_TSN,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::SKIP_AND_REPORT,
0b00000000,
false,
0,
false,
0);
REQUIRE(chunk->GetNewCumulativeTsn() == 0);
REQUIRE(chunk->GetNumberOfSkippedStreams() == 0);
REQUIRE(chunk->GetSkippedStreams().empty());
chunk->SetNewCumulativeTsn(1234);
chunk->AddSkippedStream(
RTC::SCTP::AnyForwardTsnChunk::SkippedStream{ 1111, 11110 });
chunk->AddSkippedStream(
RTC::SCTP::AnyForwardTsnChunk::SkippedStream{ 2222, 22220 });
chunk->AddSkippedStream(
RTC::SCTP::AnyForwardTsnChunk::SkippedStream{ 3333, 33330 });
CHECK_SCTP_CHUNK(
chunk,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
20,
RTC::SCTP::Chunk::ChunkType::FORWARD_TSN,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::SKIP_AND_REPORT,
0b00000000,
false,
0,
false,
0);
REQUIRE(chunk->GetNewCumulativeTsn() == 1234);
REQUIRE(chunk->GetNumberOfSkippedStreams() == 3);
REQUIRE(
chunk->GetSkippedStreams() == std::vector<RTC::SCTP::AnyForwardTsnChunk::SkippedStream>{
{ 1111, 11110 },
{ 2222, 22220 },
{ 3333, 33330 },
});
auto* parsedChunk = RTC::SCTP::ForwardTsnChunk::Parse(chunk->GetBuffer(), chunk->GetLength());
delete chunk;
CHECK_SCTP_CHUNK(
parsedChunk,
sctpCommon::FactoryBuffer,
20,
20,
RTC::SCTP::Chunk::ChunkType::FORWARD_TSN,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::SKIP_AND_REPORT,
0b00000000,
false,
0,
false,
0);
REQUIRE(parsedChunk->GetNewCumulativeTsn() == 1234);
REQUIRE(parsedChunk->GetNumberOfSkippedStreams() == 3);
REQUIRE(
parsedChunk->GetSkippedStreams() == std::vector<RTC::SCTP::AnyForwardTsnChunk::SkippedStream>{
{ 1111, 11110 },
{ 2222, 22220 },
{ 3333, 33330 },
});
delete parsedChunk;
}
}