#include "common.hpp"
#include "MediaSoupErrors.hpp"
#include "RTC/SCTP/packet/Chunk.hpp"
#include "RTC/SCTP/packet/ErrorCause.hpp"
#include "RTC/SCTP/packet/chunks/AbortAssociationChunk.hpp"
#include "RTC/SCTP/packet/errorCauses/StaleCookieErrorCause.hpp"
#include "RTC/SCTP/sctpCommon.hpp"
#include <catch2/catch_test_macros.hpp>
#include <cstring>
SCENARIO("SCTP Abort Association Chunk (6)", "[serializable][sctp][chunk]")
{
sctpCommon::ResetBuffers();
SECTION("AbortAssociationChunk::Parse() succeeds")
{
alignas(4) uint8_t buffer[] =
{
0x06, 0b00000001, 0x00, 0x0C,
0x00, 0x03, 0x00, 0x08,
0x12, 0x34, 0x56, 0x78,
0xAA, 0xBB, 0xCC, 0xDD,
0xAA, 0xBB, 0xCC, 0xDD,
};
auto* chunk = RTC::SCTP::AbortAssociationChunk::Parse(buffer, sizeof(buffer));
CHECK_SCTP_CHUNK(
chunk,
buffer,
sizeof(buffer),
12,
RTC::SCTP::Chunk::ChunkType::ABORT,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::STOP,
0b00000001,
false,
0,
true,
1);
REQUIRE(chunk->GetT() == true);
auto* errorCause1 =
reinterpret_cast<const RTC::SCTP::StaleCookieErrorCause*>(chunk->GetErrorCauseAt(0));
CHECK_SCTP_ERROR_CAUSE(
errorCause1,
nullptr,
8,
8,
RTC::SCTP::ErrorCause::ErrorCauseCode::STALE_COOKIE,
false);
REQUIRE(errorCause1->GetMeasureOfStaleness() == 0x12345678);
chunk->Serialize(sctpCommon::SerializeBuffer, sizeof(sctpCommon::SerializeBuffer));
std::memset(buffer, 0x00, sizeof(buffer));
CHECK_SCTP_CHUNK(
chunk,
sctpCommon::SerializeBuffer,
sizeof(sctpCommon::SerializeBuffer),
12,
RTC::SCTP::Chunk::ChunkType::ABORT,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::STOP,
0b00000001,
false,
0,
true,
1);
errorCause1 =
reinterpret_cast<const RTC::SCTP::StaleCookieErrorCause*>(chunk->GetErrorCauseAt(0));
CHECK_SCTP_ERROR_CAUSE(
errorCause1,
nullptr,
8,
8,
RTC::SCTP::ErrorCause::ErrorCauseCode::STALE_COOKIE,
false);
REQUIRE(errorCause1->GetMeasureOfStaleness() == 0x12345678);
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),
12,
RTC::SCTP::Chunk::ChunkType::ABORT,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::STOP,
0b00000001,
false,
0,
true,
1);
errorCause1 =
reinterpret_cast<const RTC::SCTP::StaleCookieErrorCause*>(clonedChunk->GetErrorCauseAt(0));
CHECK_SCTP_ERROR_CAUSE(
errorCause1,
nullptr,
8,
8,
RTC::SCTP::ErrorCause::ErrorCauseCode::STALE_COOKIE,
false);
REQUIRE(errorCause1->GetMeasureOfStaleness() == 0x12345678);
delete clonedChunk;
}
SECTION("AbortAssociationChunk::Factory() succeeds")
{
auto* chunk = RTC::SCTP::AbortAssociationChunk::Factory(
sctpCommon::FactoryBuffer, sizeof(sctpCommon::FactoryBuffer));
CHECK_SCTP_CHUNK(
chunk,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
4,
RTC::SCTP::Chunk::ChunkType::ABORT,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::STOP,
0b00000000,
false,
0,
true,
0);
REQUIRE(chunk->GetT() == false);
chunk->SetT(true);
auto* errorCause1 = chunk->BuildErrorCauseInPlace<RTC::SCTP::StaleCookieErrorCause>();
errorCause1->SetMeasureOfStaleness(666);
errorCause1->Consolidate();
CHECK_SCTP_CHUNK(
chunk,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
4 + (4 + 4),
RTC::SCTP::Chunk::ChunkType::ABORT,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::STOP,
0b00000001,
false,
0,
true,
1);
REQUIRE(chunk->GetT() == true);
const auto* addedErrorCause1 =
reinterpret_cast<const RTC::SCTP::StaleCookieErrorCause*>(chunk->GetErrorCauseAt(0));
CHECK_SCTP_ERROR_CAUSE(
addedErrorCause1,
nullptr,
8,
8,
RTC::SCTP::ErrorCause::ErrorCauseCode::STALE_COOKIE,
false);
REQUIRE(errorCause1->GetMeasureOfStaleness() == 666);
auto* parsedChunk =
RTC::SCTP::AbortAssociationChunk::Parse(chunk->GetBuffer(), chunk->GetLength());
delete chunk;
CHECK_SCTP_CHUNK(
parsedChunk,
sctpCommon::FactoryBuffer,
4 + (4 + 4),
4 + (4 + 4),
RTC::SCTP::Chunk::ChunkType::ABORT,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::STOP,
0b00000001,
false,
0,
true,
1);
REQUIRE(parsedChunk->GetT() == true);
const auto* parsedErrorCause1 =
reinterpret_cast<const RTC::SCTP::StaleCookieErrorCause*>(parsedChunk->GetErrorCauseAt(0));
CHECK_SCTP_ERROR_CAUSE(
parsedErrorCause1,
nullptr,
8,
8,
RTC::SCTP::ErrorCause::ErrorCauseCode::STALE_COOKIE,
false);
REQUIRE(parsedErrorCause1->GetMeasureOfStaleness() == 666);
delete parsedChunk;
}
SECTION("AbortAssociationChunk::Factory() with AddErrorCause() succeeds")
{
auto* chunk = RTC::SCTP::AbortAssociationChunk::Factory(
sctpCommon::FactoryBuffer, sizeof(sctpCommon::FactoryBuffer));
chunk->SetT(true);
auto* errorCause1 = RTC::SCTP::StaleCookieErrorCause::Factory(
sctpCommon::FactoryBuffer + 1000, sizeof(sctpCommon::FactoryBuffer));
errorCause1->SetMeasureOfStaleness(666666);
chunk->AddErrorCause(errorCause1);
delete errorCause1;
CHECK_SCTP_CHUNK(
chunk,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
12,
RTC::SCTP::Chunk::ChunkType::ABORT,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::STOP,
0b00000001,
false,
0,
true,
1);
REQUIRE(chunk->GetT() == true);
auto* obtainedErrorCause1 =
reinterpret_cast<const RTC::SCTP::StaleCookieErrorCause*>(chunk->GetErrorCauseAt(0));
CHECK_SCTP_ERROR_CAUSE(
obtainedErrorCause1,
nullptr,
8,
8,
RTC::SCTP::ErrorCause::ErrorCauseCode::STALE_COOKIE,
false);
REQUIRE(obtainedErrorCause1->GetMeasureOfStaleness() == 666666);
auto* parsedChunk =
RTC::SCTP::AbortAssociationChunk::Parse(chunk->GetBuffer(), chunk->GetLength());
delete chunk;
CHECK_SCTP_CHUNK(
parsedChunk,
sctpCommon::FactoryBuffer,
12,
12,
RTC::SCTP::Chunk::ChunkType::ABORT,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::STOP,
0b00000001,
false,
0,
true,
1);
REQUIRE(parsedChunk->GetT() == true);
obtainedErrorCause1 =
reinterpret_cast<const RTC::SCTP::StaleCookieErrorCause*>(parsedChunk->GetErrorCauseAt(0));
CHECK_SCTP_ERROR_CAUSE(
obtainedErrorCause1,
nullptr,
8,
8,
RTC::SCTP::ErrorCause::ErrorCauseCode::STALE_COOKIE,
false);
REQUIRE(obtainedErrorCause1->GetMeasureOfStaleness() == 666666);
delete parsedChunk;
}
}