#include "common.hpp"
#include "MediaSoupErrors.hpp"
#include "RTC/SCTP/packet/Chunk.hpp"
#include "RTC/SCTP/packet/chunks/AnyForwardTsnChunk.hpp"
#include "RTC/SCTP/packet/chunks/IForwardTsnChunk.hpp"
#include "test/include/RTC/SCTP/sctpCommon.hpp"
#include <catch2/catch_test_macros.hpp>
#include <cstring>
#include <vector>
SCENARIO("I-Forward Cumulative TSN Chunk (194)", "[serializable][sctp][chunk]")
{
sctpCommon::ResetBuffers();
SECTION("IForwardTsnChunk::Parse() succeeds")
{
alignas(4) uint8_t buffer[] =
{
0xC2, 0b00000000, 0x00, 0x20,
0x11, 0x22, 0x33, 0x44,
0x10, 0x01, 0x00, 0x01,
0x11, 0x00, 0x00, 0x11,
0x20, 0x02, 0x00, 0x00,
0x22, 0x00, 0x00, 0x22,
0x30, 0x03, 0x00, 0x01,
0x33, 0x00, 0x00, 0x33,
0xAA, 0xBB, 0xCC, 0xDD,
0xAA, 0xBB, 0xCC
};
auto* chunk = RTC::SCTP::IForwardTsnChunk::Parse(buffer, sizeof(buffer));
CHECK_SCTP_CHUNK(
chunk,
buffer,
sizeof(buffer),
32,
RTC::SCTP::Chunk::ChunkType::I_FORWARD_TSN,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::SKIP_AND_REPORT,
0b00000000,
false,
0,
false,
0);
REQUIRE(chunk->GetNewCumulativeTsn() == 287454020);
REQUIRE(chunk->GetNumberOfSkippedStreams() == 3);
REQUIRE(
chunk->GetSkippedStreams() == std::vector<RTC::SCTP::AnyForwardTsnChunk::SkippedStream>{
{
true, 4097,
285212689, },
{
false, 8194,
570425378, },
{
true,12291,
855638067, },
});
chunk->Serialize(sctpCommon::SerializeBuffer, sizeof(sctpCommon::SerializeBuffer));
std::memset(buffer, 0x00, sizeof(buffer));
CHECK_SCTP_CHUNK(
chunk,
sctpCommon::SerializeBuffer,
sizeof(sctpCommon::SerializeBuffer),
32,
RTC::SCTP::Chunk::ChunkType::I_FORWARD_TSN,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::SKIP_AND_REPORT,
0b00000000,
false,
0,
false,
0);
REQUIRE(chunk->GetNewCumulativeTsn() == 287454020);
REQUIRE(chunk->GetNumberOfSkippedStreams() == 3);
REQUIRE(
chunk->GetSkippedStreams() == std::vector<RTC::SCTP::AnyForwardTsnChunk::SkippedStream>{
{
true, 4097,
285212689, },
{
false, 8194,
570425378, },
{
true,12291,
855638067, },
});
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),
32,
RTC::SCTP::Chunk::ChunkType::I_FORWARD_TSN,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::SKIP_AND_REPORT,
0b00000000,
false,
0,
false,
0);
REQUIRE(clonedChunk->GetNewCumulativeTsn() == 287454020);
REQUIRE(clonedChunk->GetNumberOfSkippedStreams() == 3);
REQUIRE(
clonedChunk->GetSkippedStreams() == std::vector<RTC::SCTP::AnyForwardTsnChunk::SkippedStream>{
{
true, 4097,
285212689, },
{
false, 8194,
570425378, },
{
true,12291,
855638067, },
});
delete clonedChunk;
}
SECTION("IForwardTsnChunk::Parse() fails")
{
alignas(4) uint8_t buffer1[] =
{
0xC2, 0b00000000, 0x00, 0x14,
0x11, 0x22, 0x33, 0x44,
0x10, 0x01, 0x00, 0x01,
0x11, 0x00, 0x00, 0x11,
0x20, 0x02, 0x00, 0x00,
0x22, 0x00, 0x00, 0x22,
};
REQUIRE(!RTC::SCTP::IForwardTsnChunk::Parse(buffer1, sizeof(buffer1)));
}
SECTION("IForwardTsnChunk::Factory() succeeds")
{
auto* chunk = RTC::SCTP::IForwardTsnChunk::Factory(
sctpCommon::FactoryBuffer, sizeof(sctpCommon::FactoryBuffer));
CHECK_SCTP_CHUNK(
chunk,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
8,
RTC::SCTP::Chunk::ChunkType::I_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(12345678);
chunk->AddSkippedStream(
RTC::SCTP::AnyForwardTsnChunk::SkippedStream{
true, 1111, 11110001 });
chunk->AddSkippedStream(
RTC::SCTP::AnyForwardTsnChunk::SkippedStream{
false, 2222, 22220002 });
chunk->AddSkippedStream(
RTC::SCTP::AnyForwardTsnChunk::SkippedStream{
true, 3333, 33330003 });
CHECK_SCTP_CHUNK(
chunk,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
32,
RTC::SCTP::Chunk::ChunkType::I_FORWARD_TSN,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::SKIP_AND_REPORT,
0b00000000,
false,
0,
false,
0);
REQUIRE(chunk->GetNewCumulativeTsn() == 12345678);
REQUIRE(chunk->GetNumberOfSkippedStreams() == 3);
REQUIRE(
chunk->GetSkippedStreams() == std::vector<RTC::SCTP::AnyForwardTsnChunk::SkippedStream>{
{ true, 1111, 11110001 },
{ false, 2222, 22220002 },
{ true, 3333, 33330003 },
});
auto* parsedChunk = RTC::SCTP::IForwardTsnChunk::Parse(chunk->GetBuffer(), chunk->GetLength());
delete chunk;
CHECK_SCTP_CHUNK(
parsedChunk,
sctpCommon::FactoryBuffer,
32,
32,
RTC::SCTP::Chunk::ChunkType::I_FORWARD_TSN,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::SKIP_AND_REPORT,
0b00000000,
false,
0,
false,
0);
REQUIRE(parsedChunk->GetNewCumulativeTsn() == 12345678);
REQUIRE(parsedChunk->GetNumberOfSkippedStreams() == 3);
REQUIRE(
parsedChunk->GetSkippedStreams() == std::vector<RTC::SCTP::AnyForwardTsnChunk::SkippedStream>{
{ true, 1111, 11110001 },
{ false, 2222, 22220002 },
{ true, 3333, 33330003 },
});
delete parsedChunk;
}
}